From 2ca2b7db04ab7fb88f9d54c6373a142e4f74bd89 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Sat, 2 Mar 2019 14:36:40 -0300 Subject: [PATCH] Bug 22446: Add tests to highlight the problem --- t/db_dependent/Koha/Patron/Categories.t | 51 +++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index 58882a493e..1e2ddb7d6d 100644 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::More tests => 10; +use Time::Fake; use C4::Context; use Koha::Database; @@ -62,27 +63,35 @@ is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category subtest 'get_expiry_date' => sub { plan tests => 5; - my $next_month = dt_from_string->add( months => 1 ); - my $next_year = dt_from_string->add( months => 12 ); - my $yesterday = dt_from_string->add( days => -1 ); - my $category = Koha::Patron::Category->new({ - categorycode => 'mycat', - category_type => 'A', - description => 'mycatdesc', - enrolmentperiod => undef, - enrolmentperioddate => $next_month, - })->store; - is( $category->get_expiry_date, $next_month, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' ); - is( $category->get_expiry_date( $next_year ), $next_month, 'Without enrolmentperiod, ->get_expiry_date should return enrolmentperiodadate even if a parameter is given' ); - - $category->enrolmentperiod( 12 )->store; - is( t::lib::Dates::compare($category->get_expiry_date, $next_year), 0, 'With enrolmentperiod defined and no parameter, ->get_expiry_date should return today + enrolmentperiod' ); - is( t::lib::Dates::compare($category->get_expiry_date( $yesterday ), $next_year->clone->add( days => -1 )), 0, 'With enrolmentperiod defined and a date given in parameter, ->get_expiry_date should take this date + enrolmentperiod' ); - - my $hardcoded_date = '2000-01-31'; - is( t::lib::Dates::compare($category->get_expiry_date( $hardcoded_date ), dt_from_string( $hardcoded_date )->add( months => 12 )), 0, 'get_expiry_date accepts strings as well' ); - - $category->delete; + for my $date ( '2016-03-31', '2016-11-30', '2019-01-31', '2019-03-01', dt_from_string() ) { + subtest "get_expiry_date with today=$date" => sub { + plan tests => 5; + my $dt = dt_from_string( $date, 'iso' ); + Time::Fake->offset( $dt->epoch ); + + my $next_month = dt_from_string->add( months => 1 ); + my $next_year = dt_from_string->add( months => 12 ); + my $yesterday = dt_from_string->add( days => -1 ); + my $category = Koha::Patron::Category->new({ + categorycode => 'mycat', + category_type => 'A', + description => 'mycatdesc', + enrolmentperiod => undef, + enrolmentperioddate => $next_month, + })->store; + is( $category->get_expiry_date, $next_month, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' ); + is( $category->get_expiry_date( $next_year ), $next_month, 'Without enrolmentperiod, ->get_expiry_date should return enrolmentperiodadate even if a parameter is given' ); + + $category->enrolmentperiod( 12 )->store; + is( t::lib::Dates::compare($category->get_expiry_date, $next_year), 0, 'With enrolmentperiod defined and no parameter, ->get_expiry_date should return today + enrolmentperiod' ); + is( t::lib::Dates::compare($category->get_expiry_date( $yesterday ), $next_year->clone->add( days => -1 )), 0, 'With enrolmentperiod defined and a date given in parameter, ->get_expiry_date should take this date + enrolmentperiod' ); + + my $hardcoded_date = '2000-01-31'; + is( t::lib::Dates::compare($category->get_expiry_date( $hardcoded_date ), dt_from_string( $hardcoded_date )->add( months => 12 )), 0, 'get_expiry_date accepts strings as well' ); + + $category->delete; + }; + } }; subtest 'BlockExpiredPatronOpacActions' => sub { -- 2.11.0