diff options
-rw-r--r-- | perllib/Problems.pm | 47 | ||||
-rwxr-xr-x | t/Problems.t | 50 |
2 files changed, 96 insertions, 1 deletions
diff --git a/perllib/Problems.pm b/perllib/Problems.pm index 7eef93b76..2539a97cd 100644 --- a/perllib/Problems.pm +++ b/perllib/Problems.pm @@ -6,7 +6,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Problems.pm,v 1.20 2009-09-14 15:09:32 louise Exp $ +# $Id: Problems.pm,v 1.21 2009-10-13 09:25:56 louise Exp $ # package Problems; @@ -257,4 +257,49 @@ sub created_in_interval { date_trunc('day',created)<='$end_date'"; return problems_matching_criteria($criteria); } + +=item data_sharing_notification_start + +Returns the unix datetime when the T&Cs that explicitly allow for users' data to be displayed +on other sites. + +=cut + +sub data_sharing_notification_start { + return 1256947200; +} + +=item user_notified_data_sharing + +Accepts a hash reference of problem data and returns a boolean indicating whether the user who +submitted the problem has accepted T&Cs that explicitly allow for their data to be displayed +on other sites. + +=cut + +sub user_notified_data_sharing { + my ($problem, $notification_start) = @_; + if ($problem->{time} > $notification_start){ + return 1; + } else { + return 0; + } +} + +=item update_user_notified_data_sharing + +Accepts a hash reference of update data and returns a boolean indicating whether the user who submitted +the update has accepted the T&Cs that explicitly allow for their data to be displayed on other sites. + +=cut + +sub update_user_notified_data_sharing { + my ($update, $notification_start) = @_; + if ($update->{created} > $notification_start){ + return 1; + } else { + return 0; + } +} + 1; diff --git a/t/Problems.t b/t/Problems.t new file mode 100755 index 000000000..8a5c828e3 --- /dev/null +++ b/t/Problems.t @@ -0,0 +1,50 @@ +#!/usr/bin/perl -w +# +# Problem.t: +# Tests for the Problem functions +# +# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. +# Email: louise@mysociety.org; WWW: http://www.mysociety.org/ +# +# $Id: Problems.t,v 1.1 2009-10-13 09:25:56 louise Exp $ +# + +use strict; +use warnings; +use Test::More tests => 6; +use Test::Exception; + +use FindBin; +use lib "$FindBin::Bin"; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use Problems; + +sub test_update_user_notified_data_sharing() { + + my $update = {created => 1256947200}; + my $notification_start = 1256947201; + my $accepted = Problems::update_user_notified_data_sharing($update, $notification_start); + ok($accepted == 0, 'update_user_notified_data_sharing returns false for an update created before the notification started to be displayed'); + $notification_start = 1256947199; + $accepted = Problems::update_user_notified_data_sharing($update, $notification_start); + ok($accepted == 1, 'update_user_notified_data_sharing returns true for a problem created after the notification started to be displayed'); + return 1; +} + +sub test_user_notified_data_sharing() { + + my $problem = {time => 1256947200}; + my $notification_start = 1256947201; + my $accepted = Problems::user_notified_data_sharing($problem, $notification_start); + ok($accepted == 0, 'user_notified_data_sharing returns false for a problem created before the notification started to be displayed'); + $notification_start = 1256947199; + $accepted = Problems::user_notified_data_sharing($problem, $notification_start); + ok($accepted == 1, 'user_notified_data_sharing returns true for a problem created after the notification started to be displayed'); + return 1; +} + +ok(test_user_notified_data_sharing() == 1, 'Ran all tests for user_notified_data_sharing '); +ok(test_update_user_notified_data_sharing() == 1, 'Ran all tests for update_user_notified_data_sharing'); + |