6 use Test::More tests => 3;
8 use_ok('C4::Auth', qw/ParseSearchHistoryCookie/);
10 my $valid_cookie = "%5B%7B%22time%22%3A1374978877%2C%22query_cgi%22%3A%22idx%3D%26q%3Dhistory%26branch_group_limit%3D%22%2C%22total%22%3A2%2C%22query_desc%22%3A%22kw%2Cwrdl%3A%20history%2C%20%22%7D%5D";
11 my $expected_recent_searches = [
14 'query_cgi' => 'idx=&q=history&branch_group_limit=',
16 'query_desc' => 'kw,wrdl: history, '
20 my $input = CookieSimulator->new($valid_cookie);
21 my @recent_searches = ParseSearchHistoryCookie($input);
22 is_deeply(\@recent_searches, $expected_recent_searches, 'parsed valid search history cookie value');
24 # simulate bit of a Storable-based search history cookie
25 my $invalid_cookie = "%04%08%0812345";
26 $input = CookieSimulator->new($invalid_cookie);
27 @recent_searches = ParseSearchHistoryCookie($input);
28 is_deeply(\@recent_searches, [], 'got back empty search history list if given invalid cookie');
30 package CookieSimulator;
33 my ($class, $str) = @_;
35 return bless $val, $class;