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 |
my $cache_key = 'Patron_has_overdues:' . $retrieved_patron->borrowernumber; |
278 |
my $cache = Koha::Cache::Memory::Lite->get_instance; |
279 |
|
280 |
# Cache is set |
281 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
282 |
is ( $cache->get_from_cache($cache_key), 0, 'has_overdues cache has been set'); |
283 |
# Cache is used |
284 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
285 |
|
276 |
$issue->delete(); |
286 |
$issue->delete(); |
277 |
my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); |
287 |
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(); |
288 |
$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 ); |
289 |
$retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
280 |
is( $retrieved_patron->has_overdues, 1, ); |
290 |
is( $retrieved_patron->has_overdues, 1, ); |
|
|
291 |
is( $cache->get_from_cache($cache_key), undef, 'has_overdues cache has been invalidated' ); |
292 |
# Cache is set |
293 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
294 |
is ( $cache->get_from_cache($cache_key), 1, 'has_overdues cache has been set' ); |
295 |
# Cache is used |
296 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
297 |
|
281 |
$issue->delete(); |
298 |
$issue->delete(); |
|
|
299 |
|
300 |
# Cache is used (with stale entry, flushing cache must be handled manually as automatic invalidation is |
301 |
# complex and probably not worth the effort) |
302 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
303 |
|
304 |
# Cache has been invalidated |
305 |
is( $retrieved_patron->has_overdues, 0, ); |
282 |
}; |
306 |
}; |
283 |
|
307 |
|
284 |
subtest 'is_expired' => sub { |
308 |
subtest 'is_expired' => sub { |
285 |
plan tests => 4; |
309 |
plan tests => 14; |
286 |
my $patron = $builder->build({ source => 'Borrower' }); |
310 |
my $patron = $builder->build({ source => 'Borrower' }); |
287 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
311 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
288 |
$patron->dateexpiry( undef )->store->discard_changes; |
312 |
$patron->dateexpiry( undef )->store->discard_changes; |
289 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set'); |
313 |
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; |
314 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
291 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today'); |
315 |
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; |
316 |
$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'); |
317 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is tomorrow' ); |
|
|
318 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
319 |
is( $patron->is_expired, 1, 'Patron should be considered expired if dateexpiry is yesterday' ); |
320 |
|
321 |
|
322 |
my $cache_key = 'Patron_is_expired:' . $patron->borrowernumber; |
323 |
my $cache = Koha::Cache::Memory::Lite->get_instance; |
324 |
# Test is_expired cache |
325 |
$patron->dateexpiry( undef )->store->discard_changes; |
326 |
# Set cache |
327 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, with caching enabled' ); |
328 |
is( $cache->get_from_cache($cache_key), 0, 'is_expired cache has been set'); |
329 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, with caching enabled and cache hit' ); |
294 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
330 |
$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'); |
331 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, cache has been invalidated' ); |
|
|
332 |
is( $cache->get_from_cache($cache_key), 1, 'is_expired cache has been set'); |
333 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, on cache hit' ); |
334 |
|
335 |
$patron->{dateexpiry} = undef; |
336 |
# Checking cache is really utilized by setting dateexpiry property without using accessor method |
337 |
is( $patron->is_expired({ cache => 1 }), 1, 'Cache is used with stale value' ); |
338 |
|
339 |
$patron->set({ dateexpiry => undef })->store->discard_changes; |
340 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, cache has been invalidated' ); |
341 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, on cache hit' ); |
342 |
|
343 |
$patron->is_expired; |
344 |
is( $cache->get_from_cache($cache_key), undef , 'Cache has been invalidated after calling is_expired without caching enabled' ); |
296 |
|
345 |
|
297 |
$patron->delete; |
346 |
$patron->delete; |
298 |
}; |
347 |
}; |
299 |
- |
|
|