|
Lines 19-31
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
|
|
23 |
|
| 24 |
use C4::Members; |
| 23 |
|
25 |
|
| 24 |
use Koha::Patron; |
26 |
use Koha::Patron; |
| 25 |
use Koha::Patrons; |
27 |
use Koha::Patrons; |
| 26 |
use Koha::Database; |
28 |
use Koha::Database; |
|
|
29 |
use Koha::DateUtils; |
| 30 |
use Koha::Virtualshelves; |
| 27 |
|
31 |
|
| 28 |
use t::lib::TestBuilder; |
32 |
use t::lib::TestBuilder; |
|
|
33 |
use t::lib::Mocks; |
| 29 |
|
34 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
35 |
my $schema = Koha::Database->new->schema; |
| 31 |
$schema->storage->txn_begin; |
36 |
$schema->storage->txn_begin; |
|
Lines 98-103
subtest 'siblings' => sub {
Link Here
|
| 98 |
$retrieved_guarantee_1->delete; |
103 |
$retrieved_guarantee_1->delete; |
| 99 |
}; |
104 |
}; |
| 100 |
|
105 |
|
|
|
106 |
subtest 'extend_subscription' => sub { |
| 107 |
plan tests => 6; |
| 108 |
my $a_month_ago = dt_from_string->add( months => -1 )->truncate( to => 'day' ); |
| 109 |
my $a_year_later = dt_from_string->add( months => 12 )->truncate( to => 'day' ); |
| 110 |
my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' ); |
| 111 |
my $patron_category = $builder->build( |
| 112 |
{ source => 'Category', |
| 113 |
value => { |
| 114 |
enrolmentperiod => 12, |
| 115 |
enrolmentperioddate => undef, |
| 116 |
} |
| 117 |
} |
| 118 |
); |
| 119 |
my $patron = $builder->build( |
| 120 |
{ source => 'Borrower', |
| 121 |
value => { |
| 122 |
dateexpiry => $a_month_ago, |
| 123 |
categorycode => $patron_category->{categorycode}, |
| 124 |
} |
| 125 |
} |
| 126 |
); |
| 127 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 128 |
|
| 129 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); |
| 130 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
| 131 |
my $expiry_date = $retrieved_patron->extend_subscription; |
| 132 |
is( $expiry_date, $a_year_later_minus_a_month, ); |
| 133 |
my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
| 134 |
is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); |
| 135 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
| 136 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->extend_subscription should have logged' ); |
| 137 |
|
| 138 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); |
| 139 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
| 140 |
$expiry_date = $retrieved_patron->extend_subscription; |
| 141 |
is( $expiry_date, $a_year_later, ); |
| 142 |
$retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
| 143 |
is( dt_from_string($retrieved_expiry_date), $a_year_later ); |
| 144 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
| 145 |
is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->extend_subscription should not have logged' ); |
| 146 |
|
| 147 |
$retrieved_patron->delete; |
| 148 |
}; |
| 149 |
|
| 101 |
$retrieved_patron_1->delete; |
150 |
$retrieved_patron_1->delete; |
| 102 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
151 |
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); |
| 103 |
|
152 |
|
| 104 |
- |
|
|