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 ); |
|
|
101 |
|
100 |
|
102 |
is( $debarments->[0]->{expiration}, |
101 |
my $THE_suspension = $suspensions->next; |
|
|
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 2508-2514
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2508 |
plan tests => 8; |
2508 |
plan tests => 8; |
2509 |
|
2509 |
|
2510 |
my $library = $builder->build( { source => 'Branch' } ); |
2510 |
my $library = $builder->build( { source => 'Branch' } ); |
2511 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2511 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2512 |
|
2512 |
|
2513 |
# Add 2 items |
2513 |
# Add 2 items |
2514 |
my $biblionumber = $builder->build_sample_biblio( |
2514 |
my $biblionumber = $builder->build_sample_biblio( |
Lines 2549-2563
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2549 |
my $now = dt_from_string; |
2549 |
my $now = dt_from_string; |
2550 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2550 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2551 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2551 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2552 |
AddIssue( $patron, $item_1->barcode, $five_days_ago ); # Add an overdue |
2552 |
AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # Add an overdue |
2553 |
AddIssue( $patron, $item_2->barcode, $ten_days_ago ) |
2553 |
AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago ) |
2554 |
; # Add another overdue |
2554 |
; # Add another overdue |
2555 |
|
2555 |
|
2556 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
2556 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' ); |
2557 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2557 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2558 |
my $debarments = Koha::Patron::Debarments::GetDebarments( |
2558 |
my $suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2559 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2559 |
is( $suspensions->count, 1, "Suspension added" ); |
2560 |
is( scalar(@$debarments), 1 ); |
2560 |
my $THE_suspension = $suspensions->next; |
2561 |
|
2561 |
|
2562 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
2562 |
# FIXME Is it right? I'd have expected 5 * 2 - 1 instead |
2563 |
# Same for the others |
2563 |
# Same for the others |
Lines 2568-2579
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2568 |
dateonly => 1 |
2568 |
dateonly => 1 |
2569 |
} |
2569 |
} |
2570 |
); |
2570 |
); |
2571 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2571 |
is( $THE_suspension->expiration, $expected_expiration, "Suspesion expiration set" ); |
2572 |
|
2572 |
|
2573 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2573 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2574 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2574 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2575 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2575 |
is( $suspensions->count, 1, "Only one suspension" ); |
2576 |
is( scalar(@$debarments), 1 ); |
2576 |
$THE_suspension = $suspensions->next; |
|
|
2577 |
|
2577 |
$expected_expiration = output_pref( |
2578 |
$expected_expiration = output_pref( |
2578 |
{ |
2579 |
{ |
2579 |
dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), |
2580 |
dt => $now->clone->add( days => ( 10 - 1 ) * 2 ), |
Lines 2581-2599
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2581 |
dateonly => 1 |
2582 |
dateonly => 1 |
2582 |
} |
2583 |
} |
2583 |
); |
2584 |
); |
2584 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2585 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2585 |
|
2586 |
|
2586 |
Koha::Patron::Debarments::DelUniqueDebarment( |
2587 |
Koha::Patron::Debarments::DelUniqueDebarment( |
2587 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2588 |
{ borrowernumber => $patron->borrowernumber, type => 'SUSPENSION' } ); |
2588 |
|
2589 |
|
2589 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
2590 |
t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '1' ); |
2590 |
AddIssue( $patron, $item_1->barcode, $five_days_ago ); # Add an overdue |
2591 |
AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # Add an overdue |
2591 |
AddIssue( $patron, $item_2->barcode, $ten_days_ago ) |
2592 |
AddIssue( $patron->unblessed, $item_2->barcode, $ten_days_ago ) |
2592 |
; # Add another overdue |
2593 |
; # Add another overdue |
2593 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2594 |
AddReturn( $item_1->barcode, $library->{branchcode}, undef, $now ); |
2594 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2595 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2595 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2596 |
is( $suspensions->count, 1, "Only one suspension" ); |
2596 |
is( scalar(@$debarments), 1 ); |
2597 |
$THE_suspension = $suspensions->next; |
|
|
2598 |
|
2597 |
$expected_expiration = output_pref( |
2599 |
$expected_expiration = output_pref( |
2598 |
{ |
2600 |
{ |
2599 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
2601 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 ), |
Lines 2601-2612
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2601 |
dateonly => 1 |
2603 |
dateonly => 1 |
2602 |
} |
2604 |
} |
2603 |
); |
2605 |
); |
2604 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2606 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2605 |
|
2607 |
|
2606 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2608 |
AddReturn( $item_2->barcode, $library->{branchcode}, undef, $now ); |
2607 |
$debarments = Koha::Patron::Debarments::GetDebarments( |
2609 |
$suspensions = $patron->restrictions->search( { type => 'SUSPENSION' } ); |
2608 |
{ borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } ); |
2610 |
is( $suspensions->count, 1, "Only one suspension" ); |
2609 |
is( scalar(@$debarments), 1 ); |
2611 |
$THE_suspension = $suspensions->next; |
|
|
2612 |
|
2610 |
$expected_expiration = output_pref( |
2613 |
$expected_expiration = output_pref( |
2611 |
{ |
2614 |
{ |
2612 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
2615 |
dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ), |
Lines 2614-2627
subtest 'AddReturn + CumulativeRestrictionPeriods' => sub {
Link Here
|
2614 |
dateonly => 1 |
2617 |
dateonly => 1 |
2615 |
} |
2618 |
} |
2616 |
); |
2619 |
); |
2617 |
is( $debarments->[0]->{expiration}, $expected_expiration ); |
2620 |
is( $THE_suspension->expiration, $expected_expiration, "Suspension expiration date updated" ); |
2618 |
}; |
2621 |
}; |
2619 |
|
2622 |
|
2620 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
2623 |
subtest 'AddReturn + suspension_chargeperiod' => sub { |
2621 |
plan tests => 27; |
2624 |
plan tests => 27; |
2622 |
|
2625 |
|
2623 |
my $library = $builder->build( { source => 'Branch' } ); |
2626 |
my $library = $builder->build( { source => 'Branch' } ); |
2624 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2627 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } ); |
2625 |
|
2628 |
|
2626 |
my $biblionumber = $builder->build_sample_biblio( |
2629 |
my $biblionumber = $builder->build_sample_biblio( |
2627 |
{ |
2630 |
{ |
Lines 2905-2912
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2905 |
t::lib::Mocks::mock_preference('MaxFine', '100'); |
2908 |
t::lib::Mocks::mock_preference('MaxFine', '100'); |
2906 |
|
2909 |
|
2907 |
my $library = $builder->build( { source => 'Branch' } ); |
2910 |
my $library = $builder->build( { source => 'Branch' } ); |
2908 |
my $patron = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } ); |
2911 |
my $patron = $builder->build_object( |
2909 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2912 |
{ |
|
|
2913 |
class => 'Koha::Patrons', |
2914 |
value => { categorycode => $patron_category->{categorycode} } |
2915 |
} |
2916 |
); |
2917 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
2910 |
t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode }); |
2918 |
t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode }); |
2911 |
|
2919 |
|
2912 |
my $item = $builder->build_sample_item( |
2920 |
my $item = $builder->build_sample_item( |
Lines 2936-2942
subtest 'AddReturn | is_overdue' => sub {
Link Here
|
2936 |
my $two_days_ago = $now->clone->subtract( days => 2 ); |
2944 |
my $two_days_ago = $now->clone->subtract( days => 2 ); |
2937 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2945 |
my $five_days_ago = $now->clone->subtract( days => 5 ); |
2938 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2946 |
my $ten_days_ago = $now->clone->subtract( days => 10 ); |
2939 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
|
|
2940 |
|
2947 |
|
2941 |
# No return date specified, today will be used => 10 days overdue charged |
2948 |
# No return date specified, today will be used => 10 days overdue charged |
2942 |
AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago |
2949 |
AddIssue( $patron->unblessed, $item->barcode, $ten_days_ago ); # date due was 10d ago |
2943 |
- |
|
|