Lines 29-35
my $borrowernumber = Koha::Patron->new({
Link Here
|
29 |
branchcode => $library->{branchcode}, |
29 |
branchcode => $library->{branchcode}, |
30 |
})->store->borrowernumber; |
30 |
})->store->borrowernumber; |
31 |
|
31 |
|
32 |
my $success = AddDebarment({ |
32 |
my $success = Koha::Patron::Debarments::AddDebarment({ |
33 |
borrowernumber => $borrowernumber, |
33 |
borrowernumber => $borrowernumber, |
34 |
expiration => '9999-06-10', |
34 |
expiration => '9999-06-10', |
35 |
type => 'MANUAL', |
35 |
type => 'MANUAL', |
Lines 38-68
my $success = AddDebarment({
Link Here
|
38 |
is( $success, 1, "AddDebarment returned true" ); |
38 |
is( $success, 1, "AddDebarment returned true" ); |
39 |
|
39 |
|
40 |
|
40 |
|
41 |
my $debarments = GetDebarments({ borrowernumber => $borrowernumber }); |
41 |
my $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
42 |
is( @$debarments, 1, "GetDebarments returns 1 debarment" ); |
42 |
is( @$debarments, 1, "GetDebarments returns 1 debarment" ); |
43 |
is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
43 |
is( $debarments->[0]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
44 |
is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" ); |
44 |
is( $debarments->[0]->{'expiration'}, '9999-06-10', "Correctly stored 'expiration'" ); |
45 |
is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" ); |
45 |
is( $debarments->[0]->{'comment'}, 'Test 1', "Correctly stored 'comment'" ); |
46 |
|
46 |
|
47 |
|
47 |
|
48 |
$success = AddDebarment({ |
48 |
$success = Koha::Patron::Debarments::AddDebarment({ |
49 |
borrowernumber => $borrowernumber, |
49 |
borrowernumber => $borrowernumber, |
50 |
comment => 'Test 2', |
50 |
comment => 'Test 2', |
51 |
}); |
51 |
}); |
52 |
|
52 |
|
53 |
$debarments = GetDebarments({ borrowernumber => $borrowernumber }); |
53 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
54 |
is( @$debarments, 2, "GetDebarments returns 2 debarments" ); |
54 |
is( @$debarments, 2, "GetDebarments returns 2 debarments" ); |
55 |
is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
55 |
is( $debarments->[1]->{'type'}, 'MANUAL', "Correctly stored 'type'" ); |
56 |
is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" ); |
56 |
is( $debarments->[1]->{'expiration'}, undef, "Correctly stored debarrment with no expiration" ); |
57 |
is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" ); |
57 |
is( $debarments->[1]->{'comment'}, 'Test 2', "Correctly stored 'comment'" ); |
58 |
|
58 |
|
59 |
|
59 |
|
60 |
ModDebarment({ |
60 |
Koha::Patron::Debarments::ModDebarment({ |
61 |
borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'}, |
61 |
borrower_debarment_id => $debarments->[1]->{'borrower_debarment_id'}, |
62 |
comment => 'Test 3', |
62 |
comment => 'Test 3', |
63 |
expiration => '9998-06-10', |
63 |
expiration => '9998-06-10', |
64 |
}); |
64 |
}); |
65 |
$debarments = GetDebarments({ borrowernumber => $borrowernumber }); |
65 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
66 |
is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" ); |
66 |
is( $debarments->[1]->{'comment'}, 'Test 3', "ModDebarment functions correctly" ); |
67 |
|
67 |
|
68 |
my $patron = Koha::Patrons->find( $borrowernumber )->unblessed; |
68 |
my $patron = Koha::Patrons->find( $borrowernumber )->unblessed; |
Lines 70-92
is( $patron->{'debarred'}, '9999-06-10', "Field borrowers.debarred set correctly
Link Here
|
70 |
is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); |
70 |
is( $patron->{'debarredcomment'}, "Test 1\nTest 3", "Field borrowers.debarredcomment set correctly" ); |
71 |
|
71 |
|
72 |
|
72 |
|
73 |
AddUniqueDebarment({ |
73 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
74 |
borrowernumber => $borrowernumber, |
74 |
borrowernumber => $borrowernumber, |
75 |
type => 'OVERDUES' |
75 |
type => 'OVERDUES' |
76 |
}); |
76 |
}); |
77 |
$debarments = GetDebarments({ |
77 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
78 |
borrowernumber => $borrowernumber, |
78 |
borrowernumber => $borrowernumber, |
79 |
type => 'OVERDUES', |
79 |
type => 'OVERDUES', |
80 |
}); |
80 |
}); |
81 |
is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" ); |
81 |
is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment" ); |
82 |
is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); |
82 |
is( $debarments->[0]->{'type'}, 'OVERDUES', "AddOverduesDebarment created new debarment correctly" ); |
83 |
|
83 |
|
84 |
AddUniqueDebarment({ |
84 |
Koha::Patron::Debarments::AddUniqueDebarment({ |
85 |
borrowernumber => $borrowernumber, |
85 |
borrowernumber => $borrowernumber, |
86 |
expiration => '9999-11-09', |
86 |
expiration => '9999-11-09', |
87 |
type => 'OVERDUES' |
87 |
type => 'OVERDUES' |
88 |
}); |
88 |
}); |
89 |
$debarments = GetDebarments({ |
89 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
90 |
borrowernumber => $borrowernumber, |
90 |
borrowernumber => $borrowernumber, |
91 |
type => 'OVERDUES', |
91 |
type => 'OVERDUES', |
92 |
}); |
92 |
}); |
Lines 94-156
is( @$debarments, 1, "GetDebarments returns 1 OVERDUES debarment after running A
Link Here
|
94 |
is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" ); |
94 |
is( $debarments->[0]->{'expiration'}, '9999-11-09', "AddOverduesDebarment updated OVERDUES debarment correctly" ); |
95 |
|
95 |
|
96 |
|
96 |
|
97 |
my $delUniqueDebarment = DelUniqueDebarment({ |
97 |
my $delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
98 |
}); |
98 |
}); |
99 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" ); |
99 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' returns undef" ); |
100 |
$debarments = GetDebarments({ |
100 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
101 |
borrowernumber => $borrowernumber, |
101 |
borrowernumber => $borrowernumber, |
102 |
type => 'OVERDUES', |
102 |
type => 'OVERDUES', |
103 |
}); |
103 |
}); |
104 |
is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); |
104 |
is( @$debarments, 1, "DelUniqueDebarment without the arguments 'borrowernumber' and 'type' does not delete the debarment" ); |
105 |
|
105 |
|
106 |
$delUniqueDebarment = DelUniqueDebarment({ |
106 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
107 |
borrowernumber => $borrowernumber, |
107 |
borrowernumber => $borrowernumber, |
108 |
}); |
108 |
}); |
109 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" ); |
109 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'type' returns undef" ); |
110 |
$debarments = GetDebarments({ |
110 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
111 |
borrowernumber => $borrowernumber, |
111 |
borrowernumber => $borrowernumber, |
112 |
type => 'OVERDUES', |
112 |
type => 'OVERDUES', |
113 |
}); |
113 |
}); |
114 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); |
114 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'type' does not delete the debarment" ); |
115 |
|
115 |
|
116 |
$delUniqueDebarment = DelUniqueDebarment({ |
116 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
117 |
type => 'OVERDUES' |
117 |
type => 'OVERDUES' |
118 |
}); |
118 |
}); |
119 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" ); |
119 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment without the argument 'borrowernumber' returns undef" ); |
120 |
$debarments = GetDebarments({ |
120 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
121 |
borrowernumber => $borrowernumber, |
121 |
borrowernumber => $borrowernumber, |
122 |
type => 'OVERDUES', |
122 |
type => 'OVERDUES', |
123 |
}); |
123 |
}); |
124 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); |
124 |
is( @$debarments, 1, "DelUniqueDebarment without the argument 'borrowerumber' does not delete the debarment" ); |
125 |
|
125 |
|
126 |
$delUniqueDebarment = DelUniqueDebarment({ |
126 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
127 |
borrowernumber => $borrowernumber, |
127 |
borrowernumber => $borrowernumber, |
128 |
type => 'SUSPENSION', |
128 |
type => 'SUSPENSION', |
129 |
}); |
129 |
}); |
130 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" ); |
130 |
is( $delUniqueDebarment, undef, "DelUniqueDebarment with wrong arguments returns undef" ); |
131 |
$debarments = GetDebarments({ |
131 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
132 |
borrowernumber => $borrowernumber, |
132 |
borrowernumber => $borrowernumber, |
133 |
type => 'OVERDUES', |
133 |
type => 'OVERDUES', |
134 |
}); |
134 |
}); |
135 |
is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); |
135 |
is( @$debarments, 1, "DelUniqueDebarment with wrong arguments does not delete the debarment" ); |
136 |
|
136 |
|
137 |
$delUniqueDebarment = DelUniqueDebarment({ |
137 |
$delUniqueDebarment = Koha::Patron::Debarments::DelUniqueDebarment({ |
138 |
borrowernumber => $borrowernumber, |
138 |
borrowernumber => $borrowernumber, |
139 |
type => 'OVERDUES', |
139 |
type => 'OVERDUES', |
140 |
}); |
140 |
}); |
141 |
is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" ); |
141 |
is( $delUniqueDebarment, 1, "DelUniqueDebarment returns 1" ); |
142 |
$debarments = GetDebarments({ |
142 |
$debarments = Koha::Patron::Debarments::GetDebarments({ |
143 |
borrowernumber => $borrowernumber, |
143 |
borrowernumber => $borrowernumber, |
144 |
type => 'OVERDUES', |
144 |
type => 'OVERDUES', |
145 |
}); |
145 |
}); |
146 |
is( @$debarments, 0, "DelUniqueDebarment functions correctly" ); |
146 |
is( @$debarments, 0, "DelUniqueDebarment functions correctly" ); |
147 |
|
147 |
|
148 |
|
148 |
|
149 |
$debarments = GetDebarments({ borrowernumber => $borrowernumber }); |
149 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
150 |
foreach my $d ( @$debarments ) { |
150 |
foreach my $d ( @$debarments ) { |
151 |
DelDebarment( $d->{'borrower_debarment_id'} ); |
151 |
Koha::Patron::Debarments::DelDebarment( $d->{'borrower_debarment_id'} ); |
152 |
} |
152 |
} |
153 |
$debarments = GetDebarments({ borrowernumber => $borrowernumber }); |
153 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $borrowernumber }); |
154 |
is( @$debarments, 0, "DelDebarment functions correctly" ); |
154 |
is( @$debarments, 0, "DelDebarment functions correctly" ); |
155 |
|
155 |
|
156 |
$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); |
156 |
$dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); |
Lines 173-179
my $borrowernumber2 = Koha::Patron->new(
Link Here
|
173 |
)->store->borrowernumber; |
173 |
)->store->borrowernumber; |
174 |
my $debarreddate2 = '9999-06-10'; # Be sure to be in the future |
174 |
my $debarreddate2 = '9999-06-10'; # Be sure to be in the future |
175 |
my $debarredcomment2 = 'Test merge'; |
175 |
my $debarredcomment2 = 'Test merge'; |
176 |
AddDebarment( |
176 |
Koha::Patron::Debarments::AddDebarment( |
177 |
{ |
177 |
{ |
178 |
borrowernumber => $borrowernumber2, |
178 |
borrowernumber => $borrowernumber2, |
179 |
expiration => $debarreddate2, |
179 |
expiration => $debarreddate2, |