Bugzilla – Attachment 100128 Details for
Bug 23051
Add ability to optionally renew fine accruing items when all fines on item are paid off
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23051: Add unit tests
Bug-23051-Add-unit-tests.patch (text/plain), 7.90 KB, created by
Andrew Isherwood
on 2020-03-04 14:29:31 UTC
(
hide
)
Description:
Bug 23051: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2020-03-04 14:29:31 UTC
Size:
7.90 KB
patch
obsolete
>From 98f7aa8f2feedf81bf3f5034bc389663f0fd67bf Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Wed, 4 Mar 2020 09:24:47 +0000 >Subject: [PATCH] Bug 23051: Add unit tests > >This patch adds unit tests for all modules affected by this bug > >Signed-off-by: Lucy Harrison <L.M.Harrison@lboro.ac.uk> >Sponsored-by: Loughborough University >--- > t/db_dependent/Circulation.t | 11 +++++- > t/db_dependent/Koha/Account.t | 71 +++++++++++++++++++++++++++++++++++++- > t/db_dependent/Koha/Account/Line.t | 52 +++++++++++++++++++++++++++- > 3 files changed, 131 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 121c1767b4..66c3617638 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -3326,7 +3326,7 @@ subtest 'AddReturn should clear items.onloan for unissued items' => sub { > > subtest 'AddRenewal and AddIssuingCharge tests' => sub { > >- plan tests => 11; >+ plan tests => 12; > > > t::lib::Mocks::mock_preference('item-level_itypes', 1); >@@ -3419,6 +3419,15 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { > is( $new_log_size, $old_log_size + 1, 'renew log successfully added' ); > is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' ); > >+ AddReturn( $item->id, $library->id, undef, $date ); >+ AddIssue( $patron->unblessed, $item->barcode, dt_from_string() ); >+ AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 ); >+ my $lines_skipped = Koha::Account::Lines->search({ >+ borrowernumber => $patron->id, >+ itemnumber => $item->id >+ }); >+ is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' ); >+ > }; > > subtest 'ProcessOfflinePayment() tests' => sub { >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index 5437f16403..baeb0052c9 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -23,10 +23,12 @@ use Test::More tests => 11; > use Test::MockModule; > use Test::Exception; > >+use DateTime; >+ > use Koha::Account; > use Koha::Account::Lines; > use Koha::Account::Offsets; >- >+use Koha::DateUtils qw( dt_from_string ); > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -673,6 +675,9 @@ subtest 'pay() tests' => sub { > > $schema->storage->txn_begin; > >+ # Disable renewing upon fine payment >+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); >+ > my $patron = $builder->build_object({ class => 'Koha::Patrons' }); > my $library = $builder->build_object({ class => 'Koha::Libraries' }); > my $account = $patron->account; >@@ -897,6 +902,70 @@ subtest 'pay() handles lost items when paying by amount ( not specifying the los > $schema->storage->txn_rollback; > }; > >+subtest 'pay() renews items when appropriate' => sub { >+ >+ plan tests => 1; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $account = $patron->account; >+ >+ my $context = Test::MockModule->new('C4::Context'); >+ $context->mock( 'userenv', { branch => $library->id } ); >+ >+ my $biblio = $builder->build_sample_biblio(); >+ my $item = >+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ >+ my $now = dt_from_string(); >+ my $seven_weeks = DateTime::Duration->new(weeks => 7); >+ my $five_weeks = DateTime::Duration->new(weeks => 5); >+ my $seven_weeks_ago = $now - $seven_weeks; >+ my $five_weeks_ago = $now - $five_weeks; >+ >+ my $checkout = Koha::Checkout->new( >+ { >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ date_due => $five_weeks_ago, >+ branchcode => $patron->branchcode, >+ issuedate => $seven_weeks_ago >+ } >+ )->store(); >+ >+ my $accountline = Koha::Account::Line->new( >+ { >+ issue_id => $checkout->id, >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ date => \'NOW()', >+ accounttype => 'OVERDUE', >+ status => 'UNRETURNED', >+ interface => 'cli', >+ amount => '1', >+ amountoutstanding => '1', >+ } >+ )->store(); >+ >+ # Enable renewing upon fine payment >+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); >+ my $called = 0; >+ my $module = new Test::MockModule('C4::Circulation'); >+ $module->mock('AddRenewal', sub { $called = 1; }); >+ $account->pay( >+ { >+ amount => '1', >+ library_id => $library->id, >+ } >+ ); >+ >+ is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'Koha::Account::Line::apply() handles lost items' => sub { > > plan tests => 4; >diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t >index 1c28f569c5..1768a5964c 100644 >--- a/t/db_dependent/Koha/Account/Line.t >+++ b/t/db_dependent/Koha/Account/Line.t >@@ -21,12 +21,16 @@ use Modern::Perl; > > use Test::More tests => 11; > use Test::Exception; >+use Test::MockModule; >+ >+use DateTime; > > use C4::Circulation qw/AddIssue AddReturn/; > use Koha::Account; > use Koha::Account::Lines; > use Koha::Account::Offsets; > use Koha::Items; >+use Koha::DateUtils qw( dt_from_string ); > > use t::lib::Mocks; > use t::lib::TestBuilder; >@@ -132,7 +136,7 @@ subtest 'is_credit() and is_debit() tests' => sub { > > subtest 'apply() tests' => sub { > >- plan tests => 24; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -243,6 +247,52 @@ subtest 'apply() tests' => sub { > is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); > is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); > >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $biblio = $builder->build_sample_biblio(); >+ my $item = >+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); >+ my $now = dt_from_string(); >+ my $seven_weeks = DateTime::Duration->new(weeks => 7); >+ my $five_weeks = DateTime::Duration->new(weeks => 5); >+ my $seven_weeks_ago = $now - $seven_weeks; >+ my $five_weeks_ago = $now - $five_weeks; >+ >+ my $checkout = Koha::Checkout->new( >+ { >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ date_due => $five_weeks_ago, >+ branchcode => $library->id, >+ issuedate => $seven_weeks_ago >+ } >+ )->store(); >+ >+ my $accountline = Koha::Account::Line->new( >+ { >+ issue_id => $checkout->id, >+ borrowernumber => $patron->id, >+ itemnumber => $item->id, >+ branchcode => $library->id, >+ date => \'NOW()', >+ accounttype => 'OVERDUE', >+ status => 'UNRETURNED', >+ interface => 'cli', >+ amount => '1', >+ amountoutstanding => '1', >+ } >+ )->store(); >+ >+ # Enable renewing upon fine payment >+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); >+ my $called = 0; >+ my $module = new Test::MockModule('C4::Circulation'); >+ $module->mock('AddRenewal', sub { $called = 1; }); >+ my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); >+ my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id }); >+ $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); >+ >+ is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23051
:
90559
|
90560
|
90561
|
91058
|
91059
|
91060
|
91792
|
91793
|
91794
|
91795
|
92684
|
92685
|
92686
|
92687
|
92688
|
92689
|
93922
|
93923
|
93924
|
93925
|
94020
|
94021
|
94022
|
94023
|
94024
|
94402
|
94434
|
94453
|
94525
|
94604
|
94605
|
94606
|
94607
|
94608
|
94609
|
94610
|
94611
|
94629
|
94649
|
95557
|
95558
|
95559
|
95560
|
100127
|
100128
|
100129
|
100130
|
100131
|
100132
|
100133
|
100134
|
100135
|
100138
|
100172
|
100182
|
100183
|
100184
|
100185
|
100186
|
100187
|
100188
|
100271