Lines 173-192
subtest 'Manually pass a return date' => sub {
Link Here
|
173 |
}; |
173 |
}; |
174 |
|
174 |
|
175 |
subtest 'AutoRemoveOverduesRestrictions' => sub { |
175 |
subtest 'AutoRemoveOverduesRestrictions' => sub { |
176 |
plan tests => 2; |
176 |
plan tests => 5; |
177 |
|
177 |
|
178 |
$schema->storage->txn_begin; |
178 |
$schema->storage->txn_begin; |
179 |
|
179 |
|
180 |
t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 1); |
180 |
my $dbh = C4::Context->dbh; |
181 |
|
|
|
182 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
181 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
183 |
t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); |
182 |
my $categorycode = $patron->categorycode; |
|
|
183 |
my $branchcode = $patron->branchcode; |
184 |
|
185 |
$dbh->do(qq{ |
186 |
INSERT INTO `overduerules` ( |
187 |
`categorycode`, |
188 |
`delay1`, |
189 |
`letter1`, |
190 |
`debarred1`, |
191 |
`delay2`, |
192 |
`letter2`, |
193 |
`debarred2` |
194 |
) |
195 |
VALUES ('$categorycode', 6, 'ODUE', 0, 10, 'ODUE2', 1) |
196 |
}); |
197 |
|
198 |
t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue'); |
199 |
|
200 |
t::lib::Mocks::mock_userenv( { branchcode => $branchcode } ); |
184 |
my $item_1 = $builder->build_sample_item; |
201 |
my $item_1 = $builder->build_sample_item; |
185 |
my $item_2 = $builder->build_sample_item; |
202 |
my $item_2 = $builder->build_sample_item; |
186 |
my $item_3 = $builder->build_sample_item; |
203 |
my $item_3 = $builder->build_sample_item; |
187 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
204 |
my $five_days_ago = dt_from_string->subtract( days => 5 ); |
188 |
my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue |
205 |
my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue, but would not trigger debarment |
189 |
my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue |
206 |
my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment |
190 |
my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue |
207 |
my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue |
191 |
|
208 |
|
192 |
Koha::Patron::Debarments::AddUniqueDebarment( |
209 |
Koha::Patron::Debarments::AddUniqueDebarment( |
Lines 208-212
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
208 |
$restrictions = $patron->restrictions; |
225 |
$restrictions = $patron->restrictions; |
209 |
is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' ); |
226 |
is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' ); |
210 |
|
227 |
|
|
|
228 |
t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue_causing_debarment'); |
229 |
|
230 |
my $eleven_days_ago = dt_from_string->subtract( days => 11 ); |
231 |
|
232 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment |
233 |
$checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment |
234 |
|
235 |
Koha::Patron::Debarments::AddUniqueDebarment( |
236 |
{ |
237 |
borrowernumber => $patron->borrowernumber, |
238 |
type => 'OVERDUES', |
239 |
comment => "OVERDUES_PROCESS simulation", |
240 |
} |
241 |
); |
242 |
|
243 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); |
244 |
|
245 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber }); |
246 |
is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' ); |
247 |
|
248 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment |
249 |
|
250 |
Koha::Patron::Debarments::AddUniqueDebarment( |
251 |
{ |
252 |
borrowernumber => $patron->borrowernumber, |
253 |
type => 'OVERDUES', |
254 |
comment => "OVERDUES_PROCESS simulation", |
255 |
} |
256 |
); |
257 |
|
258 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
259 |
|
260 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber }); |
261 |
is( $debarments->[0]->{type}, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues that would trigger debarment' ); |
262 |
|
263 |
my $thirteen_days_ago = dt_from_string->subtract( days => 13 ); |
264 |
|
265 |
# overdue and would trigger debarment |
266 |
$checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $thirteen_days_ago ); |
267 |
|
268 |
# $chechout_1 should now not trigger debarment with this new rule for specific branchcode |
269 |
$dbh->do(qq{ |
270 |
INSERT INTO `overduerules` ( |
271 |
`branchcode`, |
272 |
`categorycode`, |
273 |
`delay1`, |
274 |
`letter1`, |
275 |
`debarred1`, |
276 |
`delay2`, |
277 |
`letter2`, |
278 |
`debarred2` |
279 |
) |
280 |
VALUES ('$branchcode', '$categorycode', 6, 'ODUE', 0, 12, 'ODUE2', 1) |
281 |
}); |
282 |
|
283 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
284 |
|
285 |
$debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber }); |
286 |
is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' ); |
287 |
|
211 |
$schema->storage->txn_rollback; |
288 |
$schema->storage->txn_rollback; |
212 |
}; |
289 |
}; |
213 |
- |
|
|