13 my $contextModule = new Test
::MockModule
('C4::Context');
14 $contextModule->mock('preference', sub {
17 $contextModule->mock('config', sub {
19 if ($key eq 'opachtdocs') {
20 return get_where
() . '/koha-tmpl/opac-tmpl';
21 } elsif ($key eq 'intrahtdocs') {
22 return get_where
() . '/koha-tmpl/intranet-tmpl';
28 use_ok
('Koha::SuggestionEngine');
31 my $location = File
::Spec
->rel2abs(dirname
(__FILE__
));
32 if ($location =~ /db_dependent/) {
33 $location .= '/../..';
38 return abs_path
($location);
42 if (! defined $ENV{KOHA_CONF
}) {
43 warning_like
{ $langModule = new Test
::MockModule
('C4::Languages'); }
44 qr
/unable to locate Koha configuration file koha-conf.xml/,
45 'Expected warning for unset $KOHA_CONF';
48 $langModule = new Test
::MockModule
('C4::Languages');
50 $langModule->mock('regex_lang_subtags', sub {
54 'privateuse' => undef,
58 'rfc4646_subtag' => 'en'
61 $langModule->mock('getTranslatedLanguages', sub {
64 'sublanguages_loop' => [
70 'region_description' => undef,
71 'sublanguage_current' => 1,
72 'privateuse' => undef,
74 'variant_description' => undef,
75 'script_description' => undef,
76 'rfc4646_subtag' => 'en',
77 'native_description' => 'English',
84 'native_description' => 'English',
85 'rfc4646_subtag' => 'en',
91 if (! defined $ENV{KOHA_CONF
}) {
92 warning_like
{ $tmplModule = new Test
::MockModule
('C4::Templates'); }
93 qr
/unable to locate Koha configuration file koha-conf.xml/,
94 'Expected warning for unset $KOHA_CONF';
97 $tmplModule = new Test
::MockModule
('C4::Templates');
99 $tmplModule->mock('_get_template_file', sub {
100 my ($tmplbase, $interface, $query) = @_;
101 my $opactmpl = get_where
() . '/koha-tmpl/opac-tmpl';
102 return ($opactmpl, 'bootstrap', 'en', "$opactmpl/bootstrap/en/modules/$tmplbase");
105 my $suggestor = Koha
::SuggestionEngine
->new( { plugins
=> [ 'ExplodedTerms' ] } );
106 is
(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
108 my $result = $suggestor->get_suggestions({search
=> 'Cookery'});
110 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'");
112 $result = $suggestor->get_suggestions({search
=> 'su:Cookery'});
114 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'");
116 $result = $suggestor->get_suggestions({search
=> 'nt:Cookery'});
118 is
(scalar @
$result, 0, "No suggestions for fielded search");
120 $result = $suggestor->get_suggestions({search
=> 'ccl=su:Cookery'});
122 is
(scalar @
$result, 0, "No suggestions for CCL search");