|
Lines 224-263
subtest 'is_expired' => sub {
Link Here
|
| 224 |
}; |
224 |
}; |
| 225 |
|
225 |
|
| 226 |
subtest 'is_going_to_expire' => sub { |
226 |
subtest 'is_going_to_expire' => sub { |
| 227 |
plan tests => 8; |
227 |
plan tests => 9; |
|
|
228 |
|
| 229 |
my $today = dt_from_string(undef, undef, 'floating'); |
| 228 |
my $patron = $builder->build({ source => 'Borrower' }); |
230 |
my $patron = $builder->build({ source => 'Borrower' }); |
| 229 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
231 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
| 230 |
$patron->dateexpiry( undef )->store->discard_changes; |
232 |
$patron->dateexpiry( undef )->store->discard_changes; |
| 231 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
233 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is not set'); |
| 232 |
|
234 |
|
| 233 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
235 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
| 234 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
236 |
$patron->dateexpiry( $today )->store->discard_changes; |
| 235 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today'); |
237 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today'); |
| 236 |
|
238 |
|
| 237 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
239 |
$patron->dateexpiry( $today )->store->discard_changes; |
| 238 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
240 |
is( $patron->is_going_to_expire, 0, 'Patron should not be considered going to expire if dateexpiry is today and pref is 0'); |
| 239 |
|
241 |
|
| 240 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
242 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
| 241 |
$patron->dateexpiry( dt_from_string->add( days => 11 ) )->store->discard_changes; |
243 |
$patron->dateexpiry( $today->clone->add( days => 11 ) )->store->discard_changes; |
| 242 |
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'); |
244 |
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'); |
| 243 |
|
245 |
|
| 244 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
246 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 0); |
| 245 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
247 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
| 246 |
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'); |
248 |
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'); |
| 247 |
|
249 |
|
| 248 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
250 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
| 249 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
251 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
| 250 |
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'); |
252 |
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'); |
| 251 |
$patron->delete; |
253 |
$patron->delete; |
| 252 |
|
254 |
|
| 253 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
255 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 10); |
| 254 |
$patron->dateexpiry( dt_from_string->add( days => 20 ) )->store->discard_changes; |
256 |
$patron->dateexpiry( $today->clone->add( days => 20 ) )->store->discard_changes; |
| 255 |
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'); |
257 |
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'); |
| 256 |
|
258 |
|
| 257 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
259 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 20); |
| 258 |
$patron->dateexpiry( dt_from_string->add( days => 10 ) )->store->discard_changes; |
260 |
$patron->dateexpiry( $today->clone->add( days => 10 ) )->store->discard_changes; |
| 259 |
is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
261 |
is( $patron->is_going_to_expire, 1, 'Patron should be considered going to expire if dateexpiry is 10 days ahead and pref is 20'); |
| 260 |
|
262 |
|
|
|
263 |
{ # Testing invalid is going to expiry date |
| 264 |
t::lib::Mocks::mock_preference('NotifyBorrowerDeparture', 30); |
| 265 |
# mock_config does not work here, because of tz vs timezone subroutines |
| 266 |
my $context = new Test::MockModule('C4::Context'); |
| 267 |
$context->mock( 'tz', sub { |
| 268 |
'America/Sao_Paulo'; |
| 269 |
}); |
| 270 |
$patron->dateexpiry(DateTime->new( year => 2019, month => 12, day => 3 ))->store; |
| 271 |
eval { $patron->is_going_to_expire }; |
| 272 |
is( $@, 'On invalid "is going to expire" date, the method should not crash with "Invalid local time for date in time zone"'); |
| 273 |
$context->unmock('tz'); |
| 274 |
}; |
| 275 |
|
| 261 |
$patron->delete; |
276 |
$patron->delete; |
| 262 |
}; |
277 |
}; |
| 263 |
|
278 |
|
| 264 |
- |
|
|