Bug 18624: (followup) opac-authorities-home.tt uses 'any'
[koha.git] / t / Search / History.t
blob2808e44149994346ef9f30401d6b41de73ecbf75
1 #!/usr/bin/env perl
3 use Modern::Perl;
5 use Test::More tests => 6;
6 use URI::Escape;
7 use JSON qw( decode_json );
9 use_ok('Koha::DateUtils');
10 use_ok('C4::Search::History');
11 use_ok('C4::Auth', qw/get_session/ );
13 # Test session
14 my $expected_recent_searches = [
16 'time' => 1374978877,
17 'query_cgi' => 'idx=&q=history&branch_group_limit=',
18 'total' => 2,
19 'query_desc' => 'kw,wrdl: history, '
23 # Create new session and put its id into CGISESSID cookie
24 my $session = C4::Auth::get_session("");
25 $session->flush;
26 my $input = new CookieSimulator({CGISESSID => $session->id});
28 my @recent_searches = C4::Search::History::get_from_session({ cgi => $input });
29 is_deeply(\@recent_searches, [], 'at start, there is no recent searches');
31 C4::Search::History::set_to_session({ cgi => $input, search_history => $expected_recent_searches });
32 @recent_searches = C4::Search::History::get_from_session({ cgi => $input });
33 is_deeply(\@recent_searches, $expected_recent_searches, 'recent searches set and retrieved successfully');
35 C4::Search::History::set_to_session({ cgi => $input, search_history => [] });
36 @recent_searches = C4::Search::History::get_from_session({ cgi => $input });
37 is_deeply(\@recent_searches, [], 'recent searches emptied successfully');
39 # Delete session
40 $session->delete;
41 $session->flush;
43 package CookieSimulator;
45 sub new {
46 my ($class, $hashref) = @_;
47 my $val = $hashref;
48 return bless $val, $class;
51 sub cookie {
52 my ($self, $name) = @_;
53 return $self->{$name};