Bug 16911: Koha::Patrons - Add tests for ->extend_subscription
Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
92bfc28eb0
commit
076ef1e22e
|
|
@ -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' );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue