Lines 2129-2155
subtest 'test patron_consent' => sub {
Link Here
|
2129 |
|
2129 |
|
2130 |
subtest 'update_lastseen tests' => sub { |
2130 |
subtest 'update_lastseen tests' => sub { |
2131 |
|
2131 |
|
2132 |
plan tests => 24; |
2132 |
plan tests => 26; |
2133 |
$schema->storage->txn_begin; |
2133 |
$schema->storage->txn_begin; |
2134 |
|
2134 |
|
|
|
2135 |
my $cache = Koha::Caches->get_instance(); |
2136 |
|
2137 |
t::lib::Mocks::mock_preference( |
2138 |
'TrackLastPatronActivityTriggers', |
2139 |
'creation,login,connection,check_in,check_out,renewal,hold,article' |
2140 |
); |
2141 |
|
2135 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2142 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2136 |
my $userid = $patron->userid; |
2143 |
my $userid = $patron->userid; |
2137 |
|
|
|
2138 |
$patron->lastseen(undef); |
2144 |
$patron->lastseen(undef); |
2139 |
$patron->store(); |
2145 |
my $patron_info = $patron->unblessed; |
|
|
2146 |
delete $patron_info->{borrowernumber}; |
2147 |
$patron->delete(); |
2148 |
$patron = Koha::Patron->new($patron_info)->store(); |
2140 |
|
2149 |
|
2141 |
my $cache = Koha::Caches->get_instance(); |
2150 |
my $now = dt_from_string(); |
2142 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
2151 |
my $today = $now->ymd(); |
2143 |
$cache->clear_from_cache($cache_key); |
2152 |
|
|
|
2153 |
is( |
2154 |
dt_from_string( $patron->lastseen )->ymd(), $today, |
2155 |
'Patron should have last seen when newly created if requested' |
2156 |
); |
2157 |
|
2158 |
my $cache_key = "track_activity_" . $patron->borrowernumber; |
2159 |
my $cache_value = $cache->get_from_cache($cache_key); |
2160 |
is( $cache_value, $today, "Cache was updated as expected" ); |
2161 |
|
2162 |
$patron->delete(); |
2144 |
|
2163 |
|
2145 |
t::lib::Mocks::mock_preference( |
2164 |
t::lib::Mocks::mock_preference( |
2146 |
'TrackLastPatronActivityTriggers', |
2165 |
'TrackLastPatronActivityTriggers', |
2147 |
'login,connection,check_in,check_out,renewal,hold,article' |
2166 |
'login,connection,check_in,check_out,renewal,hold,article' |
2148 |
); |
2167 |
); |
2149 |
|
2168 |
|
2150 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); |
2169 |
$patron = Koha::Patron->new($patron_info)->store(); |
|
|
2170 |
$cache_key = "track_activity_" . $patron->borrowernumber; |
2171 |
|
2172 |
is( $patron->lastseen, undef, 'Patron should have not last seen when newly created if trigger not set' ); |
2151 |
|
2173 |
|
2152 |
my $now = dt_from_string(); |
2174 |
$now = dt_from_string(); |
2153 |
Time::Fake->offset( $now->epoch ); |
2175 |
Time::Fake->offset( $now->epoch ); |
2154 |
|
2176 |
|
2155 |
$patron->update_lastseen('login'); |
2177 |
$patron->update_lastseen('login'); |
2156 |
- |
|
|