12 use_ok
('Koha::SuggestionEngine');
15 my $langModule = new Test
::MockModule
('C4::Languages');
16 $langModule->mock('regex_lang_subtags', sub {
20 'privateuse' => undef,
24 'rfc4646_subtag' => 'en'
27 $langModule->mock('getTranslatedLanguages', sub {
30 'sublanguages_loop' => [
36 'region_description' => undef,
37 'sublanguage_current' => 1,
38 'privateuse' => undef,
40 'variant_description' => undef,
41 'script_description' => undef,
42 'rfc4646_subtag' => 'en',
43 'native_description' => 'English',
50 'native_description' => 'English',
51 'rfc4646_subtag' => 'en',
56 my $tmplModule = new Test
::MockModule
('C4::Templates');
57 $tmplModule->mock('_get_template_file', sub {
58 my ($tmplbase, $interface, $query) = @_;
59 my $opactmpl = File
::Spec
->rel2abs(dirname
(__FILE__
) . '/../../koha-tmpl/opac-tmpl');
60 return ($opactmpl, 'prog', 'en', "$opactmpl/prog/en/modules/$tmplbase");
62 my $contextModule = new Test
::MockModule
('C4::Context');
63 $contextModule->mock('preference', sub {
66 $contextModule->mock('config', sub {
71 my $suggestor = Koha
::SuggestionEngine
->new( { plugins
=> [ 'ExplodedTerms' ] } );
72 is
(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
74 my $result = $suggestor->get_suggestions({search
=> 'Cookery'});
76 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'");
78 $result = $suggestor->get_suggestions({search
=> 'su:Cookery'});
80 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'");
82 $result = $suggestor->get_suggestions({search
=> 'nt:Cookery'});
84 is
(scalar @
$result, 0, "No suggestions for fielded search");
86 $result = $suggestor->get_suggestions({search
=> 'ccl=su:Cookery'});
88 is
(scalar @
$result, 0, "No suggestions for CCL search");