Bug 13877 - Fix QA issues
[koha.git] / t / SuggestionEngine_AuthorityFile.t
blobef6eb42eff0b4485b969964cfe9ae033d661cfb6
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 # This Koha test module uses Test::MockModule to get around the need for known
19 # contents in the authority file by returning a single known authority record
20 # for every call to SearchAuthorities
22 use Modern::Perl;
24 use File::Spec;
25 use MARC::Record;
27 use Test::More;
28 use Test::MockModule;
29 use t::lib::Mocks;
31 # Mock the DB connexion and C4::Context
32 my $context = t::lib::Mocks::mock_dbh;
34 use_ok('Koha::SuggestionEngine');
36 my $module = new Test::MockModule('C4::AuthoritiesMarc');
37 $module->mock('SearchAuthorities', sub {
38 return [ { 'authid' => '1234',
39 'reported_tag' => undef,
40 'even' => 0,
41 'summary' => {
42 'authorized' => [ { 'heading' => 'Cooking' } ],
43 'otherscript' => [],
44 'seefrom' => [ 'Cookery' ],
45 'notes' => [ 'Your quintessential poor heading selection' ],
46 'seealso' => []
48 'used' => 1,
49 'authtype' => 'Topical Term'
50 } ], 1
51 });
53 my $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'AuthorityFile' ] } );
54 is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
56 my $result = $suggestor->get_suggestions({search => 'Cookery'});
58 is_deeply($result, [ { 'search' => 'an=1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'");
60 done_testing();