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

(-)a/t/db_dependent/Circulation.t (-34 / +38 lines)
Lines 2007-2020 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2007
    );
2007
    );
2008
2008
2009
    # Patron cannot issue item_1, they have overdues
2009
    # Patron cannot issue item_1, they have overdues
2010
    my $five_days_ago = dt_from_string->subtract( days => 5 );
2010
    my $now = dt_from_string;
2011
    my $ten_days_ago  = dt_from_string->subtract( days => 10 );
2011
    my $five_days_ago = $now->clone->subtract( days => 5 );
2012
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2012
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2013
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2013
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2014
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2014
      ;    # Add another overdue
2015
      ;    # Add another overdue
2015
2016
2016
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
2017
    t::lib::Mocks::mock_preference( 'CumulativeRestrictionPeriods', '0' );
2017
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
2018
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now );
2018
    my $debarments = Koha::Patron::Debarments::GetDebarments(
2019
    my $debarments = Koha::Patron::Debarments::GetDebarments(
2019
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2020
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2020
    is( scalar(@$debarments), 1 );
2021
    is( scalar(@$debarments), 1 );
Lines 2023-2042 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2023
    # Same for the others
2024
    # Same for the others
2024
    my $expected_expiration = output_pref(
2025
    my $expected_expiration = output_pref(
2025
        {
2026
        {
2026
            dt         => dt_from_string->add( days => ( 5 - 1 ) * 2 ),
2027
            dt         => $now->clone->add( days => ( 5 - 1 ) * 2 ),
2027
            dateformat => 'sql',
2028
            dateformat => 'sql',
2028
            dateonly   => 1
2029
            dateonly   => 1
2029
        }
2030
        }
2030
    );
2031
    );
2031
    is( $debarments->[0]->{expiration}, $expected_expiration );
2032
    is( $debarments->[0]->{expiration}, $expected_expiration );
2032
2033
2033
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
2034
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now );
2034
    $debarments = Koha::Patron::Debarments::GetDebarments(
2035
    $debarments = Koha::Patron::Debarments::GetDebarments(
2035
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2036
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2036
    is( scalar(@$debarments), 1 );
2037
    is( scalar(@$debarments), 1 );
2037
    $expected_expiration = output_pref(
2038
    $expected_expiration = output_pref(
2038
        {
2039
        {
2039
            dt         => dt_from_string->add( days => ( 10 - 1 ) * 2 ),
2040
            dt         => $now->clone->add( days => ( 10 - 1 ) * 2 ),
2040
            dateformat => 'sql',
2041
            dateformat => 'sql',
2041
            dateonly   => 1
2042
            dateonly   => 1
2042
        }
2043
        }
Lines 2050-2075 subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { Link Here
2050
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2051
    AddIssue( $patron, $item_1->{barcode}, $five_days_ago );    # Add an overdue
2051
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2052
    AddIssue( $patron, $item_2->{barcode}, $ten_days_ago )
2052
      ;    # Add another overdue
2053
      ;    # Add another overdue
2053
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, dt_from_string );
2054
    AddReturn( $item_1->{barcode}, $library->{branchcode}, undef, $now );
2054
    $debarments = Koha::Patron::Debarments::GetDebarments(
2055
    $debarments = Koha::Patron::Debarments::GetDebarments(
2055
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2056
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2056
    is( scalar(@$debarments), 1 );
2057
    is( scalar(@$debarments), 1 );
2057
    $expected_expiration = output_pref(
2058
    $expected_expiration = output_pref(
2058
        {
2059
        {
2059
            dt         => dt_from_string->add( days => ( 5 - 1 ) * 2 ),
2060
            dt         => $now->clone->add( days => ( 5 - 1 ) * 2 ),
2060
            dateformat => 'sql',
2061
            dateformat => 'sql',
2061
            dateonly   => 1
2062
            dateonly   => 1
2062
        }
2063
        }
2063
    );
2064
    );
2064
    is( $debarments->[0]->{expiration}, $expected_expiration );
2065
    is( $debarments->[0]->{expiration}, $expected_expiration );
2065
2066
2066
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, dt_from_string );
2067
    AddReturn( $item_2->{barcode}, $library->{branchcode}, undef, $now );
2067
    $debarments = Koha::Patron::Debarments::GetDebarments(
2068
    $debarments = Koha::Patron::Debarments::GetDebarments(
2068
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2069
        { borrowernumber => $patron->{borrowernumber}, type => 'SUSPENSION' } );
2069
    is( scalar(@$debarments), 1 );
2070
    is( scalar(@$debarments), 1 );
2070
    $expected_expiration = output_pref(
2071
    $expected_expiration = output_pref(
2071
        {
2072
        {
2072
            dt => dt_from_string->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ),
2073
            dt => $now->clone->add( days => ( 5 - 1 ) * 2 + ( 10 - 1 ) * 2 ),
2073
            dateformat => 'sql',
2074
            dateformat => 'sql',
2074
            dateonly   => 1
2075
            dateonly   => 1
2075
        }
2076
        }
Lines 2112-2121 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2112
        }
2113
        }
2113
    );
2114
    );
2114
2115
2115
    my $five_days_ago = dt_from_string->subtract( days => 5 );
2116
    my $now = dt_from_string;
2117
    my $five_days_ago = $now->clone->subtract( days => 5 );
2116
    # We want to charge 2 days every day, without grace
2118
    # We want to charge 2 days every day, without grace
2117
    # With 5 days of overdue: 5 * Z
2119
    # With 5 days of overdue: 5 * Z
2118
    my $expected_expiration = dt_from_string->add( days => ( 5 * 2 ) / 1 );
2120
    my $expected_expiration = $now->clone->add( days => ( 5 * 2 ) / 1 );
2119
    test_debarment_on_checkout(
2121
    test_debarment_on_checkout(
2120
        {
2122
        {
2121
            item            => $item_1,
2123
            item            => $item_1,
Lines 2138-2144 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2138
        }
2140
        }
2139
    );
2141
    );
2140
2142
2141
    $expected_expiration = dt_from_string->add( days => floor( 5 * 2 ) / 2 );
2143
    $expected_expiration = $now->clone->add( days => floor( 5 * 2 ) / 2 );
2142
    test_debarment_on_checkout(
2144
    test_debarment_on_checkout(
2143
        {
2145
        {
2144
            item            => $item_1,
2146
            item            => $item_1,
Lines 2162-2168 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2162
            }
2164
            }
2163
        }
2165
        }
2164
    );
2166
    );
2165
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
2167
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 1 ) / 3 ) * 2 ) );
2166
    test_debarment_on_checkout(
2168
    test_debarment_on_checkout(
2167
        {
2169
        {
2168
            item            => $item_1,
2170
            item            => $item_1,
Lines 2192-2198 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2192
2194
2193
    # Adding a holiday 2 days ago
2195
    # Adding a holiday 2 days ago
2194
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
2196
    my $calendar = C4::Calendar->new(branchcode => $library->{branchcode});
2195
    my $two_days_ago = dt_from_string->subtract( days => 2 );
2197
    my $two_days_ago = $now->clone->subtract( days => 2 );
2196
    $calendar->insert_single_holiday(
2198
    $calendar->insert_single_holiday(
2197
        day             => $two_days_ago->day,
2199
        day             => $two_days_ago->day,
2198
        month           => $two_days_ago->month,
2200
        month           => $two_days_ago->month,
Lines 2201-2207 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2201
        description     => 'holidayDesc 2 days ago'
2203
        description     => 'holidayDesc 2 days ago'
2202
    );
2204
    );
2203
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
2205
    # With 5 days of overdue, only 4 (x finedays=2) days must charged (one was an holiday)
2204
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
2206
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) );
2205
    test_debarment_on_checkout(
2207
    test_debarment_on_checkout(
2206
        {
2208
        {
2207
            item            => $item_1,
2209
            item            => $item_1,
Lines 2213-2219 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2213
    );
2215
    );
2214
2216
2215
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
2217
    # Adding a holiday 2 days ahead, with finesCalendar=noFinesWhenClosed it should be skipped
2216
    my $two_days_ahead = dt_from_string->add( days => 2 );
2218
    my $two_days_ahead = $now->clone->add( days => 2 );
2217
    $calendar->insert_single_holiday(
2219
    $calendar->insert_single_holiday(
2218
        day             => $two_days_ahead->day,
2220
        day             => $two_days_ahead->day,
2219
        month           => $two_days_ahead->month,
2221
        month           => $two_days_ahead->month,
Lines 2223-2229 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2223
    );
2225
    );
2224
2226
2225
    # Same as above, but we should skip D+2
2227
    # Same as above, but we should skip D+2
2226
    $expected_expiration = dt_from_string->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
2228
    $expected_expiration = $now->clone->add( days => floor( ( ( 5 - 0 - 1 ) / 1 ) * 2 ) + 1 );
2227
    test_debarment_on_checkout(
2229
    test_debarment_on_checkout(
2228
        {
2230
        {
2229
            item            => $item_1,
2231
            item            => $item_1,
Lines 2259-2266 subtest 'AddReturn + suspension_chargeperiod' => sub { Link Here
2259
            item            => $item_1,
2261
            item            => $item_1,
2260
            library         => $library,
2262
            library         => $library,
2261
            patron          => $patron,
2263
            patron          => $patron,
2262
            return_date     => dt_from_string->add(days => 5),
2264
            return_date     => $now->clone->add(days => 5),
2263
            expiration_date => dt_from_string->add(days => 5 + (5 * 2 - 1) ),
2265
            expiration_date => $now->clone->add(days => 5 + (5 * 2 - 1) ),
2264
        }
2266
        }
2265
    );
2267
    );
2266
};
2268
};
Lines 2346-2354 subtest 'AddReturn | is_overdue' => sub { Link Here
2346
    );
2348
    );
2347
2349
2348
    my $now   = dt_from_string;
2350
    my $now   = dt_from_string;
2349
    my $one_day_ago   = dt_from_string->subtract( days => 1 );
2351
    my $one_day_ago   = $now->clone->subtract( days => 1 );
2350
    my $five_days_ago = dt_from_string->subtract( days => 5 );
2352
    my $five_days_ago = $now->clone->subtract( days => 5 );
2351
    my $ten_days_ago  = dt_from_string->subtract( days => 10 );
2353
    my $ten_days_ago  = $now->clone->subtract( days => 10 );
2352
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2354
    $patron = Koha::Patrons->find( $patron->{borrowernumber} );
2353
2355
2354
    # No return date specified, today will be used => 10 days overdue charged
2356
    # No return date specified, today will be used => 10 days overdue charged
Lines 3036-3043 subtest 'CanBookBeIssued | is_overdue' => sub { Link Here
3036
        }
3038
        }
3037
    );
