From 9222bdfa14d19e4737dd7ebefc405492ed2dc1c3 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 29 Aug 2022 16:30:01 +1200 Subject: [PATCH] Bug 31051: (follow-up) Tests for get_savings and more - Added tests in t/db_dependent/Koha/Patron.t - Added wording to OPACShowSavings syspref about anonymised checkout history - Added IDs to the savings messages on the OPAC Sponsored-by: Horowhenua Libraries Trust --- .../prog/en/modules/admin/preferences/opac.pref | 1 + .../bootstrap/en/modules/opac-readingrecord.tt | 2 +- .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 2 +- t/db_dependent/Koha/Patron.t | 31 +++++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index 5c430c944b..71ae54bf7d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -550,6 +550,7 @@ OPAC: checkouthistory: "on patron's checkout history page (the system preference opacreadinghistory must be enabled)" summary: "in user summary box on OPAC homepage (the system preference OPACUserSummary must be enabled)" user: "on patron's 'your summary' page" + - ". Note that displayed savings may be inaccurate if checkout history is anonymized." OpenURL: - - 'Complete URL of OpenURL resolver (starting with http:// or https://):' diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt index 10c00819be..27fe3f257d 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -56,7 +56,7 @@
[% IF savings %] -
+
Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
[% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt index aedfebb923..88a26ab9eb 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -163,7 +163,7 @@ [% END # / IF patron_flagged %] [% IF savings %] -
+
Congratulations, you have saved a total of [% savings | $Price with_symbol => 1 %] by using the library.
[% END %] diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 977ec261d6..0c0f3c8ba4 100755 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 18; +use Test::More tests => 19; use Test::Exception; use Test::Warn; @@ -29,6 +29,7 @@ use Koha::DateUtils qw(dt_from_string); use Koha::ArticleRequests; use Koha::Patrons; use Koha::Patron::Relationships; +use C4::Circulation qw( AddIssue AddReturn ); use t::lib::TestBuilder; use t::lib::Mocks; @@ -1292,3 +1293,31 @@ subtest 'encode_secret and decoded_secret' => sub { $schema->storage->txn_rollback; }; + +subtest 'get_savings tests' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + + my $library = $builder->build_object({ class => 'Koha::Libraries' }); + my $patron = $builder->build_object({ class => 'Koha::Patrons' }, { value => { branchcode => $library->branchcode } }); + + t::lib::Mocks::mock_userenv({ patron => $patron, branchcode => $library->branchcode }); + + my $biblio1 = $builder->build_object({ class => 'Koha::Biblios' }); + my $item1 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $biblio1->biblionumber, replacementprice => '5.00', holdingbranch => $library->branchcode, homebranch => $library->branchcode } }); + my $item2 = $builder->build_object({ class => 'Koha::Items' }, { value => { biblionumber => $biblio1->biblionumber, replacementprice => '5.00', holdingbranch => $library->branchcode, homebranch => $library->branchcode } }); + + AddIssue( $patron->unblessed, $item1->barcode ); + AddIssue( $patron->unblessed, $item2->barcode ); + + my $savings = $patron->get_savings; + is( $savings, $item1->replacementprice + $item2->replacementprice, "Savings correctly calculated from current issues" ); + + AddReturn( $item2->barcode, $item2->homebranch ); + + $savings = $patron->get_savings; + is( $savings, $item1->replacementprice + $item2->replacementprice, "Savings correctly calculated from current and old issues" ); + + $schema->storage->txn_rollback; +}; -- 2.11.0