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

(-)a/t/db_dependent/Circulation.t (-1 / +10 lines)
Lines 3326-3332 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
3326
3326
3327
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3327
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3328
3328
3329
    plan tests => 11;
3329
    plan tests => 12;
3330
3330
3331
3331
3332
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
3332
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3419-3424 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3419
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3419
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3420
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
3420
    is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
3421
3421
3422
    AddReturn( $item->id, $library->id, undef, $date );
3423
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3424
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3425
    my $lines_skipped = Koha::Account::Lines->search({
3426
        borrowernumber => $patron->id,
3427
        itemnumber     => $item->id
3428
    });
3429
    is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
3430
3422
};
3431
};
3423
3432
3424
subtest 'ProcessOfflinePayment() tests' => sub {
3433
subtest 'ProcessOfflinePayment() tests' => sub {
(-)a/t/db_dependent/Koha/Account.t (-1 / +70 lines)
Lines 23-32 use Test::More tests => 11; Link Here
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Exception;
24
use Test::Exception;
25
25
26
use DateTime;
27
26
use Koha::Account;
28
use Koha::Account;
27
use Koha::Account::Lines;
29
use Koha::Account::Lines;
28
use Koha::Account::Offsets;
30
use Koha::Account::Offsets;
29
31
use Koha::DateUtils qw( dt_from_string );
30
32
31
use t::lib::Mocks;
33
use t::lib::Mocks;
32
use t::lib::TestBuilder;
34
use t::lib::TestBuilder;
Lines 673-678 subtest 'pay() tests' => sub { Link Here
673
675
674
    $schema->storage->txn_begin;
676
    $schema->storage->txn_begin;
675
677
678
    # Disable renewing upon fine payment
679
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
680
676
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
681
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
677
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
682
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
678
    my $account = $patron->account;
683
    my $account = $patron->account;
Lines 897-902 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
897
    $schema->storage->txn_rollback;
902
    $schema->storage->txn_rollback;
898
};
903
};
899
904
905
subtest 'pay() renews items when appropriate' => sub {
906
907
    plan tests => 1;
908
909
    $schema->storage->txn_begin;
910
911
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
912
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
913
    my $account = $patron->account;
914
915
    my $context = Test::MockModule->new('C4::Context');
916
    $context->mock( 'userenv', { branch => $library->id } );
917
918
    my $biblio = $builder->build_sample_biblio();
919
    my $item =
920
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
921
922
    my $now = dt_from_string();
923
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
924
    my $five_weeks = DateTime::Duration->new(weeks => 5);
925
    my $seven_weeks_ago = $now - $seven_weeks;
926
    my $five_weeks_ago = $now - $five_weeks;
927
928
    my $checkout = Koha::Checkout->new(
929
        {
930
            borrowernumber => $patron->id,
931
            itemnumber     => $item->id,
932
            date_due       => $five_weeks_ago,
933
            branchcode     => $patron->branchcode,
934
            issuedate      => $seven_weeks_ago
935
        }
936
    )->store();
937
938
    my $accountline = Koha::Account::Line->new(
939
        {
940
            issue_id       => $checkout->id,
941
            borrowernumber => $patron->id,
942
            itemnumber     => $item->id,
943
            date           => \'NOW()',
944
            accounttype    => 'OVERDUE',
945
            status         => 'UNRETURNED',
946
            interface      => 'cli',
947
            amount => '1',
948
            amountoutstanding => '1',
949
        }
950
    )->store();
951
952
    # Enable renewing upon fine payment
953
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
954
    my $called = 0;
955
    my $module = new Test::MockModule('C4::Circulation');
956
    $module->mock('AddRenewal', sub { $called = 1; });
957
    $account->pay(
958
        {
959
            amount     => '1',
960
            library_id => $library->id,
961
        }
962
    );
963
964
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
965
966
    $schema->storage->txn_rollback;
967
};
968
900
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
969
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
901
970
902
    plan tests => 4;
971
    plan tests => 4;
(-)a/t/db_dependent/Koha/Account/Line.t (-2 / +51 lines)
Lines 21-32 use Modern::Perl; Link Here
21
21
22
use Test::More tests => 11;
22
use Test::More tests => 11;
23
use Test::Exception;
23
use Test::Exception;
24
use Test::MockModule;
25
26
use DateTime;
24
27
25
use C4::Circulation qw/AddIssue AddReturn/;
28
use C4::Circulation qw/AddIssue AddReturn/;
26
use Koha::Account;
29
use Koha::Account;
27
use Koha::Account::Lines;
30
use Koha::Account::Lines;
28
use Koha::Account::Offsets;
31
use Koha::Account::Offsets;
29
use Koha::Items;
32
use Koha::Items;
33
use Koha::DateUtils qw( dt_from_string );
30
34
31
use t::lib::Mocks;
35
use t::lib::Mocks;
32
use t::lib::TestBuilder;
36
use t::lib::TestBuilder;
Lines 132-138 subtest 'is_credit() and is_debit() tests' => sub { Link Here
132
136
133
subtest 'apply() tests' => sub {
137
subtest 'apply() tests' => sub {
134
138
135
    plan tests => 24;
139
    plan tests => 25;
136
140
137
    $schema->storage->txn_begin;
141
    $schema->storage->txn_begin;
138
142
Lines 243-248 subtest 'apply() tests' => sub { Link Here
243
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
247
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
244
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
248
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
245
249
250
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
251
    my $biblio = $builder->build_sample_biblio();
252
    my $item =
253
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
254
    my $now = dt_from_string();
255
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
256
    my $five_weeks = DateTime::Duration->new(weeks => 5);
257
    my $seven_weeks_ago = $now - $seven_weeks;
258
    my $five_weeks_ago = $now - $five_weeks;
259
260
    my $checkout = Koha::Checkout->new(
261
        {
262
            borrowernumber => $patron->id,
263
            itemnumber     => $item->id,
264
            date_due       => $five_weeks_ago,
265
            branchcode     => $library->id,
266
            issuedate      => $seven_weeks_ago
267
        }
268
    )->store();
269
270
    my $accountline = Koha::Account::Line->new(
271
        {
272
            issue_id       => $checkout->id,
273
            borrowernumber => $patron->id,
274
            itemnumber     => $item->id,
275
            branchcode     => $library->id,
276
            date           => \'NOW()',
277
            accounttype    => 'OVERDUE',
278
            status         => 'UNRETURNED',
279
            interface      => 'cli',
280
            amount => '1',
281
            amountoutstanding => '1',
282
        }
283
    )->store();
284
285
    # Enable renewing upon fine payment
286
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
287
    my $called = 0;
288
    my $module = new Test::MockModule('C4::Circulation');
289
    $module->mock('AddRenewal', sub { $called = 1; });
290
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
291
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id });
292
    $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
293
294
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
295
246
    $schema->storage->txn_rollback;
296
    $schema->storage->txn_rollback;
247
};
297
};
248
298
249
- 

Return to bug 23051