From 74501857667161fc6020cb1502aa22a9cee6f499 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 12 Jul 2016 00:18:56 +0100 Subject: [PATCH] Bug 16911: Koha::Patrons - Add tests for ->extend_subscription --- t/db_dependent/Koha/Patrons.t | 48 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 980bf84..117ecb4 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -19,12 +19,14 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Test::Warn; use Koha::Patron; use Koha::Patrons; use Koha::Database; +use Koha::DateUtils; +use Koha::Virtualshelves; use t::lib::TestBuilder; use t::lib::Mocks; @@ -127,6 +129,50 @@ subtest 'update_password' => sub { is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' ); }; +subtest 'extend_subscription' => sub { + plan tests => 6; + my $a_month_ago = dt_from_string->add( months => -1 )->truncate( to => 'day' ); + my $a_year_later = dt_from_string->add( months => 12 )->truncate( to => 'day' ); + my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' ); + my $patron_category = $builder->build( + { source => 'Category', + value => { + enrolmentperiod => 12, + enrolmentperioddate => undef, + } + } + ); + my $patron = $builder->build( + { source => 'Borrower', + value => { + dateexpiry => $a_month_ago, + categorycode => $patron_category->{categorycode}, + } + } + ); + my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); + + t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); + t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); + my $expiry_date = $retrieved_patron->extend_subscription; + is( $expiry_date, $a_year_later_minus_a_month, ); + my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; + is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); + my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; + is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->extend_subscription should have logged' ); + + t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); + t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); + $expiry_date = $retrieved_patron->extend_subscription; + is( $expiry_date, $a_year_later, ); + $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; + is( dt_from_string($retrieved_expiry_date), $a_year_later ); + $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; + is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->extend_subscription should not have logged' ); + + $retrieved_patron->delete; +}; + $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); -- 2.8.1