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

(-)a/t/db_dependent/Koha_Elasticsearch.t (-1 / +131 lines)
Line 0 Link Here
0
- 
1
# This file is part of Koha.
2
#
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.
7
#
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.
12
#
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>
15
16
use Modern::Perl;
17
18
use Test::More tests => 1;
19
use Test::MockModule;
20
21
use t::lib::Mocks;
22
use t::lib::TestBuilder;
23
use MARC::Record;
24
25
use Koha::SearchFields;
26
27
my $schema = Koha::Database->schema;
28
my $builder = t::lib::TestBuilder->new;
29
30
subtest 'get_facetable_fields() tests' => sub {
31
32
    plan tests => 15;
33
34
    $schema->storage->txn_begin;
35
36
    Koha::SearchFields->search()->delete;
37
38
    $builder->build({
39
        source => 'SearchField',
40
        value => {
41
            name => 'author',
42
            label => 'author',
43
            type => 'string',
44
            facet_order => undef
45
        }
46
    });
47
    $builder->build({
48
        source => 'SearchField',
49
        value => {
50
            name => 'holdingbranch',
51
            label => 'holdingbranch',
52
            type => 'string',
53
            facet_order => 1
54
        }
55
    });
56
    $builder->build({
57
        source => 'SearchField',
58
        value => {
59
            name => 'homebranch',
60
            label => 'homebranch',
61
            type => 'string',
62
            facet_order => 2
63
        }
64
    });
65
    $builder->build({
66
        source => 'SearchField',
67
        value => {
68
            name => 'itype',
69
            label => 'itype',
70
            type => 'string',
71
            facet_order => 3
72
        }
73
    });
74
    $builder->build({
75
        source => 'SearchField',
76
        value => {
77
            name => 'se',
78
            label => 'se',
79
            type => 'string',
80
            facet_order => 4
81
        }
82
    });
83
    $builder->build({
84
        source => 'SearchField',
85
        value => {
86
            name => 'su-geo',
87
            label => 'su-geo',
88
            type => 'string',
89
            facet_order => 5
90
        }
91
    });
92
    $builder->build({
93
        source => 'SearchField',
94
        value => {
95
            name => 'subject',
96
            label => 'subject',
97
            type => 'string',
98
            facet_order => 6
99
        }
100
    });
101
    $builder->build({
102
        source => 'SearchField',
103
        value => {
104
            name => 'not_facetable_field',
105
            label => 'not_facetable_field',
106
            type => 'string',
107
            facet_order => undef
108
        }
109
    });
110
111
    my @faceted_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
112
    is(scalar(@faceted_fields), 7);
113
114
    is($faceted_fields[0]->name, 'holdingbranch');
115
    is($faceted_fields[0]->facet_order, 1);
116
    is($faceted_fields[1]->name, 'homebranch');
117
    is($faceted_fields[1]->facet_order, 2);
118
    is($faceted_fields[2]->name, 'itype');
119
    is($faceted_fields[2]->facet_order, 3);
120
    is($faceted_fields[3]->name, 'se');
121
    is($faceted_fields[3]->facet_order, 4);
122
    is($faceted_fields[4]->name, 'su-geo');
123
    is($faceted_fields[4]->facet_order, 5);
124
    is($faceted_fields[5]->name, 'subject');
125
    is($faceted_fields[5]->facet_order, 6);
126
    is($faceted_fields[6]->name, 'author');
127
    ok(!$faceted_fields[6]->facet_order);
128
129
130
    $schema->storage->txn_rollback;
131
};

Return to bug 18235