Lines 21-26
use Modern::Perl;
Link Here
|
21 |
|
21 |
|
22 |
use Test::More tests => 22; |
22 |
use Test::More tests => 22; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
|
24 |
use Time::Fake; |
24 |
use DateTime; |
25 |
use DateTime; |
25 |
|
26 |
|
26 |
use C4::Biblio; |
27 |
use C4::Biblio; |
Lines 242-321
subtest 'is_going_to_expire' => sub {
Link Here
|
242 |
|
243 |
|
243 |
|
244 |
|
244 |
subtest 'renew_account' => sub { |
245 |
subtest 'renew_account' => sub { |
245 |
plan tests => 10; |
246 |
plan tests => 30; |
246 |
my $a_month_ago = dt_from_string->add( months => -1 )->truncate( to => 'day' ); |
247 |
|
247 |
my $a_year_later = dt_from_string->add( months => 12 )->truncate( to => 'day' ); |
248 |
for my $date ( '2016-03-31', '2016-11-30', dt_from_string() ) { |
248 |
my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' ); |
249 |
my $dt = dt_from_string( $date, 'iso' ); |
249 |
my $a_month_later = dt_from_string->add( months => 1 )->truncate( to => 'day' ); |
250 |
Time::Fake->offset( $dt->epoch ); |
250 |
my $a_year_later_plus_a_month = dt_from_string->add( months => 13 )->truncate( to => 'day' ); |
251 |
my $a_month_ago = $dt->clone->subtract( months => 1 )->truncate( to => 'day' ); |
251 |
my $patron_category = $builder->build( |
252 |
my $a_year_later = $dt->clone->add( months => 12 )->truncate( to => 'day' ); |
252 |
{ source => 'Category', |
253 |
my $a_year_later_minus_a_month = $dt->clone->add( months => 11 )->truncate( to => 'day' ); |
253 |
value => { |
254 |
my $a_month_later = $dt->clone->add( months => 1 )->truncate( to => 'day' ); |
254 |
enrolmentperiod => 12, |
255 |
my $a_year_later_plus_a_month = $dt->clone->add( months => 13 )->truncate( to => 'day' ); |
255 |
enrolmentperioddate => undef, |
256 |
my $patron_category = $builder->build( |
|
|
257 |
{ source => 'Category', |
258 |
value => { |
259 |
enrolmentperiod => 12, |
260 |
enrolmentperioddate => undef, |
261 |
} |
256 |
} |
262 |
} |
257 |
} |
263 |
); |
258 |
); |
264 |
my $patron = $builder->build( |
259 |
my $patron = $builder->build( |
265 |
{ source => 'Borrower', |
260 |
{ source => 'Borrower', |
266 |
value => { |
261 |
value => { |
267 |
dateexpiry => $a_month_ago, |
262 |
dateexpiry => $a_month_ago, |
268 |
categorycode => $patron_category->{categorycode}, |
263 |
categorycode => $patron_category->{categorycode}, |
269 |
} |
264 |
} |
270 |
} |
265 |
} |
271 |
); |
266 |
); |
272 |
my $patron_2 = $builder->build( |
267 |
my $patron_2 = $builder->build( |
273 |
{ source => 'Borrower', |
268 |
{ source => 'Borrower', |
274 |
value => { |
269 |
value => { |
275 |
dateexpiry => $a_month_ago, |
270 |
dateexpiry => $a_month_ago, |
276 |
categorycode => $patron_category->{categorycode}, |
271 |
categorycode => $patron_category->{categorycode}, |
277 |
} |
272 |
} |
278 |
} |
273 |
} |
279 |
); |
274 |
); |
280 |
my $patron_3 = $builder->build( |
275 |
my $patron_3 = $builder->build( |
281 |
{ source => 'Borrower', |
276 |
{ source => 'Borrower', |
282 |
value => { |
277 |
value => { |
283 |
dateexpiry => $a_month_later, |
278 |
dateexpiry => $a_month_later, |
284 |
categorycode => $patron_category->{categorycode}, |
279 |
categorycode => $patron_category->{categorycode}, |
285 |
} |
280 |
} |
286 |
} |
281 |
} |
287 |
); |
282 |
); |
288 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
283 |
my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
289 |
my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); |
284 |
my $retrieved_patron_2 = Koha::Patrons->find( $patron_2->{borrowernumber} ); |
290 |
my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); |
285 |
my $retrieved_patron_3 = Koha::Patrons->find( $patron_3->{borrowernumber} ); |
291 |
|
286 |
|
292 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); |
287 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' ); |
293 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
288 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
294 |
my $expiry_date = $retrieved_patron->renew_account; |
289 |
my $expiry_date = $retrieved_patron->renew_account; |
295 |
is( $expiry_date, $a_year_later_minus_a_month, ); |
290 |
is( $expiry_date, $a_year_later_minus_a_month, ); |
296 |
my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
291 |
my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
297 |
is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); |
292 |
is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month ); |
298 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
293 |
my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
299 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' ); |
294 |
is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->renew_account should have logged' ); |
300 |
|
295 |
|
301 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); |
296 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' ); |
302 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
297 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
303 |
$expiry_date = $retrieved_patron->renew_account; |
298 |
$expiry_date = $retrieved_patron->renew_account; |
304 |
is( $expiry_date, $a_year_later, ); |
299 |
is( $expiry_date, $a_year_later, ); |
305 |
$retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
300 |
$retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry; |
306 |
is( dt_from_string($retrieved_expiry_date), $a_year_later ); |
301 |
is( dt_from_string($retrieved_expiry_date), $a_year_later ); |
307 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
302 |
$number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count; |
308 |
is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); |
303 |
is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->renew_account should not have logged' ); |
309 |
|
304 |
|
310 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); |
305 |
t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'combination' ); |
311 |
$expiry_date = $retrieved_patron_2->renew_account; |
306 |
$expiry_date = $retrieved_patron_2->renew_account; |
312 |
is( $expiry_date, $a_year_later ); |
307 |
is( $expiry_date, $a_year_later ); |
313 |
$retrieved_expiry_date = Koha::Patrons->find( $patron_2->{borrowernumber} )->dateexpiry; |
308 |
$retrieved_expiry_date = Koha::Patrons->find( $patron_2->{borrowernumber} )->dateexpiry; |
314 |
is( dt_from_string($retrieved_expiry_date), $a_year_later ); |
309 |
is( dt_from_string($retrieved_expiry_date), $a_year_later ); |
315 |
|
310 |
|
316 |
$expiry_date = $retrieved_patron_3->renew_account; |
311 |
$expiry_date = $retrieved_patron_3->renew_account; |
317 |
is( $expiry_date, $a_year_later_plus_a_month ); |
312 |
is( $expiry_date, $a_year_later_plus_a_month ); |
318 |
$retrieved_expiry_date = Koha::Patrons->find( $patron_3->{borrowernumber} )->dateexpiry; |
313 |
$retrieved_expiry_date = Koha::Patrons->find( $patron_3->{borrowernumber} )->dateexpiry; |
319 |
is( dt_from_string($retrieved_expiry_date), $a_year_later_plus_a_month ); |
314 |
is( dt_from_string($retrieved_expiry_date), $a_year_later_plus_a_month ); |
320 |
|
315 |
|
321 |
$retrieved_patron->delete; |
316 |
$retrieved_patron->delete; |
322 |
$retrieved_patron_2->delete; |
317 |
$retrieved_patron_2->delete; |
323 |
$retrieved_patron_3->delete; |
318 |
$retrieved_patron_3->delete; |
324 |
} |
319 |
}; |
325 |
}; |
320 |
|
326 |
|
321 |
subtest "move_to_deleted" => sub { |
327 |
subtest "move_to_deleted" => sub { |
322 |
- |
|
|