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 <josef.moravec@gmail.com> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
81ea88fff6
commit
d892342e6f
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
|
|
|
|||
Loading…
Reference in New Issue