View | Details | Raw Unified | Return to bug 15504
Collapse All | Expand All

(-)a/t/db_dependent/Auth.t (-9 / +66 lines)
Lines 417-423 subtest 'checkauth() tests' => sub { Link Here
417
417
418
subtest 'track_login_daily tests' => sub {
418
subtest 'track_login_daily tests' => sub {
419
419
420
    plan tests => 5;
420
    plan tests => 18;
421
421
422
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
422
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
423
    my $userid = $patron->userid;
423
    my $userid = $patron->userid;
Lines 430-460 subtest 'track_login_daily tests' => sub { Link Here
430
    $cache->clear_from_cache($cache_key);
430
    $cache->clear_from_cache($cache_key);
431
431
432
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
432
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' );
433
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' );
433
434
434
    is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' );
435
    is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' );
435
436
436
    C4::Auth::track_login_daily( $userid );
437
    C4::Auth::track_login_daily( $userid, 'login' );
437
    $patron->_result()->discard_changes();
438
    $patron->_result()->discard_changes();
438
    isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' );
439
    isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' );
439
440
440
    sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different
441
    sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different
441
    my $last_seen = $patron->lastseen;
442
    my $last_seen = $patron->lastseen;
442
    C4::Auth::track_login_daily( $userid );
443
    C4::Auth::track_login_daily( $userid, 'login' );
444
    $patron->_result()->discard_changes();
445
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a login' );
446
    C4::Auth::track_login_daily( $userid, 'connection' );
447
    $patron->_result()->discard_changes();
448
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a SIP/ILSDI connection' );
449
    C4::Auth::track_login_daily( $userid, 'check_out' );
450
    $patron->_result()->discard_changes();
451
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check out' );
452
    C4::Auth::track_login_daily( $userid, 'check_in' );
453
    $patron->_result()->discard_changes();
454
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check in' );
455
    C4::Auth::track_login_daily( $userid, 'renewal' );
456
    $patron->_result()->discard_changes();
457
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' );
458
459
    # Check that removing options stops tracking changes
460
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'connection,check_in,check_out,renewal' );
461
    $cache->clear_from_cache($cache_key);
462
    C4::Auth::track_login_daily( $userid, 'login' );
463
    $patron->_result()->discard_changes();
464
    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' );
465
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'check_in,check_out,renewal' );
466
    $cache->clear_from_cache($cache_key);
467
    C4::Auth::track_login_daily( $userid, 'connection' );
468
    $patron->_result()->discard_changes();
469
    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' );
470
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'check_out,renewal' );
471
    $cache->clear_from_cache($cache_key);
472
    C4::Auth::track_login_daily( $userid, 'check_in' );
473
    $patron->_result()->discard_changes();
474
    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' );
475
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'renewal' );
476
    $cache->clear_from_cache($cache_key);
477
    C4::Auth::track_login_daily( $userid, 'check_out' );
478
    $patron->_result()->discard_changes();
479
    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' );
480
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' );
481
    $cache->clear_from_cache($cache_key);
482
    C4::Auth::track_login_daily( $userid, 'renewal' );
443
    $patron->_result()->discard_changes();
483
    $patron->_result()->discard_changes();
444
    is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged' );
484
    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' );
485
486
    # Restore all options to test changes
487
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' );
445
488
446
    $cache->clear_from_cache($cache_key);
489
    $cache->clear_from_cache($cache_key);
447
    C4::Auth::track_login_daily( $userid );
490
    C4::Auth::track_login_daily( $userid, 'login' );
448
    $patron->_result()->discard_changes();
491
    $patron->_result()->discard_changes();
449
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed if we cleared the cache' );
492
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' );
493
    $cache->clear_from_cache($cache_key);
494
    C4::Auth::track_login_daily( $userid, 'connection' );
495
    $patron->_result()->discard_changes();
496
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a connection if we cleared the cache' );
497
    $cache->clear_from_cache($cache_key);
498
    C4::Auth::track_login_daily( $userid, 'check_out' );
499
    $patron->_result()->discard_changes();
500
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_out if we cleared the cache' );
501
    $cache->clear_from_cache($cache_key);
502
    C4::Auth::track_login_daily( $userid, 'check_in' );
503
    $patron->_result()->discard_changes();
504
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_in if we cleared the cache' );
505
    $cache->clear_from_cache($cache_key);
506
    C4::Auth::track_login_daily( $userid, 'renewal' );
507
    $patron->_result()->discard_changes();
508
    isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' );
450
509
451
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
510
    t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' );
452
    $patron->lastseen( undef )->store;
511
    $patron->lastseen( undef )->store;
453
    $cache->clear_from_cache($cache_key);
512
    $cache->clear_from_cache($cache_key);
454
    C4::Auth::track_login_daily( $userid );
513
    C4::Auth::track_login_daily( $userid, 'login' );
455
    $patron->_result()->discard_changes();
514
    $patron->_result()->discard_changes();
456
    is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' );
515
    is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' );
457
458
};
516
};
459
517
460
subtest 'no_set_userenv parameter tests' => sub {
518
subtest 'no_set_userenv parameter tests' => sub {
461
- 

Return to bug 15504