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

(-)a/t/db_dependent/Circulation.t (-1 / +10 lines)
Lines 2988-2994 subtest 'AddReturn should clear items.onloan for unissued items' => sub { Link Here
2988
2988
2989
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2989
subtest 'AddRenewal and AddIssuingCharge tests' => sub {
2990
2990
2991
    plan tests => 10;
2991
    plan tests => 11;
2992
2992
2993
2993
2994
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
2994
    t::lib::Mocks::mock_preference('item-level_itypes', 1);
Lines 3071-3076 subtest 'AddRenewal and AddIssuingCharge tests' => sub { Link Here
3071
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3071
    $new_log_size = Koha::ActionLogs->count( \%params_renewal );
3072
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3072
    is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
3073
3073
3074
    AddReturn( $item->id, $library->id, undef, $date );
3075
    AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
3076
    AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
3077
    my $lines_skipped = Koha::Account::Lines->search({
3078
        borrowernumber => $patron->id,
3079
        itemnumber     => $item->id
3080
    });
3081
    is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
3082
3074
};
3083
};
3075
3084
3076
subtest 'ProcessOfflinePayment() tests' => sub {
3085
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 854-859 subtest 'pay() handles lost items when paying by amount ( not specifying the los Link Here
854
    $schema->storage->txn_rollback;
859
    $schema->storage->txn_rollback;
855
};
860
};
856
861
862
subtest 'pay() renews items when appropriate' => sub {
863
864
    plan tests => 1;
865
866
    $schema->storage->txn_begin;
867
868
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
869
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
870
    my $account = $patron->account;
871
872
    my $context = Test::MockModule->new('C4::Context');
873
    $context->mock( 'userenv', { branch => $library->id } );
874
875
    my $biblio = $builder->build_sample_biblio();
876
    my $item =
877
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
878
879
    my $now = dt_from_string();
880
    my $seven_weeks = DateTime::Duration->new(weeks => 7);
881
    my $five_weeks = DateTime::Duration->new(weeks => 5);
882
    my $seven_weeks_ago = $now - $seven_weeks;
883
    my $five_weeks_ago = $now - $five_weeks;
884
885
    my $checkout = Koha::Checkout->new(
886
        {
887
            borrowernumber => $patron->id,
888
            itemnumber     => $item->id,
889
            date_due       => $five_weeks_ago,
890
            branchcode     => $patron->branchcode,
891
            issuedate      => $seven_weeks_ago
892
        }
893
    )->store();
894
895
    my $accountline = Koha::Account::Line->new(
896
        {
897
            issue_id       => $checkout->id,
898
            borrowernumber => $patron->id,
899
            itemnumber     => $item->id,
900
            date           => \'NOW()',
901
            accounttype    => 'OVERDUE',
902
            status         => 'UNRETURNED',
903
            interface      => 'cli',
904
            amount => '1',
905
            amountoutstanding => '1',
906
        }
907
    )->store();
908
909
    # Enable renewing upon fine payment
910
    t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
911
    my $called = 0;
912
    my $module = new Test::MockModule('C4::Circulation');
913
    $module->mock('AddRenewal', sub { $called = 1; });
914
    $account->pay(
915
        {
916
            amount     => '1',
917
            library_id => $library->id,
918
        }
919
    );
920
921
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
922
923
    $schema->storage->txn_rollback;
924
};
925
857
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
926
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
858
927
859
    plan tests => 4;
928
    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