|
Lines 19-25
use Modern::Perl;
Link Here
|
| 19 |
use utf8; |
19 |
use utf8; |
| 20 |
|
20 |
|
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::More tests => 84; |
22 |
use Test::More tests => 85; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Deep qw( cmp_deeply ); |
25 |
use Test::Deep qw( cmp_deeply ); |
|
Lines 339-345
subtest 'AddIssue | renewal when adding issue to same borrower' => sub {
Link Here
|
| 339 |
my $staff = $builder->build_object( { class => "Koha::Patrons" } ); |
339 |
my $staff = $builder->build_object( { class => "Koha::Patrons" } ); |
| 340 |
t::lib::Mocks::mock_userenv( { patron => $staff } ); |
340 |
t::lib::Mocks::mock_userenv( { patron => $staff } ); |
| 341 |
|
341 |
|
| 342 |
t::lib::Mocks::mock_preference( 'RenewalPeriodBase', 'date_due' ); |
342 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'date_due' ); |
| 343 |
|
343 |
|
| 344 |
my $issue = AddIssue( $patron, $item->barcode ); |
344 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 345 |
is( dt_from_string( $issue->date_due )->truncate( to => 'day' ), $seven_days, "Item issued for correct term" ); |
345 |
is( dt_from_string( $issue->date_due )->truncate( to => 'day' ), $seven_days, "Item issued for correct term" ); |
|
Lines 866-872
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 866 |
|
866 |
|
| 867 |
# Calculate new due-date based on the present date not to incur |
867 |
# Calculate new due-date based on the present date not to incur |
| 868 |
# multiple fees |
868 |
# multiple fees |
| 869 |
t::lib::Mocks::mock_preference( 'RenewalPeriodBase', 'now' ); |
869 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'now' ); |
| 870 |
|
870 |
|
| 871 |
my $staff = $builder->build_object( { class => "Koha::Patrons" } ); |
871 |
my $staff = $builder->build_object( { class => "Koha::Patrons" } ); |
| 872 |
t::lib::Mocks::mock_userenv( { patron => $staff } ); |
872 |
t::lib::Mocks::mock_userenv( { patron => $staff } ); |
|
Lines 1185-1191
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1185 |
); |
1185 |
); |
| 1186 |
|
1186 |
|
| 1187 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1187 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1188 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1188 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1189 |
my $issue = AddIssue( |
1189 |
my $issue = AddIssue( |
| 1190 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
1190 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
| 1191 |
undef, { auto_renew => 1 } |
1191 |
undef, { auto_renew => 1 } |
|
Lines 1335-1341
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1335 |
); |
1335 |
); |
| 1336 |
|
1336 |
|
| 1337 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1337 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1338 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1338 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1339 |
my $issue = AddIssue( |
1339 |
my $issue = AddIssue( |
| 1340 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
1340 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
| 1341 |
undef, { auto_renew => 1 } |
1341 |
undef, { auto_renew => 1 } |
|
Lines 1445-1451
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1445 |
); |
1445 |
); |
| 1446 |
|
1446 |
|
| 1447 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1447 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1448 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1448 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1449 |
|
1449 |
|
| 1450 |
# Patron is expired and BlockExpiredPatronOpacActions='' |
1450 |
# Patron is expired and BlockExpiredPatronOpacActions='' |
| 1451 |
# => auto renew is allowed |
1451 |
# => auto renew is allowed |
|
Lines 1497-1503
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1497 |
); |
1497 |
); |
| 1498 |
|
1498 |
|
| 1499 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1499 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1500 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1500 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1501 |
my $issue = AddIssue( |
1501 |
my $issue = AddIssue( |
| 1502 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
1502 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
| 1503 |
undef, { auto_renew => 1 } |
1503 |
undef, { auto_renew => 1 } |
|
Lines 1618-1624
subtest "CanBookBeRenewed tests" => sub {
Link Here
|
| 1618 |
); |
1618 |
); |
| 1619 |
|
1619 |
|
| 1620 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
1620 |
my $ten_days_before = dt_from_string->add( days => -10 ); |
| 1621 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
1621 |
my $ten_days_ahead = dt_from_string->add( days => 10 ); |
| 1622 |
my $issue = AddIssue( |
1622 |
my $issue = AddIssue( |
| 1623 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
1623 |
$renewing_borrower_obj, $item_to_auto_renew->barcode, $ten_days_ahead, undef, $ten_days_before, |
| 1624 |
undef, { auto_renew => 1 } |
1624 |
undef, { auto_renew => 1 } |
|
Lines 1905-1912
subtest "CanBookBeRenewed | bookings" => sub {
Link Here
|
| 1905 |
my $schema = Koha::Database->schema; |
1905 |
my $schema = Koha::Database->schema; |
| 1906 |
$schema->storage->txn_begin; |
1906 |
$schema->storage->txn_begin; |
| 1907 |
|
1907 |
|
| 1908 |
t::lib::Mocks::mock_preference( 'RenewalPeriodBase', 'date_due' ); |
1908 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'date_due' ); |
| 1909 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
1909 |
t::lib::Mocks::mock_preference( 'ChildNeedsGuarantor', 0 ); |
| 1910 |
|
1910 |
|
| 1911 |
my $renewing_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1911 |
my $renewing_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1912 |
my $booked_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1912 |
my $booked_patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
|
Lines 2020-2026
subtest "GetUpcomingDueIssues" => sub {
Link Here
|
| 2020 |
my $a_borrower = Koha::Patrons->find($a_borrower_borrowernumber); |
2020 |
my $a_borrower = Koha::Patrons->find($a_borrower_borrowernumber); |
| 2021 |
|
2021 |
|
| 2022 |
my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 ); |
2022 |
my $yesterday = DateTime->today( time_zone => C4::Context->tz() )->add( days => -1 ); |
| 2023 |
my $two_days_ahead = DateTime->today( time_zone => C4::Context->tz() )->add( days => 2 ); |
2023 |
my $two_days_ahead = DateTime->today( time_zone => C4::Context->tz() )->add( days => 2 ); |
| 2024 |
my $today = DateTime->today( time_zone => C4::Context->tz() ); |
2024 |
my $today = DateTime->today( time_zone => C4::Context->tz() ); |
| 2025 |
|
2025 |
|
| 2026 |
my $issue = AddIssue( $a_borrower, $item_1->barcode, $yesterday ); |
2026 |
my $issue = AddIssue( $a_borrower, $item_1->barcode, $yesterday ); |
|
Lines 3932-3938
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
| 3932 |
is( $line->status, 'RETURNED', "Overdue fine is fixed" ); |
3932 |
is( $line->status, 'RETURNED', "Overdue fine is fixed" ); |
| 3933 |
$line = $lines->next; |
3933 |
$line = $lines->next; |
| 3934 |
is( $line->amount + 0, -2, "Original payment amount remains as 2" ); |
3934 |
is( $line->amount + 0, -2, "Original payment amount remains as 2" ); |
| 3935 |
is( $line->amountoutstanding + 0, 0, "Original payment remains applied" ); |
3935 |
is( $line->amountoutstanding + 0, 0, "Original payment remains applied" ); |
| 3936 |
$line = $lines->next; |
3936 |
$line = $lines->next; |
| 3937 |
is( $line->amount + 0, -1, "Refund amount correctly set to 1" ); |
3937 |
is( $line->amount + 0, -1, "Refund amount correctly set to 1" ); |
| 3938 |
is( $line->amountoutstanding + 0, -1, "Refund amount outstanding unspent" ); |
3938 |
is( $line->amountoutstanding + 0, -1, "Refund amount outstanding unspent" ); |
|
Lines 4886-4892
subtest '_FixOverduesOnReturn' => sub {
Link Here
|
| 4886 |
my $credit = $offset->credit; |
4886 |
my $credit = $offset->credit; |
| 4887 |
is( ref $credit, "Koha::Account::Line", "Found matching credit for fine forgiveness" ); |
4887 |
is( ref $credit, "Koha::Account::Line", "Found matching credit for fine forgiveness" ); |
| 4888 |
is( $credit->amount + 0, -99, "Credit amount is set correctly" ); |
4888 |
is( $credit->amount + 0, -99, "Credit amount is set correctly" ); |
| 4889 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
4889 |
is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); |
| 4890 |
|
4890 |
|
| 4891 |
# Bug 25417 - Only forgive fines where there is an amount outstanding to forgive |
4891 |
# Bug 25417 - Only forgive fines where there is an amount outstanding to forgive |
| 4892 |
$accountline->set( |
4892 |
$accountline->set( |
|
Lines 7566-7571
subtest 'Test CanBookBeIssued param ignore_reserves (Bug 35322)' => sub {
Link Here
|
| 7566 |
|
7566 |
|
| 7567 |
}; |
7567 |
}; |
| 7568 |
|
7568 |
|
|
|
7569 |
subtest "Check AutomaticRenewalPeriodBase vs ManualRenewalPeriodBase ( Bug 30331 )" => sub { |
| 7570 |
plan tests => 4; |
| 7571 |
|
| 7572 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 7573 |
my $patron = |
| 7574 |
$builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library->branchcode } } ); |
| 7575 |
my $item = $builder->build_sample_item( { library => $library->branchcode } ); |
| 7576 |
my $staff = $builder->build_object( { class => "Koha::Patrons" } ); |
| 7577 |
t::lib::Mocks::mock_userenv( { patron => $staff, branchcode => $library->branchcode } ); |
| 7578 |
|
| 7579 |
Koha::CirculationRules->set_rules( |
| 7580 |
{ |
| 7581 |
categorycode => undef, |
| 7582 |
branchcode => undef, |
| 7583 |
itemtype => $item->effective_itemtype, |
| 7584 |
rules => { |
| 7585 |
issuelength => 14, |
| 7586 |
lengthunit => 'days', |
| 7587 |
renewalperiod => 7, |
| 7588 |
renewalsallowed => 5, |
| 7589 |
} |
| 7590 |
} |
| 7591 |
); |
| 7592 |
|
| 7593 |
#Manual renewal with ManualRenewalPeriodBase === 'date_due' |
| 7594 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'date_due' ); |
| 7595 |
t::lib::Mocks::mock_preference( 'AutomaticRenewalPeriodBase', 'now' ); |
| 7596 |
|
| 7597 |
my $issue = AddIssue( $patron, $item->barcode ); |
| 7598 |
my $original_due = dt_from_string( $issue->date_due ); |
| 7599 |
my $expected_due = $original_due->clone()->add( days => 7 ); |
| 7600 |
|
| 7601 |
my $manual_due = AddRenewal( |
| 7602 |
{ |
| 7603 |
borrowernumber => $patron->borrowernumber, |
| 7604 |
itemnumber => $item->itemnumber, |
| 7605 |
branch => $library->branchcode, |
| 7606 |
automatic => 0, |
| 7607 |
} |
| 7608 |
); |
| 7609 |
|
| 7610 |
is( |
| 7611 |
$manual_due->truncate( to => 'day' )->ymd, |
| 7612 |
$expected_due->truncate( to => 'day' )->ymd, |
| 7613 |
'Manual renewal based off of old due date' |
| 7614 |
); |
| 7615 |
|
| 7616 |
#Manual renewal with ManualRenewalPeriodBase === 'now' |
| 7617 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'now' ); |
| 7618 |
|
| 7619 |
$issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); |
| 7620 |
my $now = dt_from_string(); |
| 7621 |
$expected_due = $now->clone()->add( days => 7 ); |
| 7622 |
|
| 7623 |
$manual_due = AddRenewal( |
| 7624 |
{ |
| 7625 |
borrowernumber => $patron->borrowernumber, |
| 7626 |
itemnumber => $item->itemnumber, |
| 7627 |
branch => $library->branchcode, |
| 7628 |
automatic => 0, |
| 7629 |
} |
| 7630 |
); |
| 7631 |
|
| 7632 |
is( |
| 7633 |
$manual_due->truncate( to => 'day' )->ymd, |
| 7634 |
$expected_due->truncate( to => 'day' )->ymd, |
| 7635 |
'Manual renewal based off of current date' |
| 7636 |
); |
| 7637 |
|
| 7638 |
#Automatic renewal with AutomaticRenewalPeriodBase === 'date_due' |
| 7639 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'now' ); |
| 7640 |
t::lib::Mocks::mock_preference( 'AutomaticRenewalPeriodBase', 'date_due' ); |
| 7641 |
|
| 7642 |
$issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); |
| 7643 |
$original_due = dt_from_string( $issue->date_due ); |
| 7644 |
$expected_due = $original_due->clone()->add( days => 7 ); |
| 7645 |
|
| 7646 |
my $auto_due = AddRenewal( |
| 7647 |
{ |
| 7648 |
borrowernumber => $patron->borrowernumber, |
| 7649 |
itemnumber => $item->itemnumber, |
| 7650 |
branch => $library->branchcode, |
| 7651 |
automatic => 1, |
| 7652 |
} |
| 7653 |
); |
| 7654 |
|
| 7655 |
is( |
| 7656 |
$auto_due->truncate( to => 'day' )->ymd, |
| 7657 |
$expected_due->truncate( to => 'day' )->ymd, |
| 7658 |
'Automatic renewal uses old checkout date' |
| 7659 |
); |
| 7660 |
|
| 7661 |
#Automatic renewal with AutomaticRenewalPeriodBase === 'now' |
| 7662 |
t::lib::Mocks::mock_preference( 'ManualRenewalPeriodBase', 'date_due' ); |
| 7663 |
t::lib::Mocks::mock_preference( 'AutomaticRenewalPeriodBase', 'now' ); |
| 7664 |
|
| 7665 |
$issue = Koha::Checkouts->find( { itemnumber => $item->itemnumber } ); |
| 7666 |
$now = dt_from_string(); |
| 7667 |
$expected_due = $now->clone()->add( days => 7 ); |
| 7668 |
|
| 7669 |
$auto_due = AddRenewal( |
| 7670 |
{ |
| 7671 |
borrowernumber => $patron->borrowernumber, |
| 7672 |
itemnumber => $item->itemnumber, |
| 7673 |
branch => $library->branchcode, |
| 7674 |
automatic => 1, |
| 7675 |
} |
| 7676 |
); |
| 7677 |
|
| 7678 |
is( |
| 7679 |
$auto_due->truncate( to => 'day' )->ymd, |
| 7680 |
$expected_due->truncate( to => 'day' )->ymd, |
| 7681 |
'Automatic renewal uses current date' |
| 7682 |
); |
| 7683 |
}; |
| 7684 |
|
| 7569 |
subtest 'NoRefundOnLostFinesPaidAge' => sub { |
7685 |
subtest 'NoRefundOnLostFinesPaidAge' => sub { |
| 7570 |
plan tests => 2; |
7686 |
plan tests => 2; |
| 7571 |
|
7687 |
|
|
Lines 7637-7643
subtest 'NoRefundOnLostFinesPaidAge' => sub {
Link Here
|
| 7637 |
{ |
7753 |
{ |
| 7638 |
borrowernumber => $patron->id, |
7754 |
borrowernumber => $patron->id, |
| 7639 |
date => '1970-01-01 14:00:01', |
7755 |
date => '1970-01-01 14:00:01', |
| 7640 |
amountoutstanding => 0, |
7756 |
amountoutstanding => 0, |
| 7641 |
amount => -5, |
7757 |
amount => -5, |
| 7642 |
interface => 'commandline', |
7758 |
interface => 'commandline', |
| 7643 |
credit_type_code => 'PAYMENT' |
7759 |
credit_type_code => 'PAYMENT' |
|
Lines 7693-7699
subtest 'NoRefundOnLostFinesPaidAge' => sub {
Link Here
|
| 7693 |
borrowernumber => $patron2->id, |
7809 |
borrowernumber => $patron2->id, |
| 7694 |
date => '1970-01-01 14:00:01', |
7810 |
date => '1970-01-01 14:00:01', |
| 7695 |
amount => -5, |
7811 |
amount => -5, |
| 7696 |
amountoutstanding => 0, |
7812 |
amountoutstanding => 0, |
| 7697 |
interface => 'commandline', |
7813 |
interface => 'commandline', |
| 7698 |
credit_type_code => 'PAYMENT' |
7814 |
credit_type_code => 'PAYMENT' |
| 7699 |
} |
7815 |
} |
| 7700 |
- |
|
|