Bug 16330: Add routes to add, update and delete patrons
[koha.git] / t / SuggestionEngine_AuthorityFile.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
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
21
22 use Modern::Perl;
23
24 use File::Spec;
25 use MARC::Record;
26
27 use Test::More;
28 use Test::MockModule;
29 use t::lib::Mocks;
30
31 use Module::Load::Conditional qw/check_install/;
32
33 BEGIN {
34     if ( check_install( module => 'Test::DBIx::Class' ) ) {
35         plan tests => 3;
36     } else {
37         plan skip_all => "Need Test::DBIx::Class"
38     }
39 }
40
41 # Mock the DB connexion
42 use Test::DBIx::Class;
43 my $db = Test::MockModule->new('Koha::Database');
44 $db->mock( _new_schema => sub { return Schema(); } );
45
46 use_ok('Koha::SuggestionEngine');
47
48 my $module = new Test::MockModule('C4::AuthoritiesMarc');
49 $module->mock('SearchAuthorities', sub {
50         return [ { 'authid' => '1234',
51                     'reported_tag' => undef,
52                     'even' => 0,
53                     'summary' => {
54                         'authorized' => [ { 'heading' => 'Cooking' } ],
55                         'otherscript' => [],
56                         'seefrom' => [ 'Cookery' ],
57                         'notes' => [ 'Your quintessential poor heading selection' ],
58                         'seealso' => []
59                     },
60                     'used' => 1,
61                     'authtype' => 'Topical Term'
62                 } ], 1
63 });
64
65 my $suggestor = Koha::SuggestionEngine->new( { plugins => [ 'AuthorityFile' ] } );
66 is(ref($suggestor), 'Koha::SuggestionEngine', 'Created suggestion engine');
67
68 my $result = $suggestor->get_suggestions({search => 'Cookery'});
69
70 is_deeply($result, [ { 'search' => 'an:1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'");
71
72 done_testing();
73