From d892342e6f8569a4ea51a0e550b5d9c59b92e588 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Nov 2016 17:12:58 +0000 Subject: [PATCH] Bug 17579: Add the Koha::Patron->is_expired This new method will be handy for further uses Test plan: prove t/db_dependent/Koha/Patrons.t should return green Signed-off-by: Josef Moravec Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall --- Koha/Patron.pm | 16 ++++++++++++++++ t/db_dependent/Koha/Patrons.t | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 9867aebe61..478a0cd906 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -279,6 +279,22 @@ sub is_debarred { return; } +=head2 is_expired + +my $is_expired = $patron->is_expired; + +Returns 1 if the patron is expired or 0; + +=cut + +sub is_expired { + my ($self) = @_; + return 0 unless $self->dateexpiry; + return 0 if $self->dateexpiry eq '0000-00-00'; + return 1 if dt_from_string( $self->dateexpiry ) < dt_from_string; + return 0; +} + =head2 update_password my $updated = $patron->update_password( $userid, $password ); diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 1775bb5ae4..692cd20df6 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -172,6 +172,24 @@ subtest 'update_password' => sub { is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' ); }; +subtest 'is_expired' => sub { + plan tests => 5; + my $patron = $builder->build({ source => 'Borrower' }); + $patron = Koha::Patrons->find( $patron->{borrowernumber} ); + $patron->dateexpiry( undef )->store; + is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set'); + $patron->dateexpiry( '0000-00-00' )->store; + is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not 0000-00-00'); + $patron->dateexpiry( dt_from_string )->store; + is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today'); + $patron->dateexpiry( dt_from_string->add( days => 1 ) )->store; + is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is tomorrow'); + $patron->dateexpiry( dt_from_string->add( days => -1 ) )->store; + is( $patron->is_expired, 1, 'Patron should be considered expired if dateexpiry is yesterday'); + + $patron->delete; +}; + subtest 'renew_account' => sub { plan tests => 10; my $a_month_ago = dt_from_string->add( months => -1 )->truncate( to => 'day' ); -- 2.39.5