Lines 25-30
use Test::Exception;
Link Here
|
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
use Time::Fake; |
26 |
use Time::Fake; |
27 |
use DateTime; |
27 |
use DateTime; |
|
|
28 |
use DateTime::TimeZone; |
28 |
use JSON; |
29 |
use JSON; |
29 |
use utf8; |
30 |
use utf8; |
30 |
|
31 |
|
Lines 299-305
subtest 'is_expired' => sub {
Link Here
|
299 |
}; |
300 |
}; |
300 |
|
301 |
|
301 |
subtest 'is_going_to_expire' => sub { |
302 |
subtest 'is_going_to_expire' => sub { |
302 |
plan tests => 9; |
303 |
my @tzones = DateTime::TimeZone->all_names; |
|
|
304 |
plan tests => 8 + scalar @tzones; |
303 |
|
305 |
|
304 |
my $today = dt_from_string(undef, undef, 'floating'); |
306 |
my $today = dt_from_string(undef, undef, 'floating'); |
305 |
my $patron = $builder->build({ source => 'Borrower' }); |
307 |
my $patron = $builder->build({ source => 'Borrower' }); |
Lines 335-353
subtest 'is_going_to_expire' => sub {
Link Here
|
335 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
337 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
336 |
is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
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'); |
337 |
|
339 |
|
|
|
340 |
foreach my $tz (@tzones) { |
338 |
{ # Testing invalid is going to expiry date |
341 |
{ # Testing invalid is going to expiry date |
339 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 30); |
342 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 30); |
340 |
# mock_config does not work here, because of tz vs timezone subroutines |
343 |
# mock_config does not work here, because of tz vs timezone subroutines |
341 |
my $context = Test::MockModule->new('C4::Context'); |
344 |
my $context = Test::MockModule->new('C4::Context'); |
342 |
$context->mock( 'tz', sub { |
345 |
$context->mock( 'tz', sub { |
343 |
'America/Sao_Paulo'; |
346 |
$tz; |
344 |
}); |
347 |
}); |
345 |
$patron->dateexpiry(DateTime->new( year => 2019, month => 12, day => 3 ))->store; |
348 |
$patron->dateexpiry(DateTime->new( year => 2019, month => 12, day => 3 ))->store; |
346 |
eval { $patron->is_going_to_expire }; |
349 |
eval { $patron->is_going_to_expire }; |
347 |
is( $@, '', 'On invalid "is going to expire" date, the method should not crash with "Invalid local time for date in time zone"'); |
350 |
is( $@, '', 'On invalid "is going to expire" date, the method should not crash: '.$tz ); |
348 |
$context->unmock('tz'); |
351 |
$context->unmock('tz'); |
349 |
}; |
352 |
}; |
350 |
|
353 |
} |
351 |
$patron->delete; |
354 |
$patron->delete; |
352 |
}; |
355 |
}; |
353 |
|
356 |
|
354 |
- |
|
|