Bug 17583: Make sure we are comparing 2 dates
Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
c48646e956
commit
ac281a1291
2 changed files with 10 additions and 10 deletions
|
@ -311,7 +311,7 @@ sub is_going_to_expired {
|
|||
return 0 unless $delay;
|
||||
return 0 unless $self->dateexpiry;
|
||||
return 0 if $self->dateexpiry eq '0000-00-00';
|
||||
return 1 if dt_from_string( $self->dateexpiry )->add( days => -$delay ) < dt_from_string;
|
||||
return 1 if dt_from_string( $self->dateexpiry )->add( days => -$delay ) < dt_from_string->truncate( to => 'day' );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -194,36 +194,36 @@ subtest 'is_going_to_expired' => sub {
|
|||
plan tests => 9;
|
||||
my $patron = $builder->build({ source => 'Borrower' });
|
||||
$patron = Koha::Patrons->find( $patron->{borrowernumber} );
|
||||
$patron->dateexpiry( undef )->store;
|
||||
$patron->dateexpiry( undef )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not set');
|
||||
$patron->dateexpiry( '0000-00-00' )->store;
|
||||
$patron->dateexpiry( '0000-00-00' )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00');
|
||||
$patron->dateexpiry( dt_from_string )->store;
|
||||
$patron->dateexpiry( dt_from_string )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today');
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
|
||||
$patron->dateexpiry( dt_from_string )->store;
|
||||
$patron->dateexpiry( dt_from_string )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0');
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
|
||||
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store;
|
||||
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10');
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0);
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0');
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10');
|
||||
$patron->delete;
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10);
|
||||
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store;
|
||||
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10');
|
||||
|
||||
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20);
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store;
|
||||
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes;
|
||||
is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20');
|
||||
|
||||
$patron->delete;
|
||||
|
|
Loading…
Reference in a new issue