View | Details | Raw Unified | Return to bug 17897
Collapse All | Expand All

(-)a/Koha/SearchMappingManager.pm (-10 / +10 lines)
Lines 2-19 package Koha::SearchMappingManager; Link Here
2
2
3
# This file is part of Koha.
3
# This file is part of Koha.
4
#
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
5
# Koha is free software; you can redistribute it and/or modify it
6
# terms of the GNU General Public License as published by the Free Software
6
# under the terms of the GNU General Public License as published by
7
# Foundation; either version 3 of the License, or (at your option) any later
7
# the Free Software Foundation; either version 3 of the License, or
8
# version.
8
# (at your option) any later version.
9
#
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
10
# Koha is distributed in the hope that it will be useful, but
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
13
#
14
#
14
# You should have received a copy of the GNU General Public License along
15
# You should have received a copy of the GNU General Public License
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
(-)a/t/db_dependent/Koha/SearchEngine/ElasticSearch.t (-27 / +25 lines)
Lines 17-37 Link Here
17
# You should have received a copy of the GNU General Public License
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl qw(2014);
20
use Modern::Perl;
21
use utf8;
21
use utf8;
22
use Test::More;
22
use Test::More tests => 3;
23
use Test::Exception;
23
24
24
use Koha::Database;
25
use Koha::Database;
25
use Koha::SearchEngine::Elasticsearch;
26
use Koha::SearchEngine::Elasticsearch;
26
use Koha::SearchMappingManager;
27
use Koha::SearchMappingManager;
27
28
28
my $schema = Koha::Database->schema;
29
my $schema = Koha::Database->schema;
30
$schema->storage->txn_begin;
29
31
30
subtest "Reset Elasticsearch mappings", \&reset_elasticsearch_mappings;
32
subtest 'reset_elasticsearch_mappings() tests' => sub {
31
sub reset_elasticsearch_mappings {
33
32
    my ($rv, $mappings, $count, $mapping);
34
    plan tests => 8;
33
35
34
    $schema->storage->txn_begin;
36
    my ($rv, $mappings, $count, $mapping);
35
37
36
    ok(1, 'Scenario: Reset Elasticsearch mappings to an empty database');
38
    ok(1, 'Scenario: Reset Elasticsearch mappings to an empty database');
37
    #There might or might not be any mappings. Whatever the initial status is, make sure we start from empty tables
39
    #There might or might not be any mappings. Whatever the initial status is, make sure we start from empty tables
Lines 49-60 sub reset_elasticsearch_mappings { Link Here
49
    $count = $mappings->count();
51
    $count = $mappings->count();
50
    ok($count, 'Then search mapping tables have been populated');
52
    ok($count, 'Then search mapping tables have been populated');
51
53
52
53
54
    ok(1, 'Scenario: Reset Elasticsearch mappings when custom mappings already exist');
54
    ok(1, 'Scenario: Reset Elasticsearch mappings when custom mappings already exist');
55
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
55
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
56
                                                   label => 'original language',
56
                                                   label => 'original language',
57
                                                   type => 'keyword',
57
                                                   type => '',
58
                                                   index_name => 'biblios',
58
                                                   index_name => 'biblios',
59
                                                   marc_type => 'marc21',
59
                                                   marc_type => 'marc21',
60
                                                   marc_field => '024a',
60
                                                   marc_field => '024a',
Lines 74-87 sub reset_elasticsearch_mappings { Link Here
74
    $count = $mappings->count();
74
    $count = $mappings->count();
75
    ok($count > 10, 'Then search mapping tables have been populated');
75
    ok($count > 10, 'Then search mapping tables have been populated');
76
76
77
    $schema->storage->txn_rollback;
77
};
78
}
79
78
80
subtest "Get Elasticsearch mappings", \&get_search_mappings;
79
subtest 'get_search_mappings() tests' => sub {
81
sub get_search_mappings {
82
    my ($mappings, $mapping);
83
80
84
    $schema->storage->txn_begin;
81
    plan tests => 13;
82
83
    my ($mappings, $mapping);
85
84
86
    ok(1, 'Scenario: Get a single search mapping by name');
85
    ok(1, 'Scenario: Get a single search mapping by name');
87
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ff7-00'});
86
    $mappings = Koha::SearchMappingManager::get_search_mappings({index_name => 'biblios', name => 'ff7-00'});
Lines 91-97 sub get_search_mappings { Link Here
91
    is($mapping->get_column('type'),       '',       'And the search mapping "type" matches');
90
    is($mapping->get_column('type'),       '',       'And the search mapping "type" matches');
92
    is($mapping->get_column('facet'),      '0',      'And the search mapping "facet" matches');
91
    is($mapping->get_column('facet'),      '0',      'And the search mapping "facet" matches');
93
    is($mapping->get_column('suggestible'), '0',     'And the search mapping "suggestible" matches');
92
    is($mapping->get_column('suggestible'), '0',     'And the search mapping "suggestible" matches');
94
    is($mapping->get_column('sort'),        undef,   'And the search mapping "sort" matches');
93
    is($mapping->get_column('sort'),        '1',   'And the search mapping "sort" matches');
95
    is($mapping->get_column('search'),     '1',   'And the search mapping "search" matches');
94
    is($mapping->get_column('search'),     '1',   'And the search mapping "search" matches');
96
    is($mapping->get_column('marc_type'),  'marc21', 'And the search mapping "marc_type" matches');
95
    is($mapping->get_column('marc_type'),  'marc21', 'And the search mapping "marc_type" matches');
97
    is($mapping->get_column('marc_field'), '007_/0', 'And the search mapping "marc_field" matches');
96
    is($mapping->get_column('marc_field'), '007_/0', 'And the search mapping "marc_field" matches');
Lines 101-119 sub get_search_mappings { Link Here
101
    ok($mappings, 'When search mappings are fetched');
100
    ok($mappings, 'When search mappings are fetched');
102
    ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)');
101
    ok($mappings->count() > 10, 'Then we have "'.$mappings->count().'" search mappings :)');
103
102
104
    $schema->storage->txn_rollback;
103
};
105
}
106
104
107
subtest "Add a search mapping", \&add_mapping;
105
subtest 'add_mapping() tests' => sub {
108
sub add_mapping {
109
    my ($rv, $mappings, $mapping, $count);
110
106
111
    $schema->storage->txn_begin;
107
    plan tests => 3;
108
109
    my ($rv, $mappings, $mapping, $count);
112
110
113
    ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings");
111
    ok(1, "Scenario: Add the same mapping twice and hope for no duplicate mappings");
114
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
112
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
115
                                                   label => 'original language',
113
                                                   label => 'original language',
116
                                                   type => 'keyword',
114
                                                   type => '',
117
                                                   index_name => 'biblios',
115
                                                   index_name => 'biblios',
118
                                                   marc_type => 'marc21',
116
                                                   marc_type => 'marc21',
119
                                                   marc_field => '024a',
117
                                                   marc_field => '024a',
Lines 122-128 sub add_mapping { Link Here
122
                                                   sort => 1});
120
                                                   sort => 1});
123
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
121
    $rv = Koha::SearchMappingManager::add_mapping({name => 'ln-test',
124
                                                   label => 'original language',
122
                                                   label => 'original language',
125
                                                   type => 'keyword',
123
                                                   type => '',
126
                                                   index_name => 'biblios',
124
                                                   index_name => 'biblios',
127
                                                   marc_type => 'marc21',
125
                                                   marc_type => 'marc21',
128
                                                   marc_field => '024a',
126
                                                   marc_field => '024a',
Lines 135-141 sub add_mapping { Link Here
135
    $count = $mappings->count();
133
    $count = $mappings->count();
136
    is($count, 1, "Then we received only one mapping from the database");
134
    is($count, 1, "Then we received only one mapping from the database");
137
135
138
    $schema->storage->txn_rollback;
136
};
139
}
137
138
$schema->storage->txn_rollback;
140
139
141
done_testing;
140
done_testing;
142
- 

Return to bug 17897