3039
    );
3038
3040
3039
    my $five_days_go = output_pref({ dt => dt_from_string->add( days => 5 ), dateonly => 1});
3041
    my $now   = dt_from_string;
3040
    my $ten_days_go  = output_pref({ dt => dt_from_string->add( days => 10), dateonly => 1 });
3042
    my $five_days_go = output_pref({ dt => $now->clone->add( days => 5 ), dateonly => 1});
3043
    my $ten_days_go  = output_pref({ dt => $now->clone->add( days => 10), dateonly => 1 });
3041
    my $library = $builder->build( { source => 'Branch' } );
3044
    my $library = $builder->build( { source => 'Branch' } );
3042
    my $patron  = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } );
3045
    my $patron  = $builder->build_object( { class => 'Koha::Patrons', value => { categorycode => $patron_category->{categorycode} } } );
3043
3046
Lines 3407-3413 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3407
    $context = Test::MockModule->new('C4::Context');
3410
    $context = Test::MockModule->new('C4::Context');
3408
    $context->mock( userenv => { branch => undef, interface => 'CRON'} ); #Test statistical logging of renewal via cron (atuo_renew)
3411
    $context->mock( userenv => { branch => undef, interface => 'CRON'} ); #Test statistical logging of renewal via cron (atuo_renew)
