Bug 24546: Fix intentions of build_sample_item in Club/Hold.t
[koha.git] / t / db_dependent / Koha_Elasticsearch.t
blob078d55d6594b3291d5e8c8643f9085bffa8f3ea8
1 # This file is part of Koha.
3 # Koha is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # Koha is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with Koha; if not, see <http://www.gnu.org/licenses>
16 use Modern::Perl;
18 use Test::More tests => 1;
19 use Test::MockModule;
21 use t::lib::Mocks;
22 use t::lib::TestBuilder;
23 use MARC::Record;
25 use Koha::SearchFields;
26 use Koha::SearchEngine::Elasticsearch;
28 my $schema = Koha::Database->schema;
29 my $builder = t::lib::TestBuilder->new;
31 subtest 'get_facetable_fields() tests' => sub {
33     plan tests => 15;
35     $schema->storage->txn_begin;
37     Koha::SearchFields->search()->delete;
39     $builder->build({
40         source => 'SearchField',
41         value => {
42             name => 'author',
43             label => 'author',
44             type => 'string',
45             facet_order => undef
46         }
47     });
48     $builder->build({
49         source => 'SearchField',
50         value => {
51             name => 'holdingbranch',
52             label => 'holdingbranch',
53             type => 'string',
54             facet_order => 1
55         }
56     });
57     $builder->build({
58         source => 'SearchField',
59         value => {
60             name => 'homebranch',
61             label => 'homebranch',
62             type => 'string',
63             facet_order => 2
64         }
65     });
66     $builder->build({
67         source => 'SearchField',
68         value => {
69             name => 'itype',
70             label => 'itype',
71             type => 'string',
72             facet_order => 3
73         }
74     });
75     $builder->build({
76         source => 'SearchField',
77         value => {
78             name => 'title-series',
79             label => 'titles-series',
80             type => 'string',
81             facet_order => 4
82         }
83     });
84     $builder->build({
85         source => 'SearchField',
86         value => {
87             name => 'su-geo',
88             label => 'su-geo',
89             type => 'string',
90             facet_order => 5
91         }
92     });
93     $builder->build({
94         source => 'SearchField',
95         value => {
96             name => 'subject',
97             label => 'subject',
98             type => 'string',
99             facet_order => 6
100         }
101     });
102     $builder->build({
103         source => 'SearchField',
104         value => {
105             name => 'not_facetable_field',
106             label => 'not_facetable_field',
107             type => 'string',
108             facet_order => undef
109         }
110     });
112     my @faceted_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
113     is(scalar(@faceted_fields), 7);
115     is($faceted_fields[0]->name, 'holdingbranch');
116     is($faceted_fields[0]->facet_order, 1);
117     is($faceted_fields[1]->name, 'homebranch');
118     is($faceted_fields[1]->facet_order, 2);
119     is($faceted_fields[2]->name, 'itype');
120     is($faceted_fields[2]->facet_order, 3);
121     is($faceted_fields[3]->name, 'title-series');
122     is($faceted_fields[3]->facet_order, 4);
123     is($faceted_fields[4]->name, 'su-geo');
124     is($faceted_fields[4]->facet_order, 5);
125     is($faceted_fields[5]->name, 'subject');
126     is($faceted_fields[5]->facet_order, 6);
127     is($faceted_fields[6]->name, 'author');
128     ok(!$faceted_fields[6]->facet_order);
131     $schema->storage->txn_rollback;