From 9d8754b480cb18e20b2ee00dfddc668479cec89e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 4 Mar 2019 13:18:51 -0300 Subject: [PATCH] Bug 22446: Explicitely list what we expect to avoid ambiguity --- t/db_dependent/Koha/Patron/Categories.t | 54 ++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index 1e2ddb7d6d..3153c8aa17 100644 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -62,16 +62,56 @@ is( $retrieved_category_1->checkprevcheckout, 'inherit', 'Koha::Patron::Category is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' ); subtest 'get_expiry_date' => sub { - plan tests => 5; - 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 => 3; + my $cases = [ + { + today => '2016-03-31', + next_month => '2016-04-30', + next_year => '2017-03-31', + yesterday => '2016-03-30', + }, + { + today => '2016-11-30', + next_month => '2016-12-31', + next_year => '2017-11-30', + yesterday => '2016-11-29', + }, + { + today => '2019-01-31', + next_month => '2019-02-28', + next_year => '2020-01-31', + yesterday => '2019-01-30', + }, + { + today => '2019-02-28', + next_month => '2019-03-31', + next_year => '2020-02-29', + yesterday => '2019-02-27', + }, + { + today => '2019-03-01', + next_month => '2019-02-28', + next_year => '2020-03-01', + yesterday => '2019-02-28', + }, + { + today => '2020-02-29', + next_month => '2021-03-31', + next_year => '2021-02-28', + yesterday => '2020-02-28', + }, + # TODO re-add today, dt_from_string + ]; + for my $date ( @$cases ) { + my $today = $date->{today}; + subtest "get_expiry_date with today=$today" => sub { plan tests => 5; - my $dt = dt_from_string( $date, 'iso' ); + my $dt = dt_from_string( $today, '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 $next_month = dt_from_string($date->{next_month}, 'iso'); + my $next_year = dt_from_string($date->{next_year}, 'iso'); + my $yesterday = dt_from_string($date->{yesterday}, 'iso'); my $category = Koha::Patron::Category->new({ categorycode => 'mycat', category_type => 'A', -- 2.11.0