From 91a55a7b59744af4098d2b3b749567f9ef7b4ce3 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 31 Oct 2016 14:04:01 +0000 Subject: [PATCH] Bug 17522 - opac-user.pl gives error of OpacRenewalAllowed is enabled If OpacRenewalAllowed is enabled, the following error message is displayed: Template process failed: undef error - The method is_expired is not covered by tests! at /home/vagrant/kohaclone/C4/Templates.pm line 121. Test Plan: 1) Check out an item for a patron 2) Enable OpacRenewalAllowed 3) Log in as that patron, go to opac-user.pl 4) Note the error 5) Apply this patch 6) Reload opac-user.pl 7) Page should now load! --- Koha/Patron.pm | 15 +++++++++++++++ .../opac-tmpl/bootstrap/en/modules/opac-user.tt | 10 +++++----- t/Patron.t | 22 +++++++++++++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 9a2fd18..9787ffb 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -266,6 +266,21 @@ sub is_debarred { return; } +=head2 is_expired + +my $is_expired = $patron->is_expired; + +Returns true if the patron is passed the expiry date, false otherwise + +=cut + +sub is_expired { + my ($self) = @_; + + return 1 if $self->dateexpiry && dt_from_string( $self->dateexpiry ) < dt_from_string; + return 0; +} + =head2 update_password my $updated = $patron->update_password( $userid, $password ); 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 438cb10..af533a4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt @@ -156,7 +156,7 @@ Using this account is not recommended because some parts of Koha will not functi Barcode [% END %] Call no. - [% IF ( OpacRenewalAllowed && !( borrower.is_expired && borrower.BlockExpiredPatronOpacActions ) ) %] + [% IF ( OpacRenewalAllowed && !( borrower.is_expired && Koha.Preference('BlockExpiredPatronOpacActions') ) ) %] Renew [% END %] [% IF ( OPACFinesTab ) %] @@ -245,7 +245,7 @@ Using this account is not recommended because some parts of Koha will not functi Call no.: [% ISSUE.itemcallnumber %] - [% IF ( OpacRenewalAllowed && !( borrower.is_expired && borrower.BlockExpiredPatronOpacActions ) ) %] + [% IF ( OpacRenewalAllowed && !( borrower.is_expired && Koha.Preference('BlockExpiredPatronOpacActions') ) ) %] [% IF ISSUE.renewed %]Renewed!
[% END %] [% IF ( ISSUE.status ) %] @@ -285,12 +285,12 @@ Using this account is not recommended because some parts of Koha will not functi [% END # /FOREACH ISSUES %] - [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && borrower.BlockExpiredPatronOpacActions ) ) %] + [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && Koha.Preference('BlockExpiredPatronOpacActions') ) ) %] [% END %] - [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && borrower.BlockExpiredPatronOpacActions ) ) %] + [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && Koha.Preference('BlockExpiredPatronOpacActions') ) ) %]
@@ -876,7 +876,7 @@ Using this account is not recommended because some parts of Koha will not functi e.preventDefault(); $("#renewall").submit(); }); - [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && borrower.BlockExpiredPatronOpacActions ) ) %] + [% IF ( canrenew && !userdebarred && OpacRenewalAllowed && !( borrower.is_expired && Koha.Preference('BlockExpiredPatronOpacActions') ) ) %] $("#checkoutst caption").append(""); [% END %] [% END %] diff --git a/t/Patron.t b/t/Patron.t index c32de10..14a5b81 100755 --- a/t/Patron.t +++ b/t/Patron.t @@ -17,14 +17,16 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 13; use Test::Warn; use t::lib::Mocks; +use t::lib::Mocks qw(mock_preference); BEGIN { t::lib::Mocks::mock_dbh; use_ok('Koha::Object'); use_ok('Koha::Patron'); + use_ok('Koha::DateUtils'); } my $object = Koha::Patron->new( { surname => 'Test Patron' } ); @@ -324,4 +326,22 @@ subtest 'Set tests' => sub { is( $patron->privacy, '667789', 'privacy field set ok' ); }; +subtest 'is_expiry tests' => sub { + plan tests => 4; + + t::lib::Mocks::mock_preference( "dateformat", "iso" ); + + $patron->dateexpiry(undef); + ok( !$patron->is_expired, "Patron is not expired if expiry date is not set" ); + + $patron->dateexpiry("1900-01-01"); + ok( $patron->is_expired, "Patron is expired with expiry date 1900-01-01" ); + + $patron->dateexpiry("9999-01-01"); + ok( !$patron->is_expired, "Patron is not expired with expiry date 9999-01-01" ); + + $patron->dateexpiry( dt_from_string->ymd ); + ok( $patron->is_expired, "Patron is not expired if the expiration date is today's date" ); +}; + 1; -- 2.1.4