|
Lines 2-8
Link Here
|
| 2 |
|
2 |
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
|
4 |
|
| 5 |
use Test::More tests => 19; |
5 |
use Test::More tests => 25; |
| 6 |
use Test::Warn; |
6 |
use Test::Warn; |
| 7 |
use URI::Escape; |
7 |
use URI::Escape; |
| 8 |
use List::Util qw( shuffle ); |
8 |
use List::Util qw( shuffle ); |
|
Lines 150-160
$ids = [ shuffle map { $_->{id} } @$all ];
Link Here
|
| 150 |
C4::Search::History::delete({ id => [ @$ids[0..4] ] }); |
150 |
C4::Search::History::delete({ id => [ @$ids[0..4] ] }); |
| 151 |
$all = C4::Search::History::get({ userid => $userid }); |
151 |
$all = C4::Search::History::get({ userid => $userid }); |
| 152 |
is( scalar(@$all), 4, 'There are 4 searches after calling delete with 5 ids' ); |
152 |
is( scalar(@$all), 4, 'There are 4 searches after calling delete with 5 ids' ); |
|
|
153 |
|
| 154 |
delete_all( $userid ); |
| 155 |
|
| 156 |
# Test delete with interval |
| 157 |
add( $userid, $current_sessionid, $previous_sessionid, $total, $query_cgi_b, $query_cgi_a ); |
| 158 |
C4::Search::History::delete({ |
| 159 |
userid => $userid, |
| 160 |
interval => 10, |
| 161 |
}); |
| 162 |
$all = C4::Search::History::get({userid => $userid}); |
| 163 |
is( scalar(@$all), 9, 'There are still 9 searches after calling delete with an interval = 10 days' ); |
| 164 |
C4::Search::History::delete({ |
| 165 |
userid => $userid, |
| 166 |
interval => 6, |
| 167 |
}); |
| 168 |
$all = C4::Search::History::get({userid => $userid}); |
| 169 |
is( scalar(@$all), 8, 'There are still 8 searches after calling delete with an interval = 6 days' ); |
| 170 |
C4::Search::History::delete({ |
| 171 |
userid => $userid, |
| 172 |
interval => 2, |
| 173 |
}); |
| 174 |
$all = C4::Search::History::get({userid => $userid}); |
| 175 |
is( scalar(@$all), 2, 'There are still 2 searches after calling delete with an interval = 2 days' ); |
| 176 |
delete_all( $userid ); |
| 177 |
|
| 178 |
add( $userid, $current_sessionid, $previous_sessionid, $total, $query_cgi_b, $query_cgi_a ); |
| 179 |
C4::Search::History::delete({ |
| 180 |
userid => $userid, |
| 181 |
interval => 5, |
| 182 |
type => 'biblio', |
| 183 |
}); |
| 184 |
$all = C4::Search::History::get({userid => $userid}); |
| 185 |
is( scalar(@$all), 8, 'There are still 9 searches after calling delete with an interval = 5 days for biblio' ); |
| 186 |
C4::Search::History::delete({ |
| 187 |
userid => $userid, |
| 188 |
interval => 5, |
| 189 |
type => 'authority', |
| 190 |
}); |
| 191 |
$all = C4::Search::History::get({userid => $userid}); |
| 192 |
is( scalar(@$all), 6, 'There are still 6 searches after calling delete with an interval = 5 days for authority' ); |
| 193 |
C4::Search::History::delete({ |
| 194 |
userid => $userid, |
| 195 |
interval => -1, |
| 196 |
}); |
| 197 |
$all = C4::Search::History::get({userid => $userid}); |
| 198 |
is( scalar(@$all), 0, 'There is no search after calling delete with an interval = -1 days' ); |
| 199 |
|
| 153 |
delete_all( $userid ); |
200 |
delete_all( $userid ); |
| 154 |
|
201 |
|
| 155 |
sub add { |
202 |
sub add { |
| 156 |
my ( $userid, $current_session_id, $previous_sessionid, $total, $query_cgi_b, $query_cgi_a ) = @_; |
203 |
my ( $userid, $current_session_id, $previous_sessionid, $total, $query_cgi_b, $query_cgi_a ) = @_; |
| 157 |
|
204 |
|
|
|
205 |
my $days_ago_2 = dt_from_string()->add_duration( DateTime::Duration->new( days => -2 ) ); |
| 206 |
my $days_ago_4 = dt_from_string()->add_duration( DateTime::Duration->new( days => -4 ) ); |
| 207 |
my $days_ago_6 = dt_from_string()->add_duration( DateTime::Duration->new( days => -6 ) ); |
| 208 |
my $days_ago_8 = dt_from_string()->add_duration( DateTime::Duration->new( days => -8 ) ); |
| 209 |
|
| 158 |
my $query_desc_b1_p = q{first previous biblio search}; |
210 |
my $query_desc_b1_p = q{first previous biblio search}; |
| 159 |
my $first_previous_biblio_search = { |
211 |
my $first_previous_biblio_search = { |
| 160 |
userid => $userid, |
212 |
userid => $userid, |
|
Lines 163-168
sub add {
Link Here
|
| 163 |
query_cgi => $query_cgi_b, |
215 |
query_cgi => $query_cgi_b, |
| 164 |
total => $total, |
216 |
total => $total, |
| 165 |
type => 'biblio', |
217 |
type => 'biblio', |
|
|
218 |
time => $days_ago_2, |
| 166 |
}; |
219 |
}; |
| 167 |
|
220 |
|
| 168 |
my $query_desc_a1_p = q{first previous authority search}; |
221 |
my $query_desc_a1_p = q{first previous authority search}; |
|
Lines 173-178
sub add {
Link Here
|
| 173 |
query_cgi => $query_cgi_a, |
226 |
query_cgi => $query_cgi_a, |
| 174 |
total => $total, |
227 |
total => $total, |
| 175 |
type => 'authority', |
228 |
type => 'authority', |
|
|
229 |
time => $days_ago_2, |
| 176 |
}; |
230 |
}; |
| 177 |
|
231 |
|
| 178 |
my $query_desc_b2_p = q{second previous biblio search}; |
232 |
my $query_desc_b2_p = q{second previous biblio search}; |
|
Lines 183-188
sub add {
Link Here
|
| 183 |
query_cgi => $query_cgi_b, |
237 |
query_cgi => $query_cgi_b, |
| 184 |
total => $total, |
238 |
total => $total, |
| 185 |
type => 'biblio', |
239 |
type => 'biblio', |
|
|
240 |
time => $days_ago_4, |
| 186 |
}; |
241 |
}; |
| 187 |
|
242 |
|
| 188 |
my $query_desc_a2_p = q{second previous authority search}; |
243 |
my $query_desc_a2_p = q{second previous authority search}; |
|
Lines 193-198
sub add {
Link Here
|
| 193 |
query_cgi => $query_cgi_a, |
248 |
query_cgi => $query_cgi_a, |
| 194 |
total => $total, |
249 |
total => $total, |
| 195 |
type => 'authority', |
250 |
type => 'authority', |
|
|
251 |
time => $days_ago_4, |
| 196 |
}; |
252 |
}; |
| 197 |
|
253 |
|
| 198 |
|
254 |
|
|
Lines 205-210
sub add {
Link Here
|
| 205 |
query_cgi => $query_cgi_b, |
261 |
query_cgi => $query_cgi_b, |
| 206 |
total => $total, |
262 |
total => $total, |
| 207 |
type => 'biblio', |
263 |
type => 'biblio', |
|
|
264 |
time => $days_ago_4, |
| 208 |
}; |
265 |
}; |
| 209 |
|
266 |
|
| 210 |
my $query_desc_a1_c = q{first current authority search}; |
267 |
my $query_desc_a1_c = q{first current authority search}; |
|
Lines 215-220
sub add {
Link Here
|
| 215 |
query_cgi => $query_cgi_a, |
272 |
query_cgi => $query_cgi_a, |
| 216 |
total => $total, |
273 |
total => $total, |
| 217 |
type => 'authority', |
274 |
type => 'authority', |
|
|
275 |
time => $days_ago_4, |
| 218 |
}; |
276 |
}; |
| 219 |
|
277 |
|
| 220 |
my $query_desc_b2_c = q{second current biblio search}; |
278 |
my $query_desc_b2_c = q{second current biblio search}; |
|
Lines 225-230
sub add {
Link Here
|
| 225 |
query_cgi => $query_cgi_b, |
283 |
query_cgi => $query_cgi_b, |
| 226 |
total => $total, |
284 |
total => $total, |
| 227 |
type => 'biblio', |
285 |
type => 'biblio', |
|
|
286 |
time => $days_ago_6, |
| 228 |
}; |
287 |
}; |
| 229 |
|
288 |
|
| 230 |
my $query_desc_a2_c = q{second current authority search}; |
289 |
my $query_desc_a2_c = q{second current authority search}; |
|
Lines 235-240
sub add {
Link Here
|
| 235 |
query_cgi => $query_cgi_a, |
294 |
query_cgi => $query_cgi_a, |
| 236 |
total => $total, |
295 |
total => $total, |
| 237 |
type => 'authority', |
296 |
type => 'authority', |
|
|
297 |
time => $days_ago_6, |
| 238 |
}; |
298 |
}; |
| 239 |
|
299 |
|
| 240 |
my $query_desc_a3_c = q{third current authority search}; |
300 |
my $query_desc_a3_c = q{third current authority search}; |
|
Lines 245-250
sub add {
Link Here
|
| 245 |
query_cgi => $query_cgi_a, |
305 |
query_cgi => $query_cgi_a, |
| 246 |
total => $total, |
306 |
total => $total, |
| 247 |
type => 'authority', |
307 |
type => 'authority', |
|
|
308 |
time => $days_ago_8, |
| 248 |
}; |
309 |
}; |
| 249 |
|
310 |
|
| 250 |
|
311 |
|