From d05c515c19011afe4c35e13b8476deac3beedd72 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Jul 2016 00:14:56 +0100 Subject: [PATCH] Bug 16911: Koha::Patron::Categories - Add tests for ->get_expiry_date --- 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 974b982..03bd96c 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 => 5; +use Test::More tests => 6; use Koha::Database; +use Koha::DateUtils; use Koha::Patron::Category; use Koha::Patron::Categories; use t::lib::TestBuilder; @@ -49,6 +50,27 @@ is( $retrieved_category_1->categorycode, $new_category_1->categorycode, 'Find a is_deeply( $retrieved_category_1->branch_limitations, [ $branch->{branchcode} ], 'The branch limitation should have been stored and retrieved' ); is_deeply( $retrieved_category_1->default_messaging, [], 'By default there is not messaging option' ); +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.8.1