Koha/t/db_dependent/Auth_SearchHistorySession.t
Julian Maurice bbf7cd6876 Bug 10952: (follow-up) comments fixes and unit tests
- Remove unit tests for ParseSearchHistoryCookie, which doesn't exist
  anymore
- Add unit tests for ParseSearchHistorySession and
  SetSearchHistorySession
- Remove/Modify comments about search history cookie

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Tests fixed and moved, and comments tidied up

Signed-off-by: Charlene Criton <charlene.criton@univ-lyon2.fr>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
2014-01-10 16:21:18 +00:00

52 lines
1.3 KiB
Perl

#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 4;
use_ok('C4::Auth', qw/ParseSearchHistorySession SetSearchHistorySession get_session/);
my $expected_recent_searches = [
{
'time' => 1374978877,
'query_cgi' => 'idx=&q=history&branch_group_limit=',
'total' => 2,
'query_desc' => 'kw,wrdl: history, '
}
];
# Create new session and put its id into CGISESSID cookie
my $session = get_session("");
$session->flush;
my $input = new CookieSimulator({CGISESSID => $session->id});
my @recent_searches = ParseSearchHistorySession($input);
is_deeply(\@recent_searches, [], 'at start, there is no recent searches');
SetSearchHistorySession($input, $expected_recent_searches);
@recent_searches = ParseSearchHistorySession($input);
is_deeply(\@recent_searches, $expected_recent_searches, 'recent searches set and retrieved successfully');
SetSearchHistorySession($input, []);
@recent_searches = ParseSearchHistorySession($input);
is_deeply(\@recent_searches, [], 'recent searches emptied successfully');
# Delete session
$session->delete;
$session->flush;
package CookieSimulator;
sub new {
my ($class, $hashref) = @_;
my $val = $hashref;
return bless $val, $class;
}
sub cookie {
my ($self, $name) = @_;
return $self->{$name};
}
1;