8 use Test
::More tests
=> 18;
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" );
89 $debarments = GetDebarments
({ borrowernumber
=> $borrowernumber });
90 foreach my $d ( @
$debarments ) {
91 DelDebarment
( $d->{'borrower_debarment_id'} );
93 $debarments = GetDebarments
({ borrowernumber
=> $borrowernumber });
94 ok
( @
$debarments == 0, "DelDebarment functions correctly" );