|
Lines 1-20
Link Here
|
| 1 |
#!/usr/bin/perl |
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. |
| 2 |
# |
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 |
|
| 3 |
# This Koha test module uses Test::MockModule to get around the need for known |
18 |
# This Koha test module uses Test::MockModule to get around the need for known |
| 4 |
# contents in the authority file by returning a single known authority record |
19 |
# contents in the authority file by returning a single known authority record |
| 5 |
# for every call to SearchAuthorities |
20 |
# for every call to SearchAuthorities |
| 6 |
|
21 |
|
| 7 |
use strict; |
22 |
use Modern::Perl; |
| 8 |
use warnings; |
23 |
|
| 9 |
use File::Spec; |
24 |
use File::Spec; |
| 10 |
use MARC::Record; |
25 |
use MARC::Record; |
| 11 |
|
26 |
|
| 12 |
use Test::More; |
27 |
use Test::More; |
| 13 |
use Test::MockModule; |
28 |
use Test::MockModule; |
|
|
29 |
use DBD::Mock; |
| 30 |
|
| 31 |
# Mock the DB connexion and C4::Context |
| 32 |
my $context = new Test::MockModule('C4::Context'); |
| 33 |
$context->mock( '_new_dbh', sub { |
| 34 |
my $dbh = DBI->connect( 'DBI:Mock:', '', '' ) |
| 35 |
|| die "Cannot create handle: $DBI::errstr\n"; |
| 36 |
return $dbh; |
| 37 |
}); |
| 14 |
|
38 |
|
| 15 |
BEGIN { |
39 |
use_ok('Koha::SuggestionEngine'); |
| 16 |
use_ok('Koha::SuggestionEngine'); |
|
|
| 17 |
} |
| 18 |
|
40 |
|
| 19 |
my $module = new Test::MockModule('C4::AuthoritiesMarc'); |
41 |
my $module = new Test::MockModule('C4::AuthoritiesMarc'); |
| 20 |
$module->mock('SearchAuthorities', sub { |
42 |
$module->mock('SearchAuthorities', sub { |
|
Lines 41-43
my $result = $suggestor->get_suggestions({search => 'Cookery'});
Link Here
|
| 41 |
is_deeply($result, [ { 'search' => 'an=1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'"); |
63 |
is_deeply($result, [ { 'search' => 'an=1234', 'relevance' => 1, 'label' => 'Cooking' } ], "Suggested correct alternative to 'Cookery'"); |
| 42 |
|
64 |
|
| 43 |
done_testing(); |
65 |
done_testing(); |
| 44 |
- |
66 |
|
|
|
67 |
1; |