Lines 373-379
subtest 'checkauth() tests' => sub {
Link Here
|
373 |
|
373 |
|
374 |
subtest 'track_login_daily tests' => sub { |
374 |
subtest 'track_login_daily tests' => sub { |
375 |
|
375 |
|
376 |
plan tests => 5; |
376 |
plan tests => 18; |
377 |
|
377 |
|
378 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
378 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
379 |
my $userid = $patron->userid; |
379 |
my $userid = $patron->userid; |
Lines 386-416
subtest 'track_login_daily tests' => sub {
Link Here
|
386 |
$cache->clear_from_cache($cache_key); |
386 |
$cache->clear_from_cache($cache_key); |
387 |
|
387 |
|
388 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
388 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
|
|
389 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
389 |
|
390 |
|
390 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
391 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
391 |
|
392 |
|
392 |
C4::Auth::track_login_daily( $userid ); |
393 |
C4::Auth::track_login_daily( $userid, 'login' ); |
393 |
$patron->_result()->discard_changes(); |
394 |
$patron->_result()->discard_changes(); |
394 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
395 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
395 |
|
396 |
|
396 |
sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different |
397 |
sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different |
397 |
my $last_seen = $patron->lastseen; |
398 |
my $last_seen = $patron->lastseen; |
398 |
C4::Auth::track_login_daily( $userid ); |
399 |
C4::Auth::track_login_daily( $userid, 'login' ); |
|
|
400 |
$patron->_result()->discard_changes(); |
401 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a login' ); |
402 |
C4::Auth::track_login_daily( $userid, 'connection' ); |
403 |
$patron->_result()->discard_changes(); |
404 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a SIP/ILSDI connection' ); |
405 |
C4::Auth::track_login_daily( $userid, 'check_out' ); |
406 |
$patron->_result()->discard_changes(); |
407 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check out' ); |
408 |
C4::Auth::track_login_daily( $userid, 'check_in' ); |
409 |
$patron->_result()->discard_changes(); |
410 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check in' ); |
411 |
C4::Auth::track_login_daily( $userid, 'renewal' ); |
412 |
$patron->_result()->discard_changes(); |
413 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' ); |
414 |
|
415 |
# Check that removing options stops tracking changes |
416 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'connection,check_in,check_out,renewal' ); |
417 |
$cache->clear_from_cache($cache_key); |
418 |
C4::Auth::track_login_daily( $userid, 'login' ); |
419 |
$patron->_result()->discard_changes(); |
420 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a login if login is not selected as an option and the cache has been cleared' ); |
421 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'check_in,check_out,renewal' ); |
422 |
$cache->clear_from_cache($cache_key); |
423 |
C4::Auth::track_login_daily( $userid, 'connection' ); |
424 |
$patron->_result()->discard_changes(); |
425 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a connection if connection is not selected as an option and the cache has been cleared' ); |
426 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'check_out,renewal' ); |
427 |
$cache->clear_from_cache($cache_key); |
428 |
C4::Auth::track_login_daily( $userid, 'check_in' ); |
429 |
$patron->_result()->discard_changes(); |
430 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a check_in if check_in is not selected as an option and the cache has been cleared' ); |
431 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'renewal' ); |
432 |
$cache->clear_from_cache($cache_key); |
433 |
C4::Auth::track_login_daily( $userid, 'check_out' ); |
434 |
$patron->_result()->discard_changes(); |
435 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a check_out if check_out is not selected as an option and the cache has been cleared' ); |
436 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
437 |
$cache->clear_from_cache($cache_key); |
438 |
C4::Auth::track_login_daily( $userid, 'renewal' ); |
399 |
$patron->_result()->discard_changes(); |
439 |
$patron->_result()->discard_changes(); |
400 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged' ); |
440 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged after a renewal if renewal is not selected as an option and the cache has been cleared' ); |
|
|
441 |
|
442 |
# Restore all options to test changes |
443 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
401 |
|
444 |
|
402 |
$cache->clear_from_cache($cache_key); |
445 |
$cache->clear_from_cache($cache_key); |
403 |
C4::Auth::track_login_daily( $userid ); |
446 |
C4::Auth::track_login_daily( $userid, 'login' ); |
404 |
$patron->_result()->discard_changes(); |
447 |
$patron->_result()->discard_changes(); |
405 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed if we cleared the cache' ); |
448 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); |
|
|
449 |
$cache->clear_from_cache($cache_key); |
450 |
C4::Auth::track_login_daily( $userid, 'connection' ); |
451 |
$patron->_result()->discard_changes(); |
452 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a connection if we cleared the cache' ); |
453 |
$cache->clear_from_cache($cache_key); |
454 |
C4::Auth::track_login_daily( $userid, 'check_out' ); |
455 |
$patron->_result()->discard_changes(); |
456 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_out if we cleared the cache' ); |
457 |
$cache->clear_from_cache($cache_key); |
458 |
C4::Auth::track_login_daily( $userid, 'check_in' ); |
459 |
$patron->_result()->discard_changes(); |
460 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_in if we cleared the cache' ); |
461 |
$cache->clear_from_cache($cache_key); |
462 |
C4::Auth::track_login_daily( $userid, 'renewal' ); |
463 |
$patron->_result()->discard_changes(); |
464 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
406 |
|
465 |
|
407 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
466 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
408 |
$patron->lastseen( undef )->store; |
467 |
$patron->lastseen( undef )->store; |
409 |
$cache->clear_from_cache($cache_key); |
468 |
$cache->clear_from_cache($cache_key); |
410 |
C4::Auth::track_login_daily( $userid ); |
469 |
C4::Auth::track_login_daily( $userid, 'login' ); |
411 |
$patron->_result()->discard_changes(); |
470 |
$patron->_result()->discard_changes(); |
412 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
471 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
413 |
|
|
|
414 |
}; |
472 |
}; |
415 |
|
473 |
|
416 |
subtest 'no_set_userenv parameter tests' => sub { |
474 |
subtest 'no_set_userenv parameter tests' => sub { |
417 |
- |
|
|