Lines 2012-2038
subtest 'test patron_consent' => sub {
Link Here
|
2012 |
|
2012 |
|
2013 |
subtest 'update_lastseen tests' => sub { |
2013 |
subtest 'update_lastseen tests' => sub { |
2014 |
|
2014 |
|
2015 |
plan tests => 24; |
2015 |
plan tests => 26; |
2016 |
$schema->storage->txn_begin; |
2016 |
$schema->storage->txn_begin; |
2017 |
|
2017 |
|
|
|
2018 |
my $cache = Koha::Caches->get_instance(); |
2019 |
|
2020 |
t::lib::Mocks::mock_preference( |
2021 |
'TrackLastPatronActivityTriggers', |
2022 |
'creation,login,connection,check_in,check_out,renewal,hold,article' |
2023 |
); |
2024 |
|
2018 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2025 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2019 |
my $userid = $patron->userid; |
2026 |
my $userid = $patron->userid; |
2020 |
|
|
|
2021 |
$patron->lastseen(undef); |
2027 |
$patron->lastseen(undef); |
2022 |
$patron->store(); |
2028 |
my $patron_info = $patron->unblessed; |
|
|
2029 |
delete $patron_info->{borrowernumber}; |
2030 |
$patron->delete(); |
2031 |
$patron = Koha::Patron->new($patron_info)->store(); |
2023 |
|
2032 |
|
2024 |
my $cache = Koha::Caches->get_instance(); |
2033 |
my $now = dt_from_string(); |
2025 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
2034 |
my $today = $now->ymd(); |
2026 |
$cache->clear_from_cache($cache_key); |
2035 |
|
|
|
2036 |
is( |
2037 |
dt_from_string( $patron->lastseen )->ymd(), $today, |
2038 |
'Patron should have last seen when newly created if requested' |
2039 |
); |
2040 |
|
2041 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
2042 |
my $cache_value = $cache->get_from_cache($cache_key); |
2043 |
is( $cache_value, $today, "Cache was updated as expected" ); |
2044 |
|
2045 |
$patron->delete(); |
2027 |
|
2046 |
|
2028 |
t::lib::Mocks::mock_preference( |
2047 |
t::lib::Mocks::mock_preference( |
2029 |
'TrackLastPatronActivityTriggers', |
2048 |
'TrackLastPatronActivityTriggers', |
2030 |
'login,connection,check_in,check_out,renewal,hold,article' |
2049 |
'login,connection,check_in,check_out,renewal,hold,article' |
2031 |
); |
2050 |
); |
2032 |
|
2051 |
|
2033 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
2052 |
$patron = Koha::Patron->new($patron_info)->store(); |
|
|
2053 |
$cache_key = "track_activity_" . $patron->borrowernumber; |
2054 |
|
2055 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); |
2034 |
|
2056 |
|
2035 |
my $now = dt_from_string(); |
2057 |
$now = dt_from_string(); |
2036 |
Time::Fake->offset( $now->epoch ); |
2058 |
Time::Fake->offset( $now->epoch ); |
2037 |
|
2059 |
|
2038 |
$patron->update_lastseen('login'); |
2060 |
$patron->update_lastseen('login'); |
2039 |
- |
|
|