12 my $contextModule = new Test
::MockModule
('C4::Context');
13 $contextModule->mock('preference', sub {
16 $contextModule->mock('config', sub {
18 if ($key eq 'opachtdocs') {
19 return get_where
() . '/koha-tmpl/opac-tmpl';
20 } elsif ($key eq 'intrahtdocs') {
21 return get_where
() . '/koha-tmpl/intranet-tmpl';
27 use_ok
('Koha::SuggestionEngine');
30 my $location = File
::Spec
->rel2abs(dirname
(__FILE__
));
31 if ($location =~ /db_dependent/) {
32 $location .= '/../..';
41 if (! defined $ENV{KOHA_CONF
}) {
42 warning_like
{ $langModule = new Test
::MockModule
('C4::Languages'); }
43 qr
/unable to locate Koha configuration file koha-conf.xml/,
44 'Expected warning for unset $KOHA_CONF';
47 $langModule = new Test
::MockModule
('C4::Languages');
49 $langModule->mock('regex_lang_subtags', sub {
53 'privateuse' => undef,
57 'rfc4646_subtag' => 'en'
60 $langModule->mock('getTranslatedLanguages', sub {
63 'sublanguages_loop' => [
69 'region_description' => undef,
70 'sublanguage_current' => 1,
71 'privateuse' => undef,
73 'variant_description' => undef,
74 'script_description' => undef,
75 'rfc4646_subtag' => 'en',
76 'native_description' => 'English',
83 'native_description' => 'English',
84 'rfc4646_subtag' => 'en',
90 if (! defined $ENV{KOHA_CONF
}) {
91 warning_like
{ $tmplModule = new Test
::MockModule
('C4::Templates'); }
92 qr
/unable to locate Koha configuration file koha-conf.xml/,
93 'Expected warning for unset $KOHA_CONF';
96 $tmplModule = new Test
::MockModule
('C4::Templates');
98 $tmplModule->mock('_get_template_file', sub {
99 my ($tmplbase, $interface, $query) = @_;
100 my $opactmpl = get_where
() . '/koha-tmpl/opac-tmpl';
101 return ($opactmpl, 'bootstrap', 'en', "$opactmpl/bootstrap/en/modules/$tmplbase");
104 my $suggestor = Koha
::SuggestionEngine
->new( { plugins
=> [ 'ExplodedTerms' ] } );
105 is
(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
107 my $result = $suggestor->get_suggestions({search
=> 'Cookery'});
109 ok
((grep { $_->{'search'} eq 'su-na:Cookery' } @
$result) && (grep { $_->{'search'} eq 'su-br:Cookery' } @
$result) && (grep { $_->{'search'} eq 'su-rl:Cookery' } @
$result), "Suggested correct alternatives for keyword search 'Cookery'");
111 $result = $suggestor->get_suggestions({search
=> 'su:Cookery'});
113 ok
((grep { $_->{'search'} eq 'su-na:Cookery' } @
$result) && (grep { $_->{'search'} eq 'su-br:Cookery' } @
$result) && (grep { $_->{'search'} eq 'su-rl:Cookery' } @
$result), "Suggested correct alternatives for subject search 'Cookery'");
115 $result = $suggestor->get_suggestions({search
=> 'nt:Cookery'});
117 is
(scalar @
$result, 0, "No suggestions for fielded search");
119 $result = $suggestor->get_suggestions({search
=> 'ccl=su:Cookery'});
121 is
(scalar @
$result, 0, "No suggestions for CCL search");