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
=> 16;
23 use Koha
::SearchFields
;
24 use Koha
::SearchMarcMaps
;
26 use_ok
('Koha::SearchEngine::Elasticsearch');
28 my $schema = Koha
::Database
->new->schema;
30 $schema->storage->txn_begin;
32 Koha
::SearchFields
->search->delete;
33 Koha
::SearchMarcMaps
->search->delete;
34 $schema->resultset('SearchMarcToField')->search->delete;
38 my $search_field = Koha
::SearchFields
->find_or_create(
48 my $marc_field = Koha
::SearchMarcMaps
->find_or_create(
50 index_name
=> 'biblios',
51 marc_type
=> 'marc21',
55 $search_field->add_to_search_marc_maps($marc_field,
62 $marc_field = Koha
::SearchMarcMaps
->find_or_create(
64 index_name
=> 'biblios',
65 marc_type
=> 'marc21',
69 $search_field->add_to_search_marc_maps($marc_field,
76 $marc_field = Koha
::SearchMarcMaps
->find_or_create(
78 index_name
=> 'biblios',
79 marc_type
=> 'unimarc',
83 $search_field->add_to_search_marc_maps($marc_field,
90 my $mappings = Koha
::SearchEngine
::Elasticsearch
::raw_elasticsearch_mappings
();
92 is
( $mappings->{biblios
}{title
}{type
}, 'string', 'Title is of type string');
93 is
( $mappings->{biblios
}{title
}{label
}, 'Title', 'title has label Title');
94 is
( $mappings->{biblios
}{title
}{facet_order
}, undef, 'Facet order is undef');
96 is
(scalar(@
{ $mappings->{biblios
}{title
}{mappings
} }), 3, 'Title has 3 mappings');
98 my $f247_map = $mappings->{biblios
}{title
}{mappings
}[0];
99 is
( $f247_map->{marc_field
}, 247, 'First mapping is on field 247');
100 is
( $f247_map->{marc_type
}, 'marc21', 'First mapping is for marc21');
101 is
( $f247_map->{facet
}, '', 'First mapping facet is empty');
102 is
( $f247_map->{suggestible
}, '', 'First mapping is not suggestible');
103 is
( $f247_map->{sort}, undef, 'First mapping is not sortable');
105 my $f212_map = $mappings->{biblios
}{title
}{mappings
}[1];
106 is
( $f212_map->{marc_field
}, 212, 'Second mapping is on field 247');
107 is
( $f212_map->{marc_type
}, 'marc21', 'Second mapping is for marc21');
108 is
( $f212_map->{facet
}, '', 'Second mapping facet is empty');
109 is
( $f212_map->{suggestible
}, '', 'Second mapping is not suggestible');
110 is
( $f212_map->{sort}, undef, 'Second mapping is not sortable');
112 $mappings = Koha
::SearchEngine
::Elasticsearch
::raw_elasticsearch_mappings
('unimarc');
114 is
(scalar(@
{ $mappings->{biblios
}{title
}{mappings
} }), 1, 'Title has 1 mappings');
116 $schema->storage->txn_rollback;