Bug 11439: (follow up) add missing rollback call
[koha.git] / t / db_dependent / SuggestionEngine_ExplodedTerms.t
blobb97166e354a65986b5939696974fc9c8d6d3ecd9
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use File::Basename;
7 use File::Spec;
8 use Test::More;
9 use Test::MockModule;
11 BEGIN {
12 use_ok('Koha::SuggestionEngine');
15 my $langModule = new Test::MockModule('C4::Languages');
16 $langModule->mock('regex_lang_subtags', sub {
17 return {
18 'extension' => undef,
19 'script' => undef,
20 'privateuse' => undef,
21 'variant' => undef,
22 'language' => 'en',
23 'region' => undef,
24 'rfc4646_subtag' => 'en'
26 });
27 $langModule->mock('getTranslatedLanguages', sub {
28 return [
30 'sublanguages_loop' => [
32 'script' => undef,
33 'extension' => undef,
34 'language' => 'en',
35 'region' => undef,
36 'region_description' => undef,
37 'sublanguage_current' => 1,
38 'privateuse' => undef,
39 'variant' => undef,
40 'variant_description' => undef,
41 'script_description' => undef,
42 'rfc4646_subtag' => 'en',
43 'native_description' => 'English',
44 'enabled' => 1
47 'plural' => 1,
48 'language' => 'en',
49 'current' => 1,
50 'native_description' => 'English',
51 'rfc4646_subtag' => 'en',
52 'group_enabled' => 1
55 });
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");
61 });
62 my $contextModule = new Test::MockModule('C4::Context');
63 $contextModule->mock('preference', sub {
64 return '';
65 });
66 $contextModule->mock('config', sub {
67 return '';
68 });
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");
90 done_testing();