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

(-)a/t/db_dependent/Circulation.t (-1 / +10 lines)
Lines 2966-2972 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
2966
2966
2967
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2967
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2968
2968
2969
    plan tests => 10;
2969
    plan tests => 11;
2970
2970
2971
2971
2972
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2972
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3049-3054 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3049
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3049
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3050
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3050
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3051
3051
3052
    AddReturn( $item->id, $library->id, undef, $date );
3053
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3054
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3055
    my $lines_skipped = Koha::Account::Lines->search({
3056
        borrowernumber => $patron->id,
3057
        itemnumber     => $item->id
3058
    });
3059
    is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
3060
3052
};
3061
};
3053
3062
3054
subtest 'ProcessOfflinePayment() tests' => sub {
3063
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 585-590 subtest 'pay() tests' => sub { Link Here
585
587
586
    $schema->storage->txn_begin;
588
    $schema->storage->txn_begin;
587
589
590
    # Disable renewing upon fine payment
591
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
592
588
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
593
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
589
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
594
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
590
    my $account = $patron->account;
595
    my $account = $patron->account;
Lines 766-771 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
766
    $schema->storage->txn_rollback;
771
    $schema->storage->txn_rollback;
767
};
772
};
768
773
774
subtest 'pay() renews items when appropriate' => sub {
775
776
    plan tests => 1;
777
778
    $schema->storage->txn_begin;
779
780
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
781
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
782
    my $account = $patron->account;
783
784
    my $context = Test::MockModule->new('C4::Context');
785
    $context->mock( 'userenv', { branch => $library->id } );
786
787
    my $biblio = $builder->build_sample_biblio();
788
    my $item =
789
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
790
791
    my $now = dt_from_string();
792
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
793
    my $five_weeks = DateTime::Duration->new(weeks => 5);
794
    my $seven_weeks_ago = $now - $seven_weeks;
795
    my $five_weeks_ago = $now - $five_weeks;
796
797
    my $checkout = Koha::Checkout->new(
798
        {
799
            borrowernumber => $patron->id,
800
            itemnumber     => $item->id,
801
            date_due       => $five_weeks_ago,
802
            branchcode     => $patron->branchcode,
803
            issuedate      => $seven_weeks_ago
804
        }
805
    )->store();
806
807
    my $accountline = Koha::Account::Line->new(
808
        {
809
            issue_id       => $checkout->id,
810
            borrowernumber => $patron->id,
811
            itemnumber     => $item->id,
812
            date           => \'NOW()',
813
            accounttype    => 'OVERDUE',
814
            status         => 'UNRETURNED',
815
            interface      => 'cli',
816
            amount => '1',
817
            amountoutstanding => '1',
818
        }
819
    )->store();
820
821
    # Enable renewing upon fine payment
822
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
823
    my $called = 0;
824
    my $module = new Test::MockModule('C4::Circulation');
825
    $module->mock('AddRenewal', sub { $called = 1; });
826
    $account->pay(
827
        {
828
            amount     => '1',
829
            library_id => $library->id,
830
        }
831
    );
832
833
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
834
835
    $schema->storage->txn_rollback;
836
};
837
769
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
838
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
770
839
771
    plan tests => 4;
840
    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 => 9;
22
use Test::More tests => 9;
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 209-215 subtest 'is_credit() and is_debit() tests' => sub { Link Here
209
213
210
subtest 'apply() tests' => sub {
214
subtest 'apply() tests' => sub {
211
215
212
    plan tests => 24;
216
    plan tests => 25;
213
217
214
    $schema->storage->txn_begin;
218
    $schema->storage->txn_begin;
215
219
Lines 320-325 subtest 'apply() tests' => sub { Link Here
320
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
324
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
321
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
325
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
322
326
327
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
328
    my $biblio = $builder->build_sample_biblio();
329
    my $item =
330
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
331
    my $now = dt_from_string();
332
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
333
    my $five_weeks = DateTime::Duration->new(weeks => 5);
334
    my $seven_weeks_ago = $now - $seven_weeks;
335
    my $five_weeks_ago = $now - $five_weeks;
336
337
    my $checkout = Koha::Checkout->new(
338
        {
339
            borrowernumber => $patron->id,
340
            itemnumber     => $item->id,
341
            date_due       => $five_weeks_ago,
342
            branchcode     => $library->id,
343
            issuedate      => $seven_weeks_ago
344
        }
345
    )->store();
346
347
    my $accountline = Koha::Account::Line->new(
348
        {
349
            issue_id       => $checkout->id,
350
            borrowernumber => $patron->id,
351
            itemnumber     => $item->id,
352
            branchcode     => $library->id,
353
            date           => \'NOW()',
354
            accounttype    => 'OVERDUE',
355
            status         => 'UNRETURNED',
356
            interface      => 'cli',
357
            amount => '1',
358
            amountoutstanding => '1',
359
        }
360
    )->store();
361
362
    # Enable renewing upon fine payment
363
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
364
    my $called = 0;
365
    my $module = new Test::MockModule('C4::Circulation');
366
    $module->mock('AddRenewal', sub { $called = 1; });
367
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
368
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id });
369
    $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
370
371
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
372
323
    $schema->storage->txn_rollback;
373
    $schema->storage->txn_rollback;
324
};
374
};
325
375
326
- 

Return to bug 23051