Lines 303-342
subtest 'is_expired' => sub {
Link Here
|
303 |
}; |
303 |
}; |
304 |
|
304 |
|
305 |
subtest 'is_going_to_expire' => sub { |
305 |
subtest 'is_going_to_expire' => sub { |
306 |
plan tests => 8; |
306 |
plan tests => 9; |
|
|
307 |
|
308 |
my $today = dt_from_string(undef, undef, 'floating'); |
307 |
my $patron = $builder->build({ source => 'Borrower' }); |
309 |
my $patron = $builder->build({ source => 'Borrower' }); |
308 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
310 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
309 |
$patron->dateexpiry( undef )->store->discard_changes; |
311 |
$patron->dateexpiry( undef )->store->discard_changes; |
310 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
312 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
311 |
|
313 |
|
312 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
314 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
313 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
315 |
$patron->dateexpiry( $today )->store->discard_changes; |
314 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today'); |
316 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today'); |
315 |
|
317 |
|
316 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
318 |
$patron->dateexpiry( $today )->store->discard_changes; |
317 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
319 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
318 |
|
320 |
|
319 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
321 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
320 |
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes; |
322 |
$patron->dateexpiry( $today->clone->add( days => 11 ) )->store->discard_changes; |
321 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10'); |
323 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 11 days ahead and pref is 10'); |
322 |
|
324 |
|
323 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
325 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
324 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
326 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
325 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0'); |
327 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 0'); |
326 |
|
328 |
|
327 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
329 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
328 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
330 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
329 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10'); |
331 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 10 days ahead and pref is 10'); |
330 |
$patron->delete; |
332 |
$patron->delete; |
331 |
|
333 |
|
332 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
334 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
333 |
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes; |
335 |
$patron->dateexpiry( $today->clone->add( days => 20 ) )->store->discard_changes; |
334 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10'); |
336 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is 20 days ahead and pref is 10'); |
335 |
|
337 |
|
336 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
338 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
337 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
339 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
338 |
is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
340 |
is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
339 |
|
341 |
|
|
|
342 |
{ # Testing invalid is going to expiry date |
343 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 30); |
344 |
# mock_config does not work here, because of tz vs timezone subroutines |
345 |
my $context = new Test::MockModule('C4::Context'); |
346 |
$context->mock( 'tz', sub { |
347 |
'America/Sao_Paulo'; |
348 |
}); |
349 |
$patron->dateexpiry(DateTime->new( year => 2019, month => 12, day => 3 ))->store; |
350 |
eval { $patron->is_going_to_expire }; |
351 |
is( $@, '', 'On invalid "is going to expire" date, the method should not crash with "Invalid local time for date in time zone"'); |
352 |
$context->unmock('tz'); |
353 |
}; |
354 |
|
340 |
$patron->delete; |
355 |
$patron->delete; |
341 |
}; |
356 |
}; |
342 |
|
357 |
|
343 |
- |
|
|