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

(-)a/t/db_dependent/Circulation.t (-35 / +98 lines)
Lines 3074-3087 subtest 'ProcessOfflinePayment() tests' => sub { Link Here
3074
};
3074
};
3075
3075
3076
subtest 'Incremented fee tests' => sub {
3076
subtest 'Incremented fee tests' => sub {
3077
    plan tests => 11;
3077
    plan tests => 16;
3078
3078
3079
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
3079
    my $dt = dt_from_string();
3080
    Time::Fake->offset( $dt->epoch );
3080
3081
3081
    my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store;
3082
    t::lib::Mocks::mock_preference( 'item-level_itypes', 1 );
3083
3084
    my $library =
3085
      $builder->build_object( { class => 'Koha::Libraries' } )->store;
3082
3086
3083
    my $module = new Test::MockModule('C4::Context');
3087
    my $module = new Test::MockModule('C4::Context');
3084
    $module->mock('userenv', sub { { branch => $library->id } });
3088
    $module->mock( 'userenv', sub { { branch => $library->id } } );
3085
3089
3086
    my $patron = $builder->build_object(
3090
    my $patron = $builder->build_object(
3087
        {
3091
        {
Lines 3093-3101 subtest 'Incremented fee tests' => sub { Link Here
3093
    my $itemtype = $builder->build_object(
3097
    my $itemtype = $builder->build_object(
3094
        {
3098
        {
3095
            class => 'Koha::ItemTypes',
3099
            class => 'Koha::ItemTypes',
3096
            value  => {
3100
            value => {
3097
                notforloan          => undef,
3101
                notforloan         => undef,
3098
                rentalcharge        => 0,
3102
                rentalcharge       => 0,
3099
                rentalcharge_daily => 1.000000
3103
                rentalcharge_daily => 1.000000
3100
            }
3104
            }
3101
        }
3105
        }
Lines 3108-3139 subtest 'Incremented fee tests' => sub { Link Here
3108
        }
3112
        }
3109
    );
3113
    );
3110
3114
3111
    is( $itemtype->rentalcharge_daily, '1.000000', 'Daily rental charge stored and retreived correctly' );
3115
    is( $itemtype->rentalcharge_daily,
3112
    is( $item->effective_itemtype, $itemtype->id, "Itemtype set correctly for item");
3116
        '1.000000', 'Daily rental charge stored and retreived correctly' );
3117
    is( $item->effective_itemtype, $itemtype->id,
3118
        "Itemtype set correctly for item" );
3113
3119
3114
    my $dt_from = dt_from_string();
3120
    my $dt_from     = dt_from_string();
3115
    my $dt_to = dt_from_string()->add( days => 7 );
3121
    my $dt_to       = dt_from_string()->add( days => 7 );
3116
    my $dt_to_renew = dt_from_string()->add( days => 13 );
3122
    my $dt_to_renew = dt_from_string()->add( days => 13 );
3117
3123
3118
    t::lib::Mocks::mock_preference('finesCalendar', 'ignoreCalendar');
3124
    # Daily Tests
3119
    my $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3125
    t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
3120
    my $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3126
    my $issue =
3121
    is( $accountline->amount, '7.000000', "Daily rental charge calculated correctly with finesCalendar = ignoreCalendar" );
3127
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3128
    my $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3129
    is( $accountline->amount, '7.000000',
3130
"Daily rental charge calculated correctly with finesCalendar = ignoreCalendar"
3131
    );
3122
    $accountline->delete();
3132
    $accountline->delete();
3123
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3133
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3124
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3134
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3125
    is( $accountline->amount, '6.000000', "Daily rental charge calculated correctly with finesCalendar = ignoreCalendar, for renewal" );
3135
    is( $accountline->amount, '6.000000',
3136
"Daily rental charge calculated correctly with finesCalendar = ignoreCalendar, for renewal"
3137
    );
3126
    $accountline->delete();
3138
    $accountline->delete();
3127
    $issue->delete();
3139
    $issue->delete();
3128
3140
3129
    t::lib::Mocks::mock_preference('finesCalendar', 'noFinesWhenClosed');
3141
    t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
3130
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3142
    $issue =
3131
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3143
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3132
    is( $accountline->amount, '7.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed" );
3144
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3145
    is( $accountline->amount, '7.000000',
3146
"Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed"
3147
    );
3133
    $accountline->delete();
3148
    $accountline->delete();
3134
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3149
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3135
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3150
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3136
    is( $accountline->amount, '6.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed, for renewal" );
3151
    is( $accountline->amount, '6.000000',
3152
"Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed, for renewal"
3153
    );
3137
    $accountline->delete();
3154
    $accountline->delete();
3138
    $issue->delete();
3155
    $issue->delete();
3139
3156
Lines 3143-3169 subtest 'Incremented fee tests' => sub { Link Here
3143
        title       => 'Test holiday',
3160
        title       => 'Test holiday',
3144
        description => 'Test holiday'
3161
        description => 'Test holiday'
3145
    );
3162
    );
3146
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3163
    $issue =
3147
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3164
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3148
    is( $accountline->amount, '6.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays" );
3165
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3166
    is( $accountline->amount, '6.000000',
3167
"Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays"
3168
    );
3149
    $accountline->delete();
3169
    $accountline->delete();
3150
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3170
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3151
    $accountline = Koha::Account::Lines->find({ itemnumber => $item->id });
3171
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3152
    is( $accountline->amount, '5.000000', "Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal" );
3172
    is( $accountline->amount, '5.000000',
3173
"Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays, for renewal"
3174
    );
3153
    $accountline->delete();
3175
    $accountline->delete();
3154
    $issue->delete();
3176
    $issue->delete();
3155
3177
3156
    $itemtype->rentalcharge('2.000000')->store;
3178
    $itemtype->rentalcharge('2.000000')->store;
3157
    is( $itemtype->rentalcharge, '2.000000', 'Rental charge updated and retreived correctly' );
3179
    is( $itemtype->rentalcharge, '2.000000',
3158
    $issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from);
3180
        'Rental charge updated and retreived correctly' );
3159
    my $accountlines = Koha::Account::Lines->search({ itemnumber => $item->id });
3181
    $issue =
3160
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly");
3182
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3183
    my $accountlines =
3184
      Koha::Account::Lines->search( { itemnumber => $item->id } );
3185
    is( $accountlines->count, '2',
3186
        "Fixed charge and accrued charge recorded distinctly" );
3161
    $accountlines->delete();
3187
    $accountlines->delete();
3162
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3188
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3163
    $accountlines = Koha::Account::Lines->search({ itemnumber => $item->id });
3189
    $accountlines = Koha::Account::Lines->search( { itemnumber => $item->id } );
3164
    is( $accountlines->count, '2', "Fixed charge and accrued charge recorded distinctly, for renewal");
3190
    is( $accountlines->count, '2',
3191
        "Fixed charge and accrued charge recorded distinctly, for renewal" );
3165
    $accountlines->delete();
3192
    $accountlines->delete();
3166
    $issue->delete();
3193
    $issue->delete();
3194
    $itemtype->rentalcharge('00.000000')->store;
3195
    is( $itemtype->rentalcharge, '00.000000',
3196
        'Rental charge reset and retreived correctly' );
3197
3198
    # Hourly
3199
    my $issuingrule = Koha::IssuingRules->get_effective_issuing_rule(
3200
        {
3201
            categorycode => $patron->categorycode,
3202
            itemtype     => $itemtype->id,
3203
            branchcode   => $library->id
3204
        }
3205
    );
3206
    $issuingrule->lengthunit('hours')->store();
3207
    is( $issuingrule->lengthunit, 'hours',
3208
        'Issuingrule updated and retrieved correctly' );
3209
3210
    $itemtype->rentalcharge_hourly('2.500000')->store();
3211
    is( $itemtype->rentalcharge_hourly,
3212
        '2.500000', 'Hourly rental charge stored and retreived correctly' );
3213
3214
    $dt_to       = dt_from_string()->add( hours => 4 );
3215
    $dt_to_renew = dt_from_string()->add( hours => 6 );
3216
3217
    $issue =
3218
      AddIssue( $patron->unblessed, $item->barcode, $dt_to, undef, $dt_from );
3219
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3220
    is( $accountline->amount, '10.000000',
3221
        "Hourly rental charge calculated correctly" );
3222
    $accountline->delete();
3223
    AddRenewal( $patron->id, $item->id, $library->id, $dt_to_renew, $dt_to );
3224
    $accountline = Koha::Account::Lines->find( { itemnumber => $item->id } );
3225
    is( $accountline->amount, '5.000000',
3226
        "Hourly rental charge calculated correctly, for renewal" );
3227
    $accountline->delete();
3228
    $issue->delete();
3229
    $issuingrule->lengthunit('days')->store();
3230
    Time::Fake->reset;
3167
};
3231
};
3168
3232
3169
subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub {
3233
subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub {
3170
- 

Return to bug 23382