Lines 77-114
subtest 'track_login_for_session() tests' => sub {
Link Here
|
77 |
$patron->lastseen( undef ); |
77 |
$patron->lastseen( undef ); |
78 |
$patron->store(); |
78 |
$patron->store(); |
79 |
|
79 |
|
80 |
# Mock a CGI object with real userid param |
80 |
my $cache = Koha::Caches->get_instance(); |
81 |
my $cgi = Test::MockObject->new(); |
81 |
my $cache_key = "seen-for-session-" . $patron->id; |
82 |
$cgi->mock( 'param', sub { return $patron; } ); |
82 |
$cache->clear_from_cache($cache_key); |
83 |
$cgi->mock( 'cookie', sub { return; } ); |
|
|
84 |
|
85 |
my $session = new CGI::Session( undef, undef, { Directory => File::Spec->tmpdir } ); |
86 |
|
83 |
|
87 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
84 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
88 |
|
85 |
|
89 |
C4::Auth::track_login_for_session( $userid ); |
86 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
90 |
$patron->_result()->discard_changes(); |
|
|
91 |
is( $patron->lastseen, undef, 'Patron last seen should be unchanged if no session is passed' ); |
92 |
|
87 |
|
93 |
C4::Auth::track_login_for_session( $userid, $session ); |
88 |
C4::Auth::track_login_for_session( $userid ); |
94 |
$patron->_result()->discard_changes(); |
89 |
$patron->_result()->discard_changes(); |
95 |
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' ); |
96 |
|
91 |
|
97 |
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 |
98 |
my $last_seen = $patron->lastseen; |
93 |
my $last_seen = $patron->lastseen; |
99 |
C4::Auth::track_login_for_session( $userid, $session ); |
94 |
C4::Auth::track_login_for_session( $userid ); |
100 |
$patron->_result()->discard_changes(); |
95 |
$patron->_result()->discard_changes(); |
101 |
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 be unchanged if passed the same session' ); |
102 |
|
97 |
|
103 |
$session = new CGI::Session( undef, undef, { Directory => File::Spec->tmpdir } ); |
98 |
$cache->clear_from_cache($cache_key); |
104 |
C4::Auth::track_login_for_session( $userid, $session ); |
99 |
C4::Auth::track_login_for_session( $userid ); |
105 |
$patron->_result()->discard_changes(); |
100 |
$patron->_result()->discard_changes(); |
106 |
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 given a new session' ); |
107 |
|
102 |
|
108 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
103 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
109 |
sleep(1); |
104 |
sleep(1); |
110 |
$last_seen = $patron->lastseen; |
105 |
$last_seen = $patron->lastseen; |
111 |
C4::Auth::track_login_for_session( $userid, $session ); |
106 |
C4::Auth::track_login_for_session( $userid ); |
112 |
$patron->_result()->discard_changes(); |
107 |
$patron->_result()->discard_changes(); |
113 |
is( $patron->lastseen, $last_seen, 'Patron should have last seen unchanged when TrackLastPatronActivity = 0' ); |
108 |
is( $patron->lastseen, $last_seen, 'Patron should have last seen unchanged when TrackLastPatronActivity = 0' ); |
114 |
|
109 |
|
115 |
- |
|
|