From cedacf5b2416f60a26b45511655c902cecf73462 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Jul 2016 00:14:56 +0100 Subject: [PATCH] [SIGNED-OFF] Bug 16911: Koha::Patron::Categories - Add tests for ->get_expiry_date Signed-off-by: Aleisha Amohia --- t/db_dependent/Koha/Patron/Categories.t | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron/Categories.t b/t/db_dependent/Koha/Patron/Categories.t index df0327c..75f2747 100644 --- a/t/db_dependent/Koha/Patron/Categories.t +++ b/t/db_dependent/Koha/Patron/Categories.t @@ -19,9 +19,10 @@ use Modern::Perl; -use Test::More tests => 7; +use Test::More tests => 8; use Koha::Database; +use Koha::DateUtils; use Koha::Patron::Category; use Koha::Patron::Categories; use t::lib::TestBuilder; @@ -54,6 +55,27 @@ my $retrieved_category_2 = Koha::Patron::Categories->find( $new_category_2->cate is( $retrieved_category_1->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' ); is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' ); +subtest 'get_expiry_date' => sub { + plan tests => 4; + 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( $category->get_expiry_date, $next_year, 'With enrolmentperiod defined and no parameter, ->get_expiry_date should return today + enrolmentperiod' ); + is( $category->get_expiry_date( $yesterday ), $next_year->clone->add( days => -1 ), 'With enrolmentperiod defined and a date given in parameter, ->get_expiry_date should take this date + enrolmentperiod' ); + $category->delete; +}; + $retrieved_category_1->delete; is( Koha::Patron::Categories->search->count, $nb_of_categories + 1, 'Delete should have deleted the patron category' ); -- 2.1.4