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 => 10; |
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 |
# Cache is set |
277 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
278 |
is ( $retrieved_patron->{has_overdues_cache}, 0, 'has_overdues cache has been set'); |
279 |
# Cache is used |
280 |
is( $retrieved_patron->has_overdues({ cache => 1}), 0, ); |
281 |
|
276 |
$issue->delete(); |
282 |
$issue->delete(); |
277 |
my $yesterday = DateTime->today(time_zone => C4::Context->tz())->add( days => -1 ); |
283 |
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(); |
284 |
$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 ); |
285 |
$retrieved_patron = Koha::Patrons->find( $new_patron_1->borrowernumber ); |
280 |
is( $retrieved_patron->has_overdues, 1, ); |
286 |
is( $retrieved_patron->has_overdues, 1, ); |
|
|
287 |
ok( !defined $retrieved_patron->{has_overdues_cache}, 'has_overdues cache has been invalidated' ); |
288 |
# Cache is set |
289 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
290 |
is ( $retrieved_patron->{has_overdues_cache}, 1, 'has_overdues cache has been set' ); |
291 |
# Cache is used |
292 |
is( $retrieved_patron->has_overdues({ cache => 1}), 1, ); |
293 |
|
281 |
$issue->delete(); |
294 |
$issue->delete(); |
282 |
}; |
295 |
}; |
283 |
|
296 |
|
284 |
subtest 'is_expired' => sub { |
297 |
subtest 'is_expired' => sub { |
285 |
plan tests => 4; |
298 |
plan tests => 13; |
286 |
my $patron = $builder->build({ source => 'Borrower' }); |
299 |
my $patron = $builder->build({ source => 'Borrower' }); |
287 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
300 |
$patron = Koha::Patrons->find( $patron->{borrowernumber} ); |
288 |
$patron->dateexpiry( undef )->store->discard_changes; |
301 |
$patron->dateexpiry( undef )->store->discard_changes; |
289 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is not set'); |
302 |
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; |
303 |
$patron->dateexpiry( dt_from_string )->store->discard_changes; |
291 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is today'); |
304 |
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; |
305 |
$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'); |
306 |
is( $patron->is_expired, 0, 'Patron should not be considered expired if dateexpiry is tomorrow' ); |
|
|
307 |
$patron->dateexpiry( dt_from_string->add( days => -1 ) )->store->discard_changes; |
308 |
is( $patron->is_expired, 1, 'Patron should be considered expired if dateexpiry is yesterday' ); |
309 |
|
310 |
# Test is_expired cache |
311 |
$patron->dateexpiry( undef )->store->discard_changes; |
312 |
# Set cache |
313 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, with caching enabled' ); |
314 |
is( $patron->{is_expired_cache}, 0, 'is_expired cache has been set'); |
315 |
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; |
316 |
$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'); |
317 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, cache has been invalidated' ); |
|
|
318 |
is( $patron->{is_expired_cache}, 1, 'is_expired cache has been set'); |
319 |
is( $patron->is_expired({ cache => 1 }), 1, 'Patron should be considered expired if dateexpiry is yesterday, on cache hit' ); |
320 |
$patron->set({ dateexpiry => undef })->store->discard_changes; |
321 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, cache has been invalidated' ); |
322 |
is( $patron->is_expired({ cache => 1 }), 0, 'Patron should not be considered expired if dateexpiry is not set, on cache hit' ); |
323 |
$patron->is_expired; |
324 |
ok( !defined $patron->{is_expired_cache}, 'Cache has been invalidated after calling is_expired without caching enabled' ); |
296 |
|
325 |
|
297 |
$patron->delete; |
326 |
$patron->delete; |
298 |
}; |
327 |
}; |
299 |
- |
|
|