From 3f81d28e49d1ef816312656714e8fd7a12296de0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 2 Dec 2016 11:25:29 +0100 Subject: [PATCH] Bug 17583: [QA Follow-up] Final polishing Content-Type: text/plain; charset=utf-8 Number of tests in Patrons.t corrected. Method is_going_to_expired (no english!) renamed to is_going_to_expire. Adding a negative duration replaced by a subtract. Reads easier. Signed-off-by: Marcel de Rooy --- Koha/Patron.pm | 8 ++++---- circ/circulation.pl | 2 +- t/db_dependent/Koha/Patrons.t | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 46bfe8e..92aa9cf 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -295,15 +295,15 @@ sub is_expired { return 0; } -=head2 is_going_to_expired +=head2 is_going_to_expire -my $is_going_to_expired = $patron->is_going_to_expired; +my $is_going_to_expire = $patron->is_going_to_expire; Returns 1 if the patron is going to expired, depending on the NotifyBorrowerDeparture pref or 0 =cut -sub is_going_to_expired { +sub is_going_to_expire { my ($self) = @_; my $delay = C4::Context->preference('NotifyBorrowerDeparture') || 0; @@ -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->truncate( to => 'day' ); + return 1 if dt_from_string( $self->dateexpiry )->subtract( days => $delay ) < dt_from_string->truncate( to => 'day' ); return 0; } diff --git a/circ/circulation.pl b/circ/circulation.pl index c4dde26..bc0ae4c 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -278,7 +278,7 @@ if ($borrowernumber) { ); } # check for NotifyBorrowerDeparture - elsif ( $patron->is_going_to_expired ) { + elsif ( $patron->is_going_to_expire ) { # borrower card soon to expire warn librarian $template->param( "warndeparture" => $borrower->{dateexpiry} , ); diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 2c71d21..ddd667a 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 13; +use Test::More tests => 14; use Test::Warn; use C4::Members; @@ -190,42 +190,42 @@ subtest 'is_expired' => sub { $patron->delete; }; -subtest 'is_going_to_expired' => sub { +subtest 'is_going_to_expire' => sub { plan tests => 9; my $patron = $builder->build({ source => 'Borrower' }); $patron = Koha::Patrons->find( $patron->{borrowernumber} ); $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'); + is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); $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'); + is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not 0000-00-00'); t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); $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'); + is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today'); $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'); + is( $patron->is_going_to_expire, 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->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'); + is( $patron->is_going_to_expire, 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->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'); + is( $patron->is_going_to_expire, 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->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'); + is( $patron->is_going_to_expire, 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->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'); + is( $patron->is_going_to_expire, 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->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'); + is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); $patron->delete; }; -- 2.1.4