5 use Test
::More tests
=> 6;
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/ );
14 my $expected_recent_searches = [
17 'query_cgi' => 'idx=&q=history&branch_group_limit=',
19 'query_desc' => 'kw,wrdl: history, '
23 # Create new session and put its id into CGISESSID cookie
24 my $session = C4
::Auth
::get_session
("");
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');
43 package CookieSimulator
;
46 my ($class, $hashref) = @_;
48 return bless $val, $class;
52 my ($self, $name) = @_;
53 return $self->{$name};