Lines 67-73
subtest 'checkauth() tests' => sub {
Link Here
|
67 |
|
67 |
|
68 |
}; |
68 |
}; |
69 |
|
69 |
|
70 |
subtest 'track_login_for_session() tests' => sub { |
70 |
subtest 'track_login_daily tests' => sub { |
71 |
|
71 |
|
72 |
plan tests => 5; |
72 |
plan tests => 5; |
73 |
|
73 |
|
Lines 78-111
subtest 'track_login_for_session() tests' => sub {
Link Here
|
78 |
$patron->store(); |
78 |
$patron->store(); |
79 |
|
79 |
|
80 |
my $cache = Koha::Caches->get_instance(); |
80 |
my $cache = Koha::Caches->get_instance(); |
81 |
my $cache_key = "seen-for-session-" . $patron->id; |
81 |
my $cache_key = "track_login_" . $patron->userid; |
82 |
$cache->clear_from_cache($cache_key); |
82 |
$cache->clear_from_cache($cache_key); |
83 |
|
83 |
|
84 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
84 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
85 |
|
85 |
|
86 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
86 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
87 |
|
87 |
|
88 |
C4::Auth::track_login_for_session( $userid ); |
88 |
C4::Auth::track_login_daily( $userid ); |
89 |
$patron->_result()->discard_changes(); |
89 |
$patron->_result()->discard_changes(); |
90 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
90 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
91 |
|
91 |
|
92 |
sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different |
92 |
sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different |
93 |
my $last_seen = $patron->lastseen; |
93 |
my $last_seen = $patron->lastseen; |
94 |
C4::Auth::track_login_for_session( $userid ); |
94 |
C4::Auth::track_login_daily( $userid ); |
95 |
$patron->_result()->discard_changes(); |
95 |
$patron->_result()->discard_changes(); |
96 |
is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged if passed the same session' ); |
96 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged' ); |
97 |
|
97 |
|
98 |
$cache->clear_from_cache($cache_key); |
98 |
$cache->clear_from_cache($cache_key); |
99 |
C4::Auth::track_login_for_session( $userid ); |
99 |
C4::Auth::track_login_daily( $userid ); |
100 |
$patron->_result()->discard_changes(); |
100 |
$patron->_result()->discard_changes(); |
101 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed if given a new session' ); |
101 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed if we cleared the cache' ); |
102 |
|
102 |
|
103 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
103 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
104 |
sleep(1); |
104 |
$patron->lastseen( undef )->store; |
105 |
$last_seen = $patron->lastseen; |
105 |
$cache->clear_from_cache($cache_key); |
106 |
C4::Auth::track_login_for_session( $userid ); |
106 |
C4::Auth::track_login_daily( $userid ); |
107 |
$patron->_result()->discard_changes(); |
107 |
$patron->_result()->discard_changes(); |
108 |
is( $patron->lastseen, $last_seen, 'Patron should have last seen unchanged when TrackLastPatronActivity = 0' ); |
108 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
109 |
|
109 |
|
110 |
}; |
110 |
}; |
111 |
|
111 |
|
112 |
- |
|
|