Bugzilla – Attachment 90561 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.97 KB, created by
Andrew Isherwood
on 2019-06-13 07:44:34 UTC
(
hide
)
Description:
Bug 23051: Add unit tests
Filename:
MIME Type:
Creator:
Andrew Isherwood
Created:
2019-06-13 07:44:34 UTC
Size:
7.97 KB
patch
obsolete
>From 9efecba27eb8d6383c594fe56e1a7e984c6c23f5 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >Date: Wed, 12 Jun 2019 15:18:54 +0100 >Subject: [PATCH] Bug 23051: Add unit tests > >This patch adds unit tests for all modules affected by this bug >--- > t/db_dependent/Circulation.t | 11 +++++- > t/db_dependent/Koha/Account.t | 72 ++++++++++++++++++++++++++++++++++++- > t/db_dependent/Koha/Account/Lines.t | 52 ++++++++++++++++++++++++++- > 3 files changed, 132 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index eb8be21a9a..948f241e2f 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -2996,7 +2996,7 @@ $cache->clear_from_cache('single_holidays'); > > subtest 'AddRenewal and AddIssuingCharge tests' => sub { > >- plan tests => 13; >+ plan tests => 14; > > $schema->storage->txn_begin; > >@@ -3085,6 +3085,15 @@ subtest 'AddRenewal and AddIssuingCharge tests' => sub { > is( $line->branchcode, $library->id, 'AddRenewal correctly sets branchcode' ); > is( $line->description, "Renewal of Rental Item $title $barcode", 'AddRenewal set a hardcoded description for the accountline' ); > >+ 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' ); >+ > $schema->storage->txn_rollback; > }; > >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index 735a7c950a..4e4b05e794 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; >@@ -567,6 +569,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; >@@ -584,6 +589,7 @@ subtest 'pay() tests' => sub { > > is( $credit_2->branchcode, $library->id, 'branchcode set because library_id was passed' ); > >+ > $schema->storage->txn_rollback; > }; > >@@ -731,6 +737,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/Lines.t b/t/db_dependent/Koha/Account/Lines.t >index 3856f6ef14..ae0baa9fd4 100755 >--- a/t/db_dependent/Koha/Account/Lines.t >+++ b/t/db_dependent/Koha/Account/Lines.t >@@ -21,12 +21,16 @@ use Modern::Perl; > > use Test::More tests => 8; > 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; >@@ -180,7 +184,7 @@ subtest 'is_credit() and is_debit() tests' => sub { > > subtest 'apply() tests' => sub { > >- plan tests => 24; >+ plan tests => 25; > > $schema->storage->txn_begin; > >@@ -291,6 +295,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