Bug 18755: Allow empty passwords in Patron Info to return OK
[koha.git] / t / db_dependent / SuggestionEngine_ExplodedTerms.t
blob68fae90f7c8913dcc01751fd91d8e448279cf61f
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;
10 use Test::Warn;
12 my $contextModule = new Test::MockModule('C4::Context');
13 $contextModule->mock('preference', sub {
14 return '';
15 });
16 $contextModule->mock('config', sub {
17 my ($self,$key) = @_;
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';
22 } else {
23 return '';
25 });
27 use_ok('Koha::SuggestionEngine');
29 sub get_where {
30 my $location = File::Spec->rel2abs(dirname(__FILE__));
31 if ($location =~ /db_dependent/) {
32 $location .= '/../..';
34 else {
35 $location .= '/..';
37 return $location;
40 my $langModule;
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';
46 else {
47 $langModule = new Test::MockModule('C4::Languages');
49 $langModule->mock('regex_lang_subtags', sub {
50 return {
51 'extension' => undef,
52 'script' => undef,
53 'privateuse' => undef,
54 'variant' => undef,
55 'language' => 'en',
56 'region' => undef,
57 'rfc4646_subtag' => 'en'
59 });
60 $langModule->mock('getTranslatedLanguages', sub {
61 return [
63 'sublanguages_loop' => [
65 'script' => undef,
66 'extension' => undef,
67 'language' => 'en',
68 'region' => undef,
69 'region_description' => undef,
70 'sublanguage_current' => 1,
71 'privateuse' => undef,
72 'variant' => undef,
73 'variant_description' => undef,
74 'script_description' => undef,
75 'rfc4646_subtag' => 'en',
76 'native_description' => 'English',
77 'enabled' => 1
80 'plural' => 1,
81 'language' => 'en',
82 'current' => 1,
83 'native_description' => 'English',
84 'rfc4646_subtag' => 'en',
85 'group_enabled' => 1
88 });
89 my $tmplModule;
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';
95 else {
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");
123 done_testing();