Lines 46-52
use Koha::Items;
Link Here
|
46 |
use Koha::Item::Transfers; |
46 |
use Koha::Item::Transfers; |
47 |
use Koha::Checkouts; |
47 |
use Koha::Checkouts; |
48 |
use Koha::Patrons; |
48 |
use Koha::Patrons; |
49 |
use Koha::Patron::Debarments qw( GetDebarments AddDebarment DelUniqueDebarment ); |
49 |
use Koha::Patron::Debarments qw( AddDebarment DelUniqueDebarment ); |
50 |
use Koha::Holds; |
50 |
use Koha::Holds; |
51 |
use Koha::CirculationRules; |
51 |
use Koha::CirculationRules; |
52 |
use Koha::Subscriptions; |
52 |
use Koha::Subscriptions; |
Lines 90-108
sub test_debarment_on_checkout {
Link Here
|
90 |
); |
90 |
); |
91 |
my @caller = caller; |
91 |
my @caller = caller; |
92 |
my $line_number = $caller[2]; |
92 |
my $line_number = $caller[2]; |
93 |
AddIssue( $patron, $item->barcode, $due_date ); |
93 |
AddIssue( $patron->unblessed, $item->barcode, $due_date ); |
94 |
|
94 |
|
95 |
my ( undef, $message ) = AddReturn( $item->barcode, $library->{branchcode}, undef, $return_date ); |
95 |
my ( undef, $message ) = AddReturn( $item->barcode, $library->{branchcode}, undef, $return_date ); |
96 |
is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' ) |
96 |
is( $message->{WasReturned} && exists $message->{Debarred}, 1, 'AddReturn must have debarred the patron' ) |
97 |
or diag('AddReturn returned message ' . Dumper $message ); |
97 |
or diag('AddReturn returned message ' . Dumper $message ); |
98 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
98 |
my $suspensions = $patron->restrictions->search({ type => 'SUSPENSION' } ); |
99 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
99 |
is( $suspensions->count, 1, 'Test at line ' . $line_number ); |
100 |
is( scalar(@$debarments), 1, 'Test at line ' . $line_number ); |
100 |
|
101 |
|
101 |
my $THE_suspension = $suspensions->next; |
102 |
is( $debarments->[0]->{expiration}, |
102 |
is( $THE_suspension->expiration, |
103 |
$expected_expiration_date, 'Test at line ' . $line_number ); |
103 |
$expected_expiration_date, 'Test at line ' . $line_number ); |
104 |
Koha::Patron::Debarments::DelUniqueDebarment( |
104 |
Koha::Patron::Debarments::DelUniqueDebarment( |
105 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
105 |
{ borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } ); |
106 |
}; |
106 |
}; |
107 |
|
107 |
|
108 |
my $schema = Koha::Database->schema; |
108 |
my $schema = Koha::Database->schema; |
Lines 2488-2494
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2488 |
plan tests => 8; |
2488 |
plan tests => 8; |
2489 |
|
2489 |
|
2490 |
my $library = $builder->build( { source => 'Branch' } ); |
2490 |
my $library = $builder->build( { source => 'Branch' } ); |
2491 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2491 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2492 |
|
2492 |
|
2493 |
# Add 2 items |
2493 |
# Add 2 items |
2494 |
my $biblionumber = $builder->build_sample_biblio( |
2494 |
my $biblionumber = $builder->build_sample_biblio( |
Lines 2529-2543
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2529 |
my $now = dt_from_string; |
2529 |
my $now = dt_from_string; |
2530 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2530 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2531 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2531 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2532 |
AddIssue( $patron, $item_1->barcode, $five_days_ago ); # Add an overdue |
2532 |
AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # Add an overdue |
2533 |
AddIssue( $patron, $item_2->barcode, $ten_days_ago ) |
2533 |
AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago ) |
2534 |
; # Add another overdue |
2534 |
; # Add another overdue |
2535 |
|
2535 |
|
2536 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
2536 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
2537 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2537 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2538 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
2538 |
my $suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2539 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2539 |
is( $suspensions->count, 1, "Suspension added" ); |
2540 |
is( scalar(@$debarments), 1 ); |
2540 |
my $THE_suspension = $suspensions->next; |
2541 |
|
2541 |
|
2542 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
2542 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
2543 |
# Same for the others |
2543 |
# Same for the others |
Lines 2548-2559
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2548 |
dateonly => 1 |
2548 |
dateonly => 1 |
2549 |
} |
2549 |
} |
2550 |
); |
2550 |
); |
2551 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2551 |
is( $THE_suspension->expiration, $expected_expiration, "Suspesion expiration set" ); |
2552 |
|
2552 |
|
2553 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2553 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2554 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2554 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2555 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2555 |
is( $suspensions->count, 1, "Only one suspension" ); |
2556 |
is( scalar(@$debarments), 1 ); |
2556 |
$THE_suspension = $suspensions->next; |
|
|
2557 |
|
2557 |
$expected_expiration = output_pref( |
2558 |
$expected_expiration = output_pref( |
2558 |
{ |
2559 |
{ |
2559 |
dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), |
2560 |
dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), |
Lines 2561-2579
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2561 |
dateonly => 1 |
2562 |
dateonly => 1 |
2562 |
} |
2563 |
} |
2563 |
); |
2564 |
); |
2564 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2565 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2565 |
|
2566 |
|
2566 |
Koha::Patron::Debarments::DelUniqueDebarment( |
2567 |
Koha::Patron::Debarments::DelUniqueDebarment( |
2567 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2568 |
{ borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } ); |
2568 |
|
2569 |
|
2569 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
2570 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
2570 |
AddIssue( $patron, $item_1->barcode, $five_days_ago ); # Add an overdue |
2571 |
AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # Add an overdue |
2571 |
AddIssue( $patron, $item_2->barcode, $ten_days_ago ) |
2572 |
AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago ) |
2572 |
; # Add another overdue |
2573 |
; # Add another overdue |
2573 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2574 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2574 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2575 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2575 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2576 |
is( $suspensions->count, 1, "Only one suspension" ); |
2576 |
is( scalar(@$debarments), 1 ); |
2577 |
$THE_suspension = $suspensions->next; |
|
|
2578 |
|
2577 |
$expected_expiration = output_pref( |
2579 |
$expected_expiration = output_pref( |
2578 |
{ |
2580 |
{ |
2579 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
2581 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
Lines 2581-2592
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2581 |
dateonly => 1 |
2583 |
dateonly => 1 |
2582 |
} |
2584 |
} |
2583 |
); |
2585 |
); |
2584 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2586 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2585 |
|
2587 |
|
2586 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2588 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2587 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2589 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2588 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2590 |
is( $suspensions->count, 1, "Only one suspension" ); |
2589 |
is( scalar(@$debarments), 1 ); |
2591 |
$THE_suspension = $suspensions->next; |
|
|
2592 |
|
2590 |
$expected_expiration = output_pref( |
2593 |
$expected_expiration = output_pref( |
2591 |
{ |
2594 |
{ |
2592 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
2595 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
Lines 2594-2607
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2594 |
dateonly => 1 |
2597 |
dateonly => 1 |
2595 |
} |
2598 |
} |
2596 |
); |
2599 |
); |
2597 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2600 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2598 |
}; |
2601 |
}; |
2599 |
|
2602 |
|
2600 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
2603 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
2601 |
plan tests => 27; |
2604 |
plan tests => 27; |
2602 |
|
2605 |
|
2603 |
my $library = $builder->build( { source => 'Branch' } ); |
2606 |
my $library = $builder->build( { source => 'Branch' } ); |
2604 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2607 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2605 |
|
2608 |
|
2606 |
my $biblionumber = $builder->build_sample_biblio( |
2609 |
my $biblionumber = $builder->build_sample_biblio( |
2607 |
{ |
2610 |
{ |
Lines 2885-2892
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2885 |
t::lib::Mocks::mock_preference('MaxFine', '100'); |
2888 |
t::lib::Mocks::mock_preference('MaxFine', '100'); |
2886 |
|
2889 |
|
2887 |
my $library = $builder->build( { source => 'Branch' } ); |
2890 |
my $library = $builder->build( { source => 'Branch' } ); |
2888 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2891 |
my $patron = $builder->build_object( |
2889 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2892 |
{ |
|
|
2893 |
class => 'Koha::Patrons', |
2894 |
value => { categorycode => $patron_category->{categorycode} } |
2895 |
} |
2896 |
); |
2897 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
2890 |
t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode }); |
2898 |
t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode }); |
2891 |
|
2899 |
|
2892 |
my $item = $builder->build_sample_item( |
2900 |
my $item = $builder->build_sample_item( |
Lines 2916-2922
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2916 |
my $two_days_ago = $now->clone->subtract( days => 2 ); |
2924 |
my $two_days_ago = $now->clone->subtract( days => 2 ); |
2917 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2925 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2918 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2926 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2919 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
|
|
2920 |
|
2927 |
|
2921 |
# No return date specified, today will be used => 10 days overdue charged |
2928 |
# No return date specified, today will be used => 10 days overdue charged |
2922 |
AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago |
2929 |
AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago |
2923 |
- |
|
|