View | Details | Raw Unified | Return to bug 31095
Collapse All | Expand All

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

Return to bug 31095