|
Lines 3-9
Link Here
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
|
4 |
|
| 5 |
use Test::NoWarnings; |
5 |
use Test::NoWarnings; |
| 6 |
use Test::More tests => 27; |
6 |
use Test::More tests => 32; |
| 7 |
use Test::MockModule; |
7 |
use Test::MockModule; |
| 8 |
use DBI; |
8 |
use DBI; |
| 9 |
use DateTime; |
9 |
use DateTime; |
|
Lines 552-556
is(
Link Here
|
| 552 |
"Bug 38940: Loan period shortened with Calendar mode when next day has null hours (ConsiderLibraryHoursInCirculation='close')" |
552 |
"Bug 38940: Loan period shortened with Calendar mode when next day has null hours (ConsiderLibraryHoursInCirculation='close')" |
| 553 |
); |
553 |
); |
| 554 |
|
554 |
|
|
|
555 |
# Bug 38940 follow-up - Test that ConsiderLibraryHoursInCirculation='open' extends to next open day |
| 556 |
# when tomorrow is marked as a holiday in the calendar (even though it has operating hours defined) |
| 557 |
|
| 558 |
my $library3 = $builder->build( { source => 'Branch' } ); |
| 559 |
Koha::CirculationRules->set_rules( |
| 560 |
{ |
| 561 |
categorycode => $borrower->categorycode, |
| 562 |
itemtype => $itemtype, |
| 563 |
branchcode => $library3->{branchcode}, |
| 564 |
rules => { |
| 565 |
issuelength => 4, # loan period is 4 hours |
| 566 |
lengthunit => 'hours', |
| 567 |
daysmode => '', |
| 568 |
} |
| 569 |
} |
| 570 |
); |
| 571 |
|
| 572 |
# Set up hours for Friday (day 5), Saturday (day 6), and Monday (day 1) |
| 573 |
# Friday: 09:00-17:00, Saturday: 09:00-17:00, Monday: 09:00-17:00 |
| 574 |
my $fri_open = DateTime->new( year => 2023, month => 5, day => 5, hour => 10 )->hms; |
| 575 |
my $fri_close = DateTime->new( year => 2023, month => 5, day => 5, hour => 17 )->hms; |
| 576 |
my $sat_open = DateTime->new( year => 2023, month => 5, day => 6, hour => 10 )->hms; |
| 577 |
my $sat_close = DateTime->new( year => 2023, month => 5, day => 6, hour => 17 )->hms; |
| 578 |
my $mon_open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms; |
| 579 |
my $mon_close = DateTime->new( year => 2023, month => 5, day => 1, hour => 17 )->hms; |
| 580 |
my $friday_14 = DateTime->new( year => 2023, month => 5, day => 5, hour => 14 ); # 2PM on Friday |
| 581 |
|
| 582 |
# Set operating hours for Friday (day 5), Saturday (day 6), and Monday (day 1) |
| 583 |
Koha::Library::Hour->new( |
| 584 |
{ day => 5, library_id => $library3->{branchcode}, open_time => $fri_open, close_time => $fri_close } )->store; |
| 585 |
Koha::Library::Hour->new( |
| 586 |
{ day => 6, library_id => $library3->{branchcode}, open_time => $sat_open, close_time => $sat_close } )->store; |
| 587 |
Koha::Library::Hour->new( |
| 588 |
{ day => 1, library_id => $library3->{branchcode}, open_time => $mon_open, close_time => $mon_close } )->store; |
| 589 |
|
| 590 |
# Mark Saturday and Sunday as holidays in the calendar |
| 591 |
my $calendar3 = C4::Calendar->new( branchcode => $library3->{branchcode} ); |
| 592 |
$calendar3->insert_week_day_holiday( |
| 593 |
weekday => 6, |
| 594 |
title => 'Saturday', |
| 595 |
description => 'Saturday closure' |
| 596 |
); |
| 597 |
$calendar3->insert_week_day_holiday( |
| 598 |
weekday => 0, |
| 599 |
title => 'Sunday', |
| 600 |
description => 'Sunday closure' |
| 601 |
); |
| 602 |
|
| 603 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Calendar' ); |
| 604 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 605 |
|
| 606 |
# Test with 'open' mode - should extend to Monday's opening time (skipping Saturday and Sunday holidays) |
| 607 |
$date = C4::Circulation::CalcDateDue( $friday_14, $itemtype, $library3->{branchcode}, $borrower ); |
| 608 |
$expected_duetime = DateTime->new( year => 2023, month => 5, day => 8, hour => 10, minute => 0 ); |
| 609 |
is( |
| 610 |
$date, $expected_duetime, |
| 611 |
"Bug 38940 follow-up: Loan period extended to Monday opening when Saturday/Sunday are calendar holidays (ConsiderLibraryHoursInCirculation='open')" |
| 612 |
); |
| 613 |
|
| 614 |
# Test with 'close' mode - should still shorten to Friday's closing time (calendar holidays don't affect today) |
| 615 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'close' ); |
| 616 |
$date = C4::Circulation::CalcDateDue( $friday_14, $itemtype, $library3->{branchcode}, $borrower ); |
| 617 |
$expected_duetime = $friday_14->clone->set( hour => 17, minute => 0 ); |
| 618 |
is( |
| 619 |
$date, $expected_duetime, |
| 620 |
"Bug 38940 follow-up: Loan period shortened to closing time, unaffected by weekend holidays (ConsiderLibraryHoursInCirculation='close')" |
| 621 |
); |
| 622 |
|
| 623 |
# Test the same with Days mode (ignoring calendar) - should use tomorrow's hours directly |
| 624 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' ); |
| 625 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 626 |
$date = C4::Circulation::CalcDateDue( $friday_14, $itemtype, $library3->{branchcode}, $borrower ); |
| 627 |
$expected_duetime = DateTime->new( year => 2023, month => 5, day => 6, hour => 10, minute => 0 ); |
| 628 |
is( |
| 629 |
$date, $expected_duetime, |
| 630 |
"Bug 38940 follow-up: In Days mode, extends to Saturday (ignoring calendar holidays)" |
| 631 |
); |
| 632 |
|
| 633 |
# Test scenario where next open day has no operating hours - should fall back to ignoring library hours |
| 634 |
my $library4 = $builder->build( { source => 'Branch' } ); |
| 635 |
Koha::CirculationRules->set_rules( |
| 636 |
{ |
| 637 |
categorycode => $borrower->categorycode, |
| 638 |
itemtype => $itemtype, |
| 639 |
branchcode => $library4->{branchcode}, |
| 640 |
rules => { |
| 641 |
issuelength => 4, |
| 642 |
lengthunit => 'hours', |
| 643 |
daysmode => '', |
| 644 |
} |
| 645 |
} |
| 646 |
); |
| 647 |
|
| 648 |
# Set up hours only for Friday (day 5) |
| 649 |
Koha::Library::Hour->new( |
| 650 |
{ day => 5, library_id => $library4->{branchcode}, open_time => $fri_open, close_time => $fri_close } )->store; |
| 651 |
|
| 652 |
# Mark Saturday and Sunday as holidays, and don't define hours for Monday |
| 653 |
my $calendar4 = C4::Calendar->new( branchcode => $library4->{branchcode} ); |
| 654 |
$calendar4->insert_week_day_holiday( |
| 655 |
weekday => 6, |
| 656 |
title => 'Saturday', |
| 657 |
description => 'Saturday closure' |
| 658 |
); |
| 659 |
$calendar4->insert_week_day_holiday( |
| 660 |
weekday => 0, |
| 661 |
title => 'Sunday', |
| 662 |
description => 'Sunday closure' |
| 663 |
); |
| 664 |
|
| 665 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Calendar' ); |
| 666 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 667 |
|
| 668 |
# Should fall back to standard loan since no suitable open day with hours found |
| 669 |
$date = C4::Circulation::CalcDateDue( $friday_14, $itemtype, $library4->{branchcode}, $borrower ); |
| 670 |
$expected_duetime = $friday_14->clone->add( hours => 4 ); |
| 671 |
is( |
| 672 |
$date, $expected_duetime, |
| 673 |
"Bug 38940 follow-up: Falls back to standard loan when next open day has no operating hours" |
| 674 |
); |
| 675 |
|
| 676 |
# Test with a single day holiday (not weekly repeating) |
| 677 |
my $library5 = $builder->build( { source => 'Branch' } ); |
| 678 |
Koha::CirculationRules->set_rules( |
| 679 |
{ |
| 680 |
categorycode => $borrower->categorycode, |
| 681 |
itemtype => $itemtype, |
| 682 |
branchcode => $library5->{branchcode}, |
| 683 |
rules => { |
| 684 |
issuelength => 4, |
| 685 |
lengthunit => 'hours', |
| 686 |
daysmode => '', |
| 687 |
} |
| 688 |
} |
| 689 |
); |
| 690 |
|
| 691 |
# Set hours for all days of the week (0-6) |
| 692 |
for my $day ( 0 .. 6 ) { |
| 693 |
Koha::Library::Hour->new( |
| 694 |
{ day => $day, library_id => $library5->{branchcode}, open_time => $fri_open, close_time => $fri_close } ) |
| 695 |
->store; |
| 696 |
} |
| 697 |
|
| 698 |
# Mark Saturday May 6, 2023 and Sunday May 7, 2023 as single day holidays |
| 699 |
my $calendar5 = C4::Calendar->new( branchcode => $library5->{branchcode} ); |
| 700 |
my $specific_saturday = DateTime->new( year => 2023, month => 5, day => 6 ); |
| 701 |
$calendar5->insert_single_holiday( |
| 702 |
day => $specific_saturday->day, |
| 703 |
month => $specific_saturday->month, |
| 704 |
year => $specific_saturday->year, |
| 705 |
title => 'Public Holiday', |
| 706 |
description => 'Special bank holiday' |
| 707 |
); |
| 708 |
my $specific_sunday = DateTime->new( year => 2023, month => 5, day => 7 ); |
| 709 |
$calendar5->insert_single_holiday( |
| 710 |
day => $specific_sunday->day, |
| 711 |
month => $specific_sunday->month, |
| 712 |
year => $specific_sunday->year, |
| 713 |
title => 'Sunday', |
| 714 |
description => 'Sunday closure' |
| 715 |
); |
| 716 |
|
| 717 |
t::lib::Mocks::mock_preference( 'useDaysMode', 'Calendar' ); |
| 718 |
t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); |
| 719 |
|
| 720 |
# Should extend to Monday (skipping Saturday public holiday and Sunday which has no hours) |
| 721 |
$date = C4::Circulation::CalcDateDue( $friday_14, $itemtype, $library5->{branchcode}, $borrower ); |
| 722 |
$expected_duetime = DateTime->new( year => 2023, month => 5, day => 8, hour => 10, minute => 0 ); |
| 723 |
is( |
| 724 |
$date, $expected_duetime, |
| 725 |
"Bug 38940 follow-up: Extends to Monday when Saturday is single-day holiday" |
| 726 |
); |
| 727 |
|
| 555 |
$cache->clear_from_cache($key); |
728 |
$cache->clear_from_cache($key); |
| 556 |
$schema->storage->txn_rollback; |
729 |
$schema->storage->txn_rollback; |
| 557 |
- |
|
|