Lines 177-188
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
177 |
|
177 |
|
178 |
$schema->storage->txn_begin; |
178 |
$schema->storage->txn_begin; |
179 |
|
179 |
|
180 |
my $dbh = C4::Context->dbh; |
180 |
my $dbh = C4::Context->dbh; |
181 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
181 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
182 |
my $categorycode = $patron->categorycode; |
182 |
my $categorycode = $patron->categorycode; |
183 |
my $branchcode = $patron->branchcode; |
183 |
my $branchcode = $patron->branchcode; |
184 |
|
184 |
|
185 |
$dbh->do(qq{ |
185 |
$dbh->do( |
|
|
186 |
qq{ |
186 |
INSERT INTO `overduerules` ( |
187 |
INSERT INTO `overduerules` ( |
187 |
`categorycode`, |
188 |
`categorycode`, |
188 |
`delay1`, |
189 |
`delay1`, |
Lines 193-222
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
193 |
`debarred2` |
194 |
`debarred2` |
194 |
) |
195 |
) |
195 |
VALUES ('$categorycode', 6, 'ODUE', 0, 10, 'ODUE2', 1) |
196 |
VALUES ('$categorycode', 6, 'ODUE', 0, 10, 'ODUE2', 1) |
196 |
}); |
197 |
} |
|
|
198 |
); |
197 |
|
199 |
|
198 |
t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue'); |
200 |
t::lib::Mocks::mock_preference( 'AutoRemoveOverduesRestrictions', 'when_no_overdue' ); |
199 |
|
201 |
|
200 |
t::lib::Mocks::mock_userenv( { branchcode => $branchcode } ); |
202 |
t::lib::Mocks::mock_userenv( { branchcode => $branchcode } ); |
201 |
my $item_1 = $builder->build_sample_item; |
203 |
my $item_1 = $builder->build_sample_item; |
202 |
my $item_2 = $builder->build_sample_item; |
204 |
my $item_2 = $builder->build_sample_item; |
203 |
my $item_3 = $builder->build_sample_item; |
205 |
my $item_3 = $builder->build_sample_item; |
204 |
my $nine_days_ago = dt_from_string->subtract( days => 9 ); #->set_hour(23)->set_minute(59); |
206 |
my $nine_days_ago = dt_from_string->subtract( days => 9 ); |
205 |
my $checkout_1 = AddIssue( $patron, $item_1->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
207 |
my $checkout_1 = |
206 |
my $checkout_2 = AddIssue( $patron, $item_2->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
208 |
AddIssue( $patron, $item_1->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
207 |
my $checkout_3 = AddIssue( $patron, $item_3->barcode ); # not overdue |
209 |
my $checkout_2 = |
|
|
210 |
AddIssue( $patron, $item_2->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
211 |
my $checkout_3 = AddIssue( $patron, $item_3->barcode ); # not overdue |
212 |
|
208 |
|
213 |
|
209 |
Koha::Patron::Debarments::AddUniqueDebarment( |
214 |
Koha::Patron::Debarments::AddUniqueDebarment( |
210 |
{ |
215 |
{ |
211 |
borrowernumber => $patron->borrowernumber, |
216 |
borrowernumber => $patron->borrowernumber, |
212 |
type => 'OVERDUES', |
217 |
type => 'OVERDUES', |
213 |
comment => "OVERDUES_PROCESS simulation", |
218 |
comment => "OVERDUES_PROCESS simulation", |
214 |
} |
219 |
} |
215 |
); |
220 |
); |
216 |
|
221 |
|
217 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); |
222 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); |
218 |
|
223 |
|
219 |
my $restrictions = $patron->restrictions; |
224 |
my $restrictions = $patron->restrictions; |
220 |
my $THE_restriction = $restrictions->next; |
225 |
my $THE_restriction = $restrictions->next; |
221 |
is( $THE_restriction->type->code, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues' ); |
226 |
is( $THE_restriction->type->code, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues' ); |
222 |
|
227 |
|
Lines 225-249
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
225 |
$restrictions = $patron->restrictions; |
230 |
$restrictions = $patron->restrictions; |
226 |
is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' ); |
231 |
is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' ); |
227 |
|
232 |
|
228 |
t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue_causing_debarment'); |
233 |
t::lib::Mocks::mock_preference( 'AutoRemoveOverduesRestrictions', 'when_no_overdue_causing_debarment' ); |
229 |
|
234 |
|
230 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
235 |
my $ten_days_ago = dt_from_string->subtract( days => 10 ); |
231 |
|
236 |
|
232 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $ten_days_ago ); # overdue and would trigger debarment |
237 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $ten_days_ago ); # overdue and would trigger debarment |
233 |
$checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
238 |
$checkout_2 = |
|
|
239 |
AddIssue( $patron->unblessed, $item_2->barcode, $nine_days_ago ); # overdue, but would not trigger debarment |
234 |
|
240 |
|
235 |
Koha::Patron::Debarments::AddUniqueDebarment( |
241 |
Koha::Patron::Debarments::AddUniqueDebarment( |
236 |
{ |
242 |
{ |
237 |
borrowernumber => $patron->borrowernumber, |
243 |
borrowernumber => $patron->borrowernumber, |
238 |
type => 'OVERDUES', |
244 |
type => 'OVERDUES', |
239 |
comment => "OVERDUES_PROCESS simulation", |
245 |
comment => "OVERDUES_PROCESS simulation", |
240 |
} |
246 |
} |
241 |
); |
247 |
); |
242 |
|
248 |
|
243 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); |
249 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber ); |
244 |
|
250 |
|
245 |
$restrictions = $patron->restrictions; |
251 |
$restrictions = $patron->restrictions; |
246 |
is($restrictions->count, 0, 'OVERDUES debarment is removed if remaining items would not result in patron debarment' ); |
252 |
is( |
|
|
253 |
$restrictions->count, 0, |
254 |
'OVERDUES debarment is removed if remaining items would not result in patron debarment' |
255 |
); |
247 |
|
256 |
|
248 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $ten_days_ago ); # overdue and would trigger debarment |
257 |
$checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $ten_days_ago ); # overdue and would trigger debarment |
249 |
|
258 |
|
Lines 251-264
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
251 |
{ |
260 |
{ |
252 |
borrowernumber => $patron->borrowernumber, |
261 |
borrowernumber => $patron->borrowernumber, |
253 |
type => 'OVERDUES', |
262 |
type => 'OVERDUES', |
254 |
comment => "OVERDUES_PROCESS simulation", |
263 |
comment => "OVERDUES_PROCESS simulation", |
255 |
} |
264 |
} |
256 |
); |
265 |
); |
257 |
|
266 |
|
258 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
267 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
259 |
|
268 |
|
260 |
$restrictions = $patron->restrictions->search({ type => 'OVERDUES' }); |
269 |
$restrictions = $patron->restrictions->search( { type => 'OVERDUES' } ); |
261 |
is( $restrictions->count, 1, 'OVERDUES debarment is not removed if patron still has overdues that would trigger debarment' ); |
270 |
is( |
|
|
271 |
$restrictions->count, 1, |
272 |
'OVERDUES debarment is not removed if patron still has overdues that would trigger debarment' |
273 |
); |
262 |
|
274 |
|
263 |
my $eleven_days_ago = dt_from_string->subtract( days => 11 ); |
275 |
my $eleven_days_ago = dt_from_string->subtract( days => 11 ); |
264 |
|
276 |
|
Lines 266-272
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
266 |
$checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $eleven_days_ago ); |
278 |
$checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $eleven_days_ago ); |
267 |
|
279 |
|
268 |
# $checkout_1 should now not trigger debarment with this new rule for specific branchcode |
280 |
# $checkout_1 should now not trigger debarment with this new rule for specific branchcode |
269 |
$dbh->do(qq{ |
281 |
$dbh->do( |
|
|
282 |
qq{ |
270 |
INSERT INTO `overduerules` ( |
283 |
INSERT INTO `overduerules` ( |
271 |
`branchcode`, |
284 |
`branchcode`, |
272 |
`categorycode`, |
285 |
`categorycode`, |
Lines 278-289
subtest 'AutoRemoveOverduesRestrictions' => sub {
Link Here
|
278 |
`debarred2` |
291 |
`debarred2` |
279 |
) |
292 |
) |
280 |
VALUES ('$branchcode', '$categorycode', 6, 'ODUE', 0, 11, 'ODUE2', 1) |
293 |
VALUES ('$branchcode', '$categorycode', 6, 'ODUE', 0, 11, 'ODUE2', 1) |
281 |
}); |
294 |
} |
|
|
295 |
); |
282 |
|
296 |
|
283 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
297 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber ); |
284 |
|
298 |
|
285 |
$restrictions = $patron->restrictions; |
299 |
$restrictions = $patron->restrictions; |
286 |
is( $restrictions->count, 0, 'OVERDUES debarment is removed if remaining items would not result in patron debarment' ); |
300 |
is( |
|
|
301 |
$restrictions->count, 0, |
302 |
'OVERDUES debarment is removed if remaining items would not result in patron debarment' |
303 |
); |
287 |
|
304 |
|
288 |
$schema->storage->txn_rollback; |
305 |
$schema->storage->txn_rollback; |
289 |
}; |
306 |
}; |
290 |
- |
|
|