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

(-)a/t/db_dependent/Circulation.t (-1 / +10 lines)
Lines 3093-3099 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
3093
3093
3094
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3094
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
3095
3095
3096
    plan tests => 10;
3096
    plan tests => 11;
3097
3097
3098
3098
3099
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
3099
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3176-3181 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3176
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3176
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3177
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3177
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3178
3178
3179
    AddReturn( $item->id, $library->id, undef, $date );
3180
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3181
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3182
    my $lines_skipped = Koha::Account::Lines->search({
3183
        borrowernumber => $patron->id,
3184
        itemnumber     => $item->id
3185
    });
3186
    is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
3187
3179
};
3188
};
3180
3189
3181
subtest 'ProcessOfflinePayment() tests' => sub {
3190
subtest 'ProcessOfflinePayment() tests' => sub {
(-)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 564-569 subtest 'pay() tests' => sub { Link Here
564
566
565
    $schema->storage->txn_begin;
567
    $schema->storage->txn_begin;
566
568
569
    # Disable renewing upon fine payment
570
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
571
567
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
572
    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
568
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
573
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
569
    my $account = $patron->account;
574
    my $account = $patron->account;
Lines 581-586 subtest 'pay() tests' => sub { Link Here
581
586
582
    is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
587
    is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' );
583
588
589
584
    $schema->storage->txn_rollback;
590
    $schema->storage->txn_rollback;
585
};
591
};
586
592
Lines 728-733 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
728
    $schema->storage->txn_rollback;
734
    $schema->storage->txn_rollback;
729
};
735
};
730
736
737
subtest 'pay() renews items when appropriate' => sub {
738
739
    plan tests => 1;
740
741
    $schema->storage->txn_begin;
742
743
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
744
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
745
    my $account = $patron->account;
746
747
    my $context = Test::MockModule->new('C4::Context');
748
    $context->mock( 'userenv', { branch => $library->id } );
749
750
    my $biblio = $builder->build_sample_biblio();
751
    my $item =
752
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
753
754
    my $now = dt_from_string();
755
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
756
    my $five_weeks = DateTime::Duration->new(weeks => 5);
757
    my $seven_weeks_ago = $now - $seven_weeks;
758
    my $five_weeks_ago = $now - $five_weeks;
759
760
    my $checkout = Koha::Checkout->new(
761
        {
762
            borrowernumber => $patron->id,
763
            itemnumber     => $item->id,
764
            date_due       => $five_weeks_ago,
765
            branchcode     => $patron->branchcode,
766
            issuedate      => $seven_weeks_ago
767
        }
768
    )->store();
769
770
    my $accountline = Koha::Account::Line->new(
771
        {
772
            issue_id       => $checkout->id,
773
            borrowernumber => $patron->id,
774
            itemnumber     => $item->id,
775
            date           => \'NOW()',
776
            accounttype    => 'OVERDUE',
777
            status         => 'UNRETURNED',
778
            interface      => 'cli',
779
            amount => '1',
780
            amountoutstanding => '1',
781
        }
782
    )->store();
783
784
    # Enable renewing upon fine payment
785
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
786
    my $called = 0;
787
    my $module = new Test::MockModule('C4::Circulation');
788
    $module->mock('AddRenewal', sub { $called = 1; });
789
    $account->pay(
790
        {
791
            amount     => '1',
792
            library_id => $library->id,
793
        }
794
    );
795
796
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
797
798
    $schema->storage->txn_rollback;
799
};
800
731
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
801
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
732
802
733
    plan tests => 4;
803
    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