Lines 264-270
subtest 'siblings' => sub {
Link Here
|
264 |
}; |
264 |
}; |
265 |
|
265 |
|
266 |
subtest 'has_overdues' => sub { |
266 |
subtest 'has_overdues' => sub { |
267 |
plan tests => 3; |
267 |
plan tests => 12; |
268 |
|
268 |
|
269 |
my $item_1 = $builder->build_sample_item; |
269 |
my $item_1 = $builder->build_sample_item; |
270 |
my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
270 |
my $retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
Lines 273-298
subtest 'has_overdues' => sub {
Link Here
|
273 |
my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 ); |
273 |
my $tomorrow = DateTime->today( time_zone => C4::Context->tz() )->add( days => 1 ); |
274 |
my $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $tomorrow, branchcode => $library->{branchcode} })->store(); |
274 |
my $issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $tomorrow, branchcode => $library->{branchcode} })->store(); |
275 |
is( $retrieved_patron->has_overdues, 0, ); |
275 |
is( $retrieved_patron->has_overdues, 0, ); |
|
|
276 |
|
277 |
# Cache is set |
278 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
279 |
is( $retrieved_patron->_cache_get('has_overdues'), 0, 'has_overdues cache has been set'); |
280 |
# Cache is used |
281 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
282 |
|
276 |
$issue->delete(); |
283 |
$issue->delete(); |
277 |
my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); |
284 |
my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); |
278 |
$issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $yesterday, branchcode => $library->{branchcode} })->store(); |
285 |
$issue = Koha::Checkout->new({ borrowernumber => $new_patron_1->id, itemnumber => $item_1->itemnumber, date_due => $yesterday, branchcode => $library->{branchcode} })->store(); |
279 |
$retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
286 |
$retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
280 |
is( $retrieved_patron->has_overdues, 1, ); |
287 |
is( $retrieved_patron->has_overdues, 1, ); |
|
|
288 |
is( $retrieved_patron->_cache_get('has_overdues'),, undef, 'has_overdues cache has been invalidated' ); |
289 |
# Cache is set |
290 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
291 |
is ( $retrieved_patron->_cache_get('has_overdues'),, 1, 'has_overdues cache has been set' ); |
292 |
# Cache is used |
293 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
294 |
|
281 |
$issue->delete(); |
295 |
$issue->delete(); |
|
|
296 |
|
297 |
# Cache is used (with stale entry, flushing cache must be handled manually as automatic invalidation is |
298 |
# complex and probably not worth the effort) |
299 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
300 |
|
301 |
# Cache has been invalidated |
302 |
is( $retrieved_patron->has_overdues, 0, ); |
282 |
}; |
303 |
}; |
283 |
|
304 |
|
284 |
subtest 'is_expired' => sub { |
305 |
subtest 'is_expired' => sub { |
285 |
plan tests => 4; |
306 |
plan tests => 14; |
286 |
my $patron = $builder->build({ source => 'Borrower' }); |
307 |
my $patron = $builder->build({ source => 'Borrower' }); |
287 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
308 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
288 |
$patron->dateexpiry( undef )->store->discard_changes; |
309 |
$patron->dateexpiry( undef )->store->discard_changes; |
289 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set'); |
310 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set' ); |
290 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
311 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
291 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today'); |
312 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today' ); |
292 |
$patron->dateexpiry( dt_from_string->add( days => 1 ) )->store->discard_changes; |
313 |
$patron->dateexpiry( dt_from_string->add( days => 1 ) )->store->discard_changes; |
293 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is tomorrow'); |
314 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is tomorrow' ); |
294 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
315 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
295 |
is( $patron->is_expired, 1, 'Patron should be considered expired if dateexpiry is yesterday'); |
316 |
is( $patron->is_expired, 1, 'Patron should be considered expired if dateexpiry is yesterday' ); |
|
|
317 |
|
318 |
|
319 |
# Test is_expired cache |
320 |
$patron->dateexpiry( undef )->store->discard_changes; |
321 |
# Set cache |
322 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, with caching enabled' ); |
323 |
is( $patron->_cache_get('is_expired'), 0, 'is_expired cache has been set'); |
324 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, with caching enabled and cache hit' ); |
325 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
326 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, cache has been invalidated' ); |
327 |
is( $patron->_cache_get('is_expired'), 1, 'is_expired cache has been set'); |
328 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, on cache hit' ); |
329 |
|
330 |
$patron->{dateexpiry} = undef; |
331 |
# Checking cache is really utilized by setting dateexpiry property without using accessor method |
332 |
is( $patron->is_expired({ cache => 1 }), 1, 'Cache is used with stale value' ); |
333 |
|
334 |
$patron->set({ dateexpiry => undef })->store->discard_changes; |
335 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, cache has been invalidated' ); |
336 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, on cache hit' ); |
337 |
|
338 |
$patron->is_expired; |
339 |
is( $patron->_cache_get('is_expired'), undef , 'Cache has been invalidated after calling is_expired without caching enabled' ); |
296 |
|
340 |
|
297 |
$patron->delete; |
341 |
$patron->delete; |
298 |
}; |
342 |
}; |
299 |
- |
|
|