8 use Test::More tests => 22;
10 use_ok('Koha::Borrower::Debarments');
12 my $dbh = C4::Context->dbh;
13 $dbh->{AutoCommit} = 0;
14 $dbh->{RaiseError} = 1;
16 my $borrowernumber = AddMember(
17 firstname => 'my firstname',
18 surname => 'my surname',
23 my $success = AddDebarment({
24 borrowernumber => $borrowernumber,
25 expiration => '9999-06-10',
29 ok( $success, "AddDebarment returned true" );
32 my $debarments = GetDebarments({ borrowernumber => $borrowernumber });
33 ok( @$debarments == 1, "GetDebarments returns 1 debarment" );
34 ok( $debarments->[0]->{'type'} eq 'MANUAL', "Correctly stored 'type'" );
35 ok( $debarments->[0]->{'expiration'} eq '9999-06-10', "Correctly stored 'expiration'" );
36 ok( $debarments->[0]->{'comment'} eq 'Test 1', "Correctly stored 'comment'" );
39 $success = AddDebarment({
40 borrowernumber => $borrowernumber,
44 $debarments = GetDebarments({ borrowernumber => $borrowernumber });
45 ok( @$debarments == 2, "GetDebarments returns 2 debarments" );
46 ok( $debarments->[1]->{'type'} eq 'MANUAL', "Correctly stored 'type'" );
47 ok( !$debarments->[1]->{'expiration'}, "Correctly stored debarrment with no expiration" );
48 ok( $debarments->[1]->{'comment'} eq 'Test 2', "Correctly stored 'comment'" );
52 borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'},
54 expiration => '9998-06-10',
56 $debarments = GetDebarments({ borrowernumber => $borrowernumber });
57 ok( $debarments->[1]->{'comment'} eq 'Test 3', "ModDebarment functions correctly" );
60 my $borrower = GetMember( borrowernumber => $borrowernumber );
61 ok( $borrower->{'debarred'} eq '9999-06-10', "Field borrowers.debarred set correctly" );
62 ok( $borrower->{'debarredcomment'} eq "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" );
66 borrowernumber => $borrowernumber,
69 $debarments = GetDebarments({
70 borrowernumber => $borrowernumber,
73 ok( @$debarments == 1, "GetDebarments returns 1 OVERDUES debarment" );
74 ok( $debarments->[0]->{'type'} eq 'OVERDUES', "AddOverduesDebarment created new debarment correctly" );
77 borrowernumber => $borrowernumber,
78 expiration => '9999-11-09',
81 $debarments = GetDebarments({
82 borrowernumber => $borrowernumber,
85 ok( @$debarments == 1, "GetDebarments returns 1 OVERDUES debarment after running AddOverduesDebarment twice" );
86 ok( $debarments->[0]->{'expiration'} eq '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" );
90 borrowernumber => $borrowernumber,
93 $debarments = GetDebarments({
94 borrowernumber => $borrowernumber,
97 is( @$debarments, 0, "DelUniqueDebarment functions correctly" );
100 $debarments = GetDebarments({ borrowernumber => $borrowernumber });
101 foreach my $d ( @$debarments ) {
102 DelDebarment( $d->{'borrower_debarment_id'} );
104 $debarments = GetDebarments({ borrowernumber => $borrowernumber });
105 ok( @$debarments == 0, "DelDebarment functions correctly" );
107 $dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|);
108 is( IsDebarred( $borrowernumber ), undef, 'A patron with a debarred date in the past is not debarred' );
110 $dbh->do(q|UPDATE borrowers SET debarred = NULL|);
111 is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is not debarred' );
113 $dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000!
114 is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' );