From ec034be633212f630d4b8dd47696d7ce939cfa8f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 9 Nov 2016 11:25:16 +0000 Subject: [PATCH] Bug 17583: Fix tests --- Koha/Patron.pm | 2 +- t/db_dependent/Koha/Patrons.t | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 577920e..06204d4 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -297,7 +297,7 @@ sub is_going_to_expired { 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; return 0; } diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 8175a05..67d72a3 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -196,33 +196,32 @@ subtest 'is_going_to_expired' => sub { $patron->dateexpiry( '0000-00-00' )->store; 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; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today'); + is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is today'); t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); - my $dt_from_string = dt_from_string; - $patron->dateexpiry( $dt_from_string )->store; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); + $patron->dateexpiry( dt_from_string )->store; + is( $patron->is_going_to_expired, 1, 'Patron should 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; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days before and pref is 10'); + 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; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 0'); + 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; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days before and pref is 10'); + is( $patron->is_going_to_expired, 1, 'Patron should 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; - is( $patron->is_going_to_expired, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days before and pref is 10'); + 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; - is( $patron->is_going_to_expired, 1, 'Patron should be considered going to expire if dateexpiry is 10 days before and pref is 20'); + 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; }; -- 2.1.4