Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 26; |
22 |
use Test::More tests => 27; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::Warn; |
24 |
use Test::Warn; |
25 |
|
25 |
|
Lines 318-323
subtest 'Accessor tests' => sub {
Link Here
|
318 |
is( $patron->smsalertnumber, '0683027347', 'smsalertnumber field set ok' ); |
318 |
is( $patron->smsalertnumber, '0683027347', 'smsalertnumber field set ok' ); |
319 |
is( $patron->privacy, '667789', 'privacy field set ok' ); |
319 |
is( $patron->privacy, '667789', 'privacy field set ok' ); |
320 |
}; |
320 |
}; |
|
|
321 |
}; |
322 |
|
323 |
subtest 'is_active' => sub { |
324 |
plan tests => 19; |
325 |
$schema->storage->txn_begin; |
326 |
|
327 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
328 |
throws_ok { $patron->is_active } 'Koha::Exceptions::MissingParameter', 'Called without params'; |
329 |
|
330 |
# Check expiry |
331 |
$patron->dateexpiry( dt_from_string->subtract( days => 1 ) )->store; |
332 |
is( $patron->is_active( { days => 1 } ), 0, 'Expired patron is not active' ); |
333 |
$patron->dateexpiry(undef)->store; |
334 |
is( $patron->is_active( { days => 1 } ), 1, 'Expiry date removed' ); |
335 |
|
336 |
# Change enrolled date now |
337 |
$patron->dateenrolled('2020-01-01')->store; |
338 |
|
339 |
# Check lastseen, test days parameter |
340 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); |
341 |
$patron->track_login; |
342 |
is( $patron->is_active( { days => 1 } ), 1, 'Just logged in' ); |
343 |
my $ago = dt_from_string->subtract( days => 2 ); |
344 |
$patron->lastseen($ago)->store; |
345 |
is( $patron->is_active( { days => 1 } ), 0, 'Not active since yesterday' ); |
346 |
is( $patron->is_active( { days => 3 } ), 1, 'Active within last 3 days' ); |
347 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 0 ); |
348 |
is( $patron->is_active( { days => 3 } ), 0, 'Pref disabled' ); |
349 |
|
350 |
# Look at holds, test with weeks |
351 |
$ago = dt_from_string->subtract( weeks => 2 ); |
352 |
my $hold = $builder->build_object( |
353 |
{ |
354 |
class => 'Koha::Holds', |
355 |
value => { borrowernumber => $patron->id, timestamp => $ago }, |
356 |
} |
357 |
); |
358 |
is( $patron->is_active( { weeks => 1 } ), 0, 'No holds in 1 weeks' ); |
359 |
is( $patron->is_active( { weeks => 3 } ), 1, 'Hold in last 3 weeks' ); |
360 |
$hold->delete; |
361 |
my $old_hold = $builder->build_object( |
362 |
{ |
363 |
class => 'Koha::Old::Holds', |
364 |
value => { borrowernumber => $patron->id, timestamp => $ago }, |
365 |
} |
366 |
); |
367 |
is( $patron->is_active( { weeks => 1 } ), 0, 'No old holds in 1 weeks' ); |
368 |
is( $patron->is_active( { weeks => 3 } ), 1, 'Old hold in last 3 weeks' ); |
369 |
$old_hold->delete; |
370 |
|
371 |
# Look at checkouts, test with months |
372 |
$ago = dt_from_string->subtract( months => 2 ); |
373 |
my $checkout = $builder->build_object( |
374 |
{ |
375 |
class => 'Koha::Checkouts', |
376 |
value => { borrowernumber => $patron->id, timestamp => $ago }, |
377 |
} |
378 |
); |
379 |
is( $patron->is_active( { months => 1 } ), 0, 'No checkouts in 1 months' ); |
380 |
is( $patron->is_active( { months => 3 } ), 1, 'Checkout in last 3 months' ); |
381 |
$checkout->delete; |
382 |
my $old_checkout = $builder->build_object( |
383 |
{ |
384 |
class => 'Koha::Old::Checkouts', |
385 |
value => { borrowernumber => $patron->id, timestamp => $ago }, |
386 |
} |
387 |
); |
388 |
is( $patron->is_active( { months => 1 } ), 0, 'No old checkouts in 1 months' ); |
389 |
is( $patron->is_active( { months => 3 } ), 1, 'Old checkout in last 3 months' ); |
390 |
$old_checkout->delete; |
391 |
|
392 |
# Look at article_requests, test with since |
393 |
$ago = dt_from_string->subtract( days => 10 ); |
394 |
my $article_request = $builder->build_object( |
395 |
{ |
396 |
class => 'Koha::ArticleRequests', |
397 |
value => { borrowernumber => $patron->id, updated_on => $ago }, |
398 |
} |
399 |
); |
400 |
is( $patron->is_active( { days => 9 } ), 0, 'No article requests in 9 days' ); |
401 |
is( $patron->is_active( { days => 10 } ), 1, 'Article requests in 10 days' ); |
402 |
is( $patron->is_active( { since => $ago } ), 1, 'Article requests since ago' ); |
403 |
is( $patron->is_active( { since => $ago->add( days => 1 ) } ), 0, 'No article requests since ago + 1 day' ); |
404 |
$article_request->delete; |
321 |
|
405 |
|
322 |
$schema->storage->txn_rollback; |
406 |
$schema->storage->txn_rollback; |
323 |
}; |
407 |
}; |
324 |
- |
|
|