Koha/t/db_dependent/SuggestionEngine_ExplodedTerms.t
Tomas Cohen Arazi ecd91d6089
Bug 31069: Remove ExplodedTerms dependency on templates
This patch removes the use of templates and CGI in ExplodedTerms by using the
Koha::I18N library.

The functionality on the package is too simple, and messing with the
template paths complexity on the tests was too much, given we have a
nice way to have translatable strings at the package level.

This patch does that, and cleans up the test file as well, that required
complex template and CGI mocking to run properly.

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/SuggestionEngine_ExplodedTerms.t
=> FAIL: It fails in master
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass
4. Follow the original test plan
=> SUCCESS: Things work
5. Enjoy the rest of the day and forget this ever happened

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2022-07-18 12:37:35 -03:00

45 lines
1.8 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 5;
use Koha::SuggestionEngine;
my $suggestor = Koha::SuggestionEngine->new( { plugins => ['ExplodedTerms'] } );
is( ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine' );
my $result = $suggestor->get_suggestions( { search => 'Cookery' } );
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'"
);
$result = $suggestor->get_suggestions( { search => 'su:Cookery' } );
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'"
);
$result = $suggestor->get_suggestions( { search => 'nt:Cookery' } );
is( scalar @$result, 0, "No suggestions for fielded search" );
$result = $suggestor->get_suggestions( { search => 'ccl=su:Cookery' } );
is( scalar @$result, 0, "No suggestions for CCL search" );