|
Lines 1975-2001
subtest 'test patron_consent' => sub {
Link Here
|
| 1975 |
|
1975 |
|
| 1976 |
subtest 'update_lastseen tests' => sub { |
1976 |
subtest 'update_lastseen tests' => sub { |
| 1977 |
|
1977 |
|
| 1978 |
plan tests => 24; |
1978 |
plan tests => 26; |
| 1979 |
$schema->storage->txn_begin; |
1979 |
$schema->storage->txn_begin; |
| 1980 |
|
1980 |
|
|
|
1981 |
my $cache = Koha::Caches->get_instance(); |
| 1982 |
|
| 1983 |
t::lib::Mocks::mock_preference( |
| 1984 |
'TrackLastPatronActivityTriggers', |
| 1985 |
'creation,login,connection,check_in,check_out,renewal,hold,article' |
| 1986 |
); |
| 1987 |
|
| 1981 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
1988 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1982 |
my $userid = $patron->userid; |
1989 |
my $userid = $patron->userid; |
| 1983 |
|
|
|
| 1984 |
$patron->lastseen(undef); |
1990 |
$patron->lastseen(undef); |
| 1985 |
$patron->store(); |
1991 |
my $patron_info = $patron->unblessed; |
|
|
1992 |
delete $patron_info->{borrowernumber}; |
| 1993 |
$patron->delete(); |
| 1994 |
$patron = Koha::Patron->new($patron_info)->store(); |
| 1986 |
|
1995 |
|
| 1987 |
my $cache = Koha::Caches->get_instance(); |
1996 |
my $now = dt_from_string(); |
| 1988 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
1997 |
my $today = $now->ymd(); |
| 1989 |
$cache->clear_from_cache($cache_key); |
1998 |
|
|
|
1999 |
is( |
| 2000 |
dt_from_string( $patron->lastseen )->ymd(), $today, |
| 2001 |
'Patron should have last seen when newly created if requested' |
| 2002 |
); |
| 2003 |
|
| 2004 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
| 2005 |
my $cache_value = $cache->get_from_cache($cache_key); |
| 2006 |
is( $cache_value, $today, "Cache was updated as expected" ); |
| 2007 |
|
| 2008 |
$patron->delete(); |
| 1990 |
|
2009 |
|
| 1991 |
t::lib::Mocks::mock_preference( |
2010 |
t::lib::Mocks::mock_preference( |
| 1992 |
'TrackLastPatronActivityTriggers', |
2011 |
'TrackLastPatronActivityTriggers', |
| 1993 |
'login,connection,check_in,check_out,renewal,hold,article' |
2012 |
'login,connection,check_in,check_out,renewal,hold,article' |
| 1994 |
); |
2013 |
); |
| 1995 |
|
2014 |
|
| 1996 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
2015 |
$patron = Koha::Patron->new($patron_info)->store(); |
|
|
2016 |
$cache_key = "track_activity_" . $patron->borrowernumber; |
| 2017 |
|
| 2018 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); |
| 1997 |
|
2019 |
|
| 1998 |
my $now = dt_from_string(); |
2020 |
$now = dt_from_string(); |
| 1999 |
Time::Fake->offset( $now->epoch ); |
2021 |
Time::Fake->offset( $now->epoch ); |
| 2000 |
|
2022 |
|
| 2001 |
$patron->update_lastseen('login'); |
2023 |
$patron->update_lastseen('login'); |
| 2002 |
- |
|
|