aboutsummaryrefslogtreecommitdiffstats
path: root/t/Problems.t
blob: 8a5c828e3ed686cc28fa663ca2ff2feccefed11b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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');