Lines 1957-1973
subtest 'update_lastseen tests' => sub {
Link Here
|
1957 |
plan tests => 18; |
1957 |
plan tests => 18; |
1958 |
$schema->storage->txn_begin; |
1958 |
$schema->storage->txn_begin; |
1959 |
|
1959 |
|
1960 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1960 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1961 |
my $userid = $patron->userid; |
1961 |
my $userid = $patron->userid; |
1962 |
|
1962 |
|
1963 |
$patron->lastseen( undef ); |
1963 |
$patron->lastseen(undef); |
1964 |
$patron->store(); |
1964 |
$patron->store(); |
1965 |
|
1965 |
|
1966 |
my $cache = Koha::Caches->get_instance(); |
1966 |
my $cache = Koha::Caches->get_instance(); |
1967 |
my $cache_key = "track_login_" . $patron->userid; |
1967 |
my $cache_key = "track_login_" . $patron->userid; |
1968 |
$cache->clear_from_cache($cache_key); |
1968 |
$cache->clear_from_cache($cache_key); |
1969 |
|
1969 |
|
1970 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
1970 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); |
1971 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
1971 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
1972 |
|
1972 |
|
1973 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
1973 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
Lines 1975-2060
subtest 'update_lastseen tests' => sub {
Link Here
|
1975 |
my $now = dt_from_string(); |
1975 |
my $now = dt_from_string(); |
1976 |
Time::Fake->offset( $now->epoch ); |
1976 |
Time::Fake->offset( $now->epoch ); |
1977 |
|
1977 |
|
1978 |
$patron->update_lastseen( 'login' ); |
1978 |
$patron->update_lastseen('login'); |
1979 |
$patron->_result()->discard_changes(); |
1979 |
$patron->_result()->discard_changes(); |
1980 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
1980 |
isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); |
1981 |
my $last_seen = $patron->lastseen; |
1981 |
my $last_seen = $patron->lastseen; |
1982 |
|
1982 |
|
1983 |
Time::Fake->offset( $now->epoch + 5 ); |
1983 |
Time::Fake->offset( $now->epoch + 5 ); |
|
|
1984 |
|
1984 |
# Test that lastseen isn't updated more than once in a day (regardless of activity passed) |
1985 |
# Test that lastseen isn't updated more than once in a day (regardless of activity passed) |
1985 |
$patron->update_lastseen( 'login' ); |
1986 |
$patron->update_lastseen('login'); |
1986 |
$patron->_result()->discard_changes(); |
1987 |
$patron->_result()->discard_changes(); |
1987 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a login' ); |
1988 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a login' ); |
1988 |
$patron->update_lastseen( 'connection' ); |
1989 |
$patron->update_lastseen('connection'); |
1989 |
$patron->_result()->discard_changes(); |
1990 |
$patron->_result()->discard_changes(); |
1990 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a SIP/ILSDI connection' ); |
1991 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a SIP/ILSDI connection' ); |
1991 |
$patron->update_lastseen( 'check_out' ); |
1992 |
$patron->update_lastseen('check_out'); |
1992 |
$patron->_result()->discard_changes(); |
1993 |
$patron->_result()->discard_changes(); |
1993 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check out' ); |
1994 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check out' ); |
1994 |
$patron->update_lastseen( 'check_in' ); |
1995 |
$patron->update_lastseen('check_in'); |
1995 |
$patron->_result()->discard_changes(); |
1996 |
$patron->_result()->discard_changes(); |
1996 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check in' ); |
1997 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a check in' ); |
1997 |
$patron->update_lastseen( 'renewal' ); |
1998 |
$patron->update_lastseen('renewal'); |
1998 |
$patron->_result()->discard_changes(); |
1999 |
$patron->_result()->discard_changes(); |
1999 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' ); |
2000 |
is( $patron->lastseen, $last_seen, 'Patron last seen should still be unchanged after a renewal' ); |
2000 |
|
2001 |
|
2001 |
# Check that tracking is disabled when the activity isn't listed |
2002 |
# Check that tracking is disabled when the activity isn't listed |
2002 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
2003 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', '' ); |
2003 |
$cache->clear_from_cache($cache_key); # Rule out the more than once day prevention above |
2004 |
$cache->clear_from_cache($cache_key); # Rule out the more than once day prevention above |
2004 |
|
2005 |
|
2005 |
$patron->update_lastseen( 'login' ); |
2006 |
$patron->update_lastseen('login'); |
2006 |
$patron->_result()->discard_changes(); |
2007 |
$patron->_result()->discard_changes(); |
2007 |
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' ); |
2008 |
is( |
|
|
2009 |
$patron->lastseen, $last_seen, |
2010 |
'Patron last seen should be unchanged after a login if login is not selected as an option and the cache has been cleared' |
2011 |
); |
2008 |
|
2012 |
|
2009 |
$patron->update_lastseen( 'connection' ); |
2013 |
$patron->update_lastseen('connection'); |
2010 |
$patron->_result()->discard_changes(); |
2014 |
$patron->_result()->discard_changes(); |
2011 |
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' ); |
2015 |
is( |
|
|
2016 |
$patron->lastseen, $last_seen, |
2017 |
'Patron last seen should be unchanged after a connection if connection is not selected as an option and the cache has been cleared' |
2018 |
); |
2012 |
|
2019 |
|
2013 |
$patron->update_lastseen( 'check_in' ); |
2020 |
$patron->update_lastseen('check_in'); |
2014 |
$patron->_result()->discard_changes(); |
2021 |
$patron->_result()->discard_changes(); |
2015 |
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' ); |
2022 |
is( |
|
|
2023 |
$patron->lastseen, $last_seen, |
2024 |
'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' |
2025 |
); |
2016 |
|
2026 |
|
2017 |
$patron->update_lastseen( 'check_out' ); |
2027 |
$patron->update_lastseen('check_out'); |
2018 |
$patron->_result()->discard_changes(); |
2028 |
$patron->_result()->discard_changes(); |
2019 |
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' ); |
2029 |
is( |
|
|
2030 |
$patron->lastseen, $last_seen, |
2031 |
'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' |
2032 |
); |
2020 |
|
2033 |
|
2021 |
$patron->update_lastseen( 'renewal' ); |
2034 |
$patron->update_lastseen('renewal'); |
2022 |
$patron->_result()->discard_changes(); |
2035 |
$patron->_result()->discard_changes(); |
2023 |
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' ); |
2036 |
is( |
|
|
2037 |
$patron->lastseen, $last_seen, |
2038 |
'Patron last seen should be unchanged after a renewal if renewal is not selected as an option and the cache has been cleared' |
2039 |
); |
2024 |
|
2040 |
|
2025 |
# Check tracking for each activity |
2041 |
# Check tracking for each activity |
2026 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
2042 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivityTriggers', 'login,connection,check_in,check_out,renewal' ); |
2027 |
|
2043 |
|
2028 |
$cache->clear_from_cache($cache_key); |
2044 |
$cache->clear_from_cache($cache_key); |
2029 |
$patron->update_lastseen( 'login' ); |
2045 |
$patron->update_lastseen('login'); |
2030 |
$patron->_result()->discard_changes(); |
2046 |
$patron->_result()->discard_changes(); |
2031 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); |
2047 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a login if we cleared the cache' ); |
2032 |
|
2048 |
|
2033 |
$cache->clear_from_cache($cache_key); |
2049 |
$cache->clear_from_cache($cache_key); |
2034 |
$patron->update_lastseen( 'connection' ); |
2050 |
$patron->update_lastseen('connection'); |
2035 |
$patron->_result()->discard_changes(); |
2051 |
$patron->_result()->discard_changes(); |
2036 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a connection if we cleared the cache' ); |
2052 |
isnt( |
|
|
2053 |
$patron->lastseen, $last_seen, |
2054 |
'Patron last seen should be changed after a connection if we cleared the cache' |
2055 |
); |
2037 |
|
2056 |
|
2038 |
$cache->clear_from_cache($cache_key); |
2057 |
$cache->clear_from_cache($cache_key); |
2039 |
$patron->update_lastseen( 'check_out' ); |
2058 |
$patron->update_lastseen('check_out'); |
2040 |
$patron->_result()->discard_changes(); |
2059 |
$patron->_result()->discard_changes(); |
2041 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_out if we cleared the cache' ); |
2060 |
isnt( |
|
|
2061 |
$patron->lastseen, $last_seen, |
2062 |
'Patron last seen should be changed after a check_out if we cleared the cache' |
2063 |
); |
2042 |
|
2064 |
|
2043 |
$cache->clear_from_cache($cache_key); |
2065 |
$cache->clear_from_cache($cache_key); |
2044 |
$patron->update_lastseen( 'check_in' ); |
2066 |
$patron->update_lastseen('check_in'); |
2045 |
$patron->_result()->discard_changes(); |
2067 |
$patron->_result()->discard_changes(); |
2046 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a check_in if we cleared the cache' ); |
2068 |
isnt( |
|
|
2069 |
$patron->lastseen, $last_seen, |
2070 |
'Patron last seen should be changed after a check_in if we cleared the cache' |
2071 |
); |
2047 |
|
2072 |
|
2048 |
$cache->clear_from_cache($cache_key); |
2073 |
$cache->clear_from_cache($cache_key); |
2049 |
$patron->update_lastseen( 'renewal' ); |
2074 |
$patron->update_lastseen('renewal'); |
2050 |
$patron->_result()->discard_changes(); |
2075 |
$patron->_result()->discard_changes(); |
2051 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
2076 |
isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed after a renewal if we cleared the cache' ); |
2052 |
|
2077 |
|
2053 |
# Check that the preference takes effect |
2078 |
# Check that the preference takes effect |
2054 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
2079 |
t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); |
2055 |
$patron->lastseen( undef )->store; |
2080 |
$patron->lastseen(undef)->store; |
2056 |
$cache->clear_from_cache($cache_key); |
2081 |
$cache->clear_from_cache($cache_key); |
2057 |
$patron->update_lastseen( 'login' ); |
2082 |
$patron->update_lastseen('login'); |
2058 |
$patron->_result()->discard_changes(); |
2083 |
$patron->_result()->discard_changes(); |
2059 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
2084 |
is( $patron->lastseen, undef, 'Patron should still have last seen unchanged when TrackLastPatronActivity = 0' ); |
2060 |
|
2085 |
|
2061 |
- |
|
|