Bug 11635: remove duplicate definition of 995$r in UNIMARC record.abs
[koha.git] / t / db_dependent / Auth_SearchHistorySession.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 4;
7
8 use_ok('C4::Auth', qw/ParseSearchHistorySession SetSearchHistorySession get_session/);
9
10 my $expected_recent_searches = [
11     {
12         'time' => 1374978877,
13         'query_cgi' => 'idx=&q=history&branch_group_limit=',
14         'total' => 2,
15         'query_desc' => 'kw,wrdl: history, '
16     }
17 ];
18
19 # Create new session and put its id into CGISESSID cookie
20 my $session = get_session("");
21 $session->flush;
22 my $input = new CookieSimulator({CGISESSID => $session->id});
23
24 my @recent_searches = ParseSearchHistorySession($input);
25 is_deeply(\@recent_searches, [], 'at start, there is no recent searches');
26
27 SetSearchHistorySession($input, $expected_recent_searches);
28 @recent_searches = ParseSearchHistorySession($input);
29 is_deeply(\@recent_searches, $expected_recent_searches, 'recent searches set and retrieved successfully');
30
31 SetSearchHistorySession($input, []);
32 @recent_searches = ParseSearchHistorySession($input);
33 is_deeply(\@recent_searches, [], 'recent searches emptied successfully');
34
35 # Delete session
36 $session->delete;
37 $session->flush;
38
39 package CookieSimulator;
40
41 sub new {
42     my ($class, $hashref) = @_;
43     my $val = $hashref;
44     return bless $val, $class;
45 }
46
47 sub cookie {
48     my ($self, $name) = @_;
49     return $self->{$name};
50 }
51
52 1;