3409
3412
3410
    $date = output_pref( { dt => dt_from_string(), dateonly => 1, dateformat => 'iso' } );
3413
    my $now = dt_from_string;
3414
    $date = output_pref( { dt => $now, dateonly => 1, dateformat => 'iso' } );
3411
    $old_log_size = Koha::ActionLogs->count( \%params_renewal );
3415
    $old_log_size = Koha::ActionLogs->count( \%params_renewal );
3412
    my $sth = $dbh->prepare("SELECT COUNT(*) FROM statistics WHERE itemnumber = ? AND branch = ?");
3416
    my $sth = $dbh->prepare("SELECT COUNT(*) FROM statistics WHERE itemnumber = ? AND branch = ?");
3413
    $sth->execute($item->id, $library->id);
3417
    $sth->execute($item->id, $library->id);
Lines 3420-3426 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3420
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
3424
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
3421
3425
3422
    AddReturn( $item->id, $library->id, undef, $date );
3426
    AddReturn( $item->id, $library->id, undef, $date );
3423
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3427
    AddIssue( $patron->unblessed, $item->barcode, $now );
3424
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3428
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3425
    my $lines_skipped = Koha::Account::Lines->search({
3429
    my $lines_skipped = Koha::Account::Lines->search({
3426
        borrowernumber => $patron->id,
3430
        borrowernumber => $patron->id,
Lines 3496-3504 subtest 'Incremented fee tests' => sub { Link Here
3496
    is( $item->effective_itemtype, $itemtype->id,
3500
    is( $item->effective_itemtype, $itemtype->id,
3497
        "Itemtype set correctly for item" );
3501
        "Itemtype set correctly for item" );
3498
3502
3499
    my $dt_from     = dt_from_string();
3503
    my $now         = dt_from_string;
3500
    my $dt_to       = dt_from_string()->add( days => 7 );
3504
    my $dt_from     = $now->clone;
3501
    my $dt_to_renew = dt_from_string()->add( days => 13 );
3505
    my $dt_to       = $now->clone->add( days => 7 );
3506
    my $dt_to_renew = $now->clone->add( days => 13 );
3502
3507
3503
    # Daily Tests
3508
    # Daily Tests
3504
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
3509
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
Lines 3595-3602 subtest 'Incremented fee tests' => sub { Link Here
3595
    is( $itemtype->rentalcharge_hourly,
3600
    is( $itemtype->rentalcharge_hourly,
3596
        '0.25', 'Hourly rental charge stored and retreived correctly' );
3601
        '0.25', 'Hourly rental charge stored and retreived correctly' );
3597
3602
3598
    $dt_to       = dt_from_string()->add( hours => 168 );
3603
    $dt_to       = $now->clone->add( hours => 168 );
3599
    $dt_to_renew = dt_from_string()->add( hours => 312 );
3604
    $dt_to_renew = $now->clone->add( hours => 312 );
3600
3605
3601
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
3606
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
3602
    $issue =
3607
    $issue =
Lines 3687-3693 subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub { Link Here
3687
3692
3688
    my ( $issuingimpossible, $needsconfirmation );
3693
    my ( $issuingimpossible, $needsconfirmation );
3689
    my $dt_from = dt_from_string();
3694
    my $dt_from = dt_from_string();
3690
    my $dt_due = dt_from_string()->add( days => 3 );
3695
    my $dt_due = $dt_from->clone->add( days => 3 );
3691
3696
3692
    $itemtype->rentalcharge(1)->store;
3697
    $itemtype->rentalcharge(1)->store;
3693
    ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef );
3698
    ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->barcode, $dt_due, undef, undef, undef );
3694
- 

Return to bug 24881