Bug 11491: add option to supply field names in reports web service output
[koha.git] / t / db_dependent / Borrower_Debarments.t
blob88141f6ddb2c65438f038279984d5e1e29fc26fb
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use C4::Context;
6 use C4::Members;
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',
19 categorycode => 'S',
20 branchcode => 'CPL',
23 my $success = AddDebarment({
24 borrowernumber => $borrowernumber,
25 expiration => '9999-06-10',
26 type => 'MANUAL',
27 comment => 'Test 1',
28 });
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,
41 comment => 'Test 2',
42 });
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'" );
51 ModDebarment({
52 borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'},
53 comment => 'Test 3',
54 expiration => '9998-06-10',
55 });
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" );
65 AddUniqueDebarment({
66 borrowernumber => $borrowernumber,
67 type => 'OVERDUES'
68 });
69 $debarments = GetDebarments({
70 borrowernumber => $borrowernumber,
71 type => 'OVERDUES',
72 });
73 ok( @$debarments == 1, "GetDebarments returns 1 OVERDUES debarment" );
74 ok( $debarments->[0]->{'type'} eq 'OVERDUES', "AddOverduesDebarment created new debarment correctly" );
76 AddUniqueDebarment({
77 borrowernumber => $borrowernumber,
78 expiration => '9999-11-09',
79 type => 'OVERDUES'
80 });
81 $debarments = GetDebarments({
82 borrowernumber => $borrowernumber,
83 type => 'OVERDUES',
84 });
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" );
96 $dbh->rollback;