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