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

(-)a/t/db_dependent/Circulation.t (-1 / +10 lines)
Lines 2996-3002 $cache->clear_from_cache('single_holidays'); Link Here
2996
2996
2997
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2997
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2998
2998
2999
    plan tests => 13;
2999
    plan tests => 14;
3000
3000
3001
    $schema->storage->txn_begin;
3001
    $schema->storage->txn_begin;
3002
3002
Lines 3085-3090 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3085
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
3085
    is( $line->branchcode,  $library->id, 'AddRenewal correctly sets branchcode' );
3086
    is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' );
3086
    is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' );
3087
3087
3088
    AddReturn( $item->id, $library->id, undef, $date );
3089
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3090
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3091
    my $lines_skipped = Koha::Account::Lines->search({
3092
        borrowernumber => $patron->id,
3093
        itemnumber     => $item->id
3094
    });
3095
    is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
3096
3088
    $schema->storage->txn_rollback;
3097
    $schema->storage->txn_rollback;
3089
};
3098
};
3090
3099
(-)a/t/db_dependent/Koha/Account.t (-1 / +71 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 567-572 subtest 'pay() tests' => sub { Link Here
567
569
568
    $schema->storage->txn_begin;
570
    $schema->storage->txn_begin;
569
571
572
    # Disable renewing upon fine payment
573
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
574
570
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
575
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
571
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
576
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
572
    my $account = $patron->account;
577
    my $account = $patron->account;
Lines 584-589 subtest 'pay() tests' => sub { Link Here
584
589
585
    is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
590
    is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
586
591
592
587
    $schema->storage->txn_rollback;
593
    $schema->storage->txn_rollback;
588
};
594
};
589
595
Lines 731-736 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
731
    $schema->storage->txn_rollback;
737
    $schema->storage->txn_rollback;
732
};
738
};
733
739
740
subtest 'pay() renews items when appropriate' => sub {
741
742
    plan tests => 1;
743
744
    $schema->storage->txn_begin;
745
746
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
747
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
748
    my $account = $patron->account;
749
750
    my $context = Test::MockModule->new('C4::Context');
751
    $context->mock( 'userenv', { branch => $library->id } );
752
753
    my $biblio = $builder->build_sample_biblio();
754
    my $item =
755
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
756
757
    my $now = dt_from_string();
758
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
759
    my $five_weeks = DateTime::Duration->new(weeks => 5);
760
    my $seven_weeks_ago = $now - $seven_weeks;
761
    my $five_weeks_ago = $now - $five_weeks;
762
763
    my $checkout = Koha::Checkout->new(
764
        {
765
            borrowernumber => $patron->id,
766
            itemnumber     => $item->id,
767
            date_due       => $five_weeks_ago,
768
            branchcode     => $patron->branchcode,
769
            issuedate      => $seven_weeks_ago
770
        }
771
    )->store();
772
773
    my $accountline = Koha::Account::Line->new(
774
        {
775
            issue_id       => $checkout->id,
776
            borrowernumber => $patron->id,
777
            itemnumber     => $item->id,
778
            date           => \'NOW()',
779
            accounttype    => 'OVERDUE',
780
            status         => 'UNRETURNED',
781
            interface      => 'cli',
782
            amount => '1',
783
            amountoutstanding => '1',
784
        }
785
    )->store();
786
787
    # Enable renewing upon fine payment
788
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
789
    my $called = 0;
790
    my $module = new Test::MockModule('C4::Circulation');
791
    $module->mock('AddRenewal', sub { $called = 1; });
792
    $account->pay(
793
        {
794
            amount     => '1',
795
            library_id => $library->id,
796
        }
797
    );
798
799
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
800
801
    $schema->storage->txn_rollback;
802
};
803
734
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
804
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
735
805
736
    plan tests => 4;
806
    plan tests => 4;
(-)a/t/db_dependent/Koha/Account/Lines.t (-2 / +51 lines)
Lines 21-32 use Modern::Perl; Link Here
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 8;
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 180-186 subtest 'is_credit() and is_debit() tests' => sub { Link Here
180
184
181
subtest 'apply() tests' => sub {
185
subtest 'apply() tests' => sub {
182
186
183
    plan tests => 24;
187
    plan tests => 25;
184
188
185
    $schema->storage->txn_begin;
189
    $schema->storage->txn_begin;
186
190
Lines 291-296 subtest 'apply() tests' => sub { Link Here
291
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
295
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
292
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
296
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
293
297
298
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
299
    my $biblio = $builder->build_sample_biblio();
300
    my $item =
301
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
302
    my $now = dt_from_string();
303
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
304
    my $five_weeks = DateTime::Duration->new(weeks => 5);
305
    my $seven_weeks_ago = $now - $seven_weeks;
306
    my $five_weeks_ago = $now - $five_weeks;
307
308
    my $checkout = Koha::Checkout->new(
309
        {
310
            borrowernumber => $patron->id,
311
            itemnumber     => $item->id,
312
            date_due       => $five_weeks_ago,
313
            branchcode     => $library->id,
314
            issuedate      => $seven_weeks_ago
315
        }
316
    )->store();
317
318
    my $accountline = Koha::Account::Line->new(
319
        {
320
            issue_id       => $checkout->id,
321
            borrowernumber => $patron->id,
322
            itemnumber     => $item->id,
323
            branchcode     => $library->id,
324
            date           => \'NOW()',
325
            accounttype    => 'OVERDUE',
326
            status         => 'UNRETURNED',
327
            interface      => 'cli',
328
            amount => '1',
329
            amountoutstanding => '1',
330
        }
331
    )->store();
332
333
    # Enable renewing upon fine payment
334
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
335
    my $called = 0;
336
    my $module = new Test::MockModule('C4::Circulation');
337
    $module->mock('AddRenewal', sub { $called = 1; });
338
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
339
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id });
340
    $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
341
342
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
343
294
    $schema->storage->txn_rollback;
344
    $schema->storage->txn_rollback;
295
};
345
};
296
346
297
- 

Return to bug 23051