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>.
20 use Test::More tests => 7;
47 my $yaml = Test::MockModule->new('YAML::Syck');
48 $yaml->mock( 'LoadFile', sub { return $indexes; } );
50 use_ok('Koha::SearchEngine::Elasticsearch');
52 my $schema = Koha::Database->new->schema;
54 $schema->storage->txn_begin;
56 Koha::SearchFields->search->delete;
57 Koha::SearchMarcMaps->search->delete;
58 $schema->resultset('SearchMarcToField')->search->delete;
61 Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
63 my $cache = Koha::Caches->get_instance();
64 is( $cache->get_from_cache('elasticsearch_search_fields_staff_client'), undef, 'Cache has been flushed by reset_elasticsearch_mappings' );
66 my $search_fields = Koha::SearchFields->search({});
67 is($search_fields->count, 2, 'There is 2 search fields after reset');
69 my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next;
70 is($match_sf->weight, '15.00', 'Match search field is weighted with 15');
71 is($match_sf->mandatory, '0', 'Match search field is not mandatory');
73 my $title_sf = Koha::SearchFields->search({ name => 'title' })->next;
74 is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
75 is($title_sf->mandatory, '1', 'Title search field is mandatory');
77 $schema->storage->txn_rollback;
79 Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();