Bug 26384: Fix executable flags
[srvgit] / t / db_dependent / Koha / SearchEngine / Elasticsearch / Reset.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 use Modern::Perl;
19
20 use Test::More tests => 5;
21 use Test::MockModule;
22
23 use Koha::Database;
24 use Koha::Caches;
25
26 my $indexes = {
27     'authorities' => {
28         'Match' => {
29             'label' => 'Match',
30             'type' => '',
31             'weight' => 15,
32             'mappings' => []
33         }
34     },
35     'biblios' => {
36         'title' => {
37             'label' => 'title',
38             'type' => '',
39             'weight' => 20,
40             'mapping' => []
41         }
42     }
43 };
44
45 my $yaml = Test::MockModule->new('YAML::Syck');
46 $yaml->mock( 'LoadFile', sub { return $indexes; } );
47
48 use_ok('Koha::SearchEngine::Elasticsearch');
49
50 my $schema = Koha::Database->new->schema;
51
52 $schema->storage->txn_begin;
53
54 Koha::SearchFields->search->delete;
55 Koha::SearchMarcMaps->search->delete;
56 $schema->resultset('SearchMarcToField')->search->delete;
57
58
59 Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
60
61 my $cache = Koha::Caches->get_instance();
62 is( $cache->get_from_cache('elasticsearch_search_fields_staff_client'), undef, 'Cache has been flushed by reset_elasticsearch_mappings' );
63
64 my $search_fields = Koha::SearchFields->search({});
65 is($search_fields->count, 2, 'There is 2 search fields after reset');
66
67 my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next;
68 is($match_sf->weight, '15.00', 'Match search field is weighted with 15');
69
70 my $title_sf = Koha::SearchFields->search({ name => 'title' })->next;
71 is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
72
73 $schema->storage->txn_rollback;
74
75 Koha::SearchEngine::Elasticsearch->clear_search_fields_cache();