|
Lines 362-440
is( $date->ymd, $renewed_date->ymd, 'Renewal period of "" should trigger fallove
Link Here
|
| 362 |
my $library1 = $builder->build( { source => 'Branch' } ); |
362 |
my $library1 = $builder->build( { source => 'Branch' } ); |
| 363 |
Koha::CirculationRules->set_rules( |
363 |
Koha::CirculationRules->set_rules( |
| 364 |
{ |
364 |
{ |
| 365 |
categorycode => $categorycode, |
365 |
categorycode => $borrower->categorycode, |
| 366 |
itemtype => $itemtype, |
366 |
itemtype => $itemtype, |
| 367 |
branchcode => $library1->{branchcode}, |
367 |
branchcode => $library1->{branchcode}, |
| 368 |
rules => { |
368 |
rules => { |
| 369 |
issuelength => 3, # loan period is 3 hours |
369 |
issuelength => 3, # loan period is 3 hours |
| 370 |
lengthunit => 'hours', |
370 |
lengthunit => 'hours', |
| 371 |
daysmode => '', |
371 |
daysmode => '', |
| 372 |
} |
372 |
} |
| 373 |
} |
373 |
} |
| 374 |
); |
374 |
); |
| 375 |
|
375 |
|
| 376 |
my $open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms; |
376 |
my $open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms; |
| 377 |
my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms; |
377 |
my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms; |
| 378 |
my $now = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 ); |
378 |
my $now = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 ); |
|
|
379 |
|
| 380 |
foreach ( 0 .. 6 ) { |
| 379 |
|
381 |
|
| 380 |
foreach (0..6) { |
|
|
| 381 |
# library opened 4 hours ago and closes in 2 hours. |
382 |
# library opened 4 hours ago and closes in 2 hours. |
| 382 |
Koha::Library::Hour->new({ day => $_, library_id => $library1->{branchcode}, open_time => $open, close_time => $close })->store; |
383 |
Koha::Library::Hour->new( |
|
|
384 |
{ day => $_, library_id => $library1->{branchcode}, open_time => $open, close_time => $close } )->store; |
| 383 |
} |
385 |
} |
| 384 |
|
386 |
|
| 385 |
# ignore calendar |
387 |
# ignore calendar |
| 386 |
t::lib::Mocks::mock_preference('useDaysMode', 'Days'); |
388 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' ); |
| 387 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); |
389 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'close' ); |
|
|
390 |
|
| 388 |
# shorten loan period |
391 |
# shorten loan period |
| 389 |
|
392 |
|
| 390 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
393 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 391 |
my $expected_duetime = $now->clone->add( hours => 2 ); |
394 |
my $expected_duetime = $now->clone->add( hours => 2 ); |
| 392 |
is( $date, $expected_duetime, "Loan period was shortened because ConsiderLibraryHoursInCirculation is set to close time" ); |
395 |
is( |
|
|
396 |
$date, $expected_duetime, |
| 397 |
"Loan period was shortened because ConsiderLibraryHoursInCirculation is set to close time" |
| 398 |
); |
| 399 |
|
| 400 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 393 |
|
401 |
|
| 394 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursWhenIssuing', 'open'); |
|
|
| 395 |
# extend loan period |
402 |
# extend loan period |
| 396 |
|
403 |
|
| 397 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
404 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 398 |
$expected_duetime = $now->clone->add( days => 1 )->subtract( hours => 4 ); |
405 |
$expected_duetime = $now->clone->add( days => 1 )->subtract( hours => 4 ); |
| 399 |
is( $date, $expected_duetime, "Loan period was extended because ConsiderLibraryHoursInCirculation is set to open time" ); |
406 |
is( |
|
|
407 |
$date, $expected_duetime, |
| 408 |
"Loan period was extended because ConsiderLibraryHoursInCirculation is set to open time" |
| 409 |
); |
| 400 |
|
410 |
|
| 401 |
my $holiday_tomorrow = $now->clone->add( days => 1 ); |
411 |
my $holiday_tomorrow = $now->clone->add( days => 1 ); |
| 402 |
|
412 |
|
| 403 |
# consider calendar |
413 |
# consider calendar |
| 404 |
my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} ); |
414 |
my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} ); |
| 405 |
$library1_calendar->insert_single_holiday( |
415 |
$library1_calendar->insert_single_holiday( |
| 406 |
day => $holiday_tomorrow->day, |
416 |
day => $holiday_tomorrow->day, |
| 407 |
month => $holiday_tomorrow->month, |
417 |
month => $holiday_tomorrow->month, |
| 408 |
year => $holiday_tomorrow->year, |
418 |
year => $holiday_tomorrow->year, |
| 409 |
title => 'testholiday', |
419 |
title => 'testholiday', |
| 410 |
description => 'testholiday' |
420 |
description => 'testholiday' |
| 411 |
); |
421 |
); |
| 412 |
Koha::CirculationRules->set_rules( |
422 |
Koha::CirculationRules->set_rules( |
| 413 |
{ |
423 |
{ |
| 414 |
categorycode => $categorycode, |
424 |
categorycode => $patron_category->categorycode, |
| 415 |
itemtype => $itemtype, |
425 |
itemtype => $itemtype, |
| 416 |
branchcode => $library1->{branchcode}, |
426 |
branchcode => $library1->{branchcode}, |
| 417 |
rules => { |
427 |
rules => { |
| 418 |
issuelength => 18, # loan period must cross over into tomorrow |
428 |
issuelength => 18, # loan period must cross over into tomorrow |
| 419 |
lengthunit => 'hours', |
429 |
lengthunit => 'hours', |
| 420 |
} |
430 |
} |
| 421 |
} |
431 |
} |
| 422 |
); |
432 |
); |
| 423 |
|
433 |
|
| 424 |
t::lib::Mocks::mock_preference('useDaysMode', 'Calendar'); |
434 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Calendar' ); |
| 425 |
t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); |
435 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'close' ); |
|
|
436 |
|
| 426 |
# shorten loan period |
437 |
# shorten loan period |
| 427 |
|
438 |
|
| 428 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
439 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 429 |
$expected_duetime = $now->clone->add( days => 2, hours => 2 ); |
440 |
$expected_duetime = $now->clone->add( hours => 2 ); |
| 430 |
is( $date, $expected_duetime, "Loan period was shortened (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to close time" ); |
441 |
is( |
|
|
442 |
$date, $expected_duetime, |
| 443 |
"Loan period was shortened (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to close time" |
| 444 |
); |
| 431 |
|
445 |
|
| 432 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
446 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
|
|
447 |
|
| 433 |
# extend loan period |
448 |
# extend loan period |
| 434 |
|
449 |
|
| 435 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
450 |
$date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); |
| 436 |
$expected_duetime = $now->clone->add( days => 2 )->subtract( hours => 4 ); |
451 |
$expected_duetime = $now->clone->add( days => 2 )->subtract( hours => 4 ); |
| 437 |
is( $date, $expected_duetime, "Loan period was extended (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to open time" ); |
452 |
is( |
|
|
453 |
$date, $expected_duetime, |
| 454 |
"Loan period was extended (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to open time" |
| 455 |
); |
| 438 |
|
456 |
|
| 439 |
$cache->clear_from_cache($key); |
457 |
$cache->clear_from_cache($key); |
| 440 |
$schema->storage->txn_rollback; |
458 |
$schema->storage->txn_rollback; |
| 441 |
- |
|
|