Lines 19-28
use Modern::Perl;
Link Here
|
19 |
|
19 |
|
20 |
use Test::More tests => 14; |
20 |
use Test::More tests => 14; |
21 |
use t::lib::Mocks; |
21 |
use t::lib::Mocks; |
|
|
22 |
use t::lib::TestBuilder; |
22 |
|
23 |
|
23 |
use Koha::SearchEngine::Elasticsearch::QueryBuilder; |
24 |
use Koha::SearchEngine::Elasticsearch::QueryBuilder; |
24 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
25 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
25 |
|
26 |
use Koha::SearchFields; |
26 |
|
27 |
|
27 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
28 |
my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' ); |
28 |
$se->mock( 'get_elasticsearch_mappings', sub { |
29 |
$se->mock( 'get_elasticsearch_mappings', sub { |
Lines 125-155
SKIP: {
Link Here
|
125 |
is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value'); |
126 |
is ($searcher->max_result_window, 12000, 'max_result_window returns the correct value'); |
126 |
|
127 |
|
127 |
subtest "_convert_facets" => sub { |
128 |
subtest "_convert_facets" => sub { |
128 |
plan tests => 2; |
129 |
plan tests => 5; |
|
|
130 |
|
131 |
my $schema = Koha::Database->new()->schema(); |
132 |
$schema->storage->txn_begin; |
133 |
my $builder = t::lib::TestBuilder->new; |
129 |
|
134 |
|
130 |
my $es_facets = { |
135 |
my $es_facets = { |
131 |
'ln' => { |
136 |
'ln' => { |
132 |
'sum_other_doc_count' => 0, |
137 |
'sum_other_doc_count' => 0, |
133 |
'buckets' => [ |
138 |
'buckets' => [ |
134 |
{ |
139 |
{ |
135 |
'doc_count' => 2, |
140 |
'doc_count' => 2, |
136 |
'key' => 'eng' |
141 |
'key' => 'eng' |
137 |
}, |
142 |
}, |
138 |
{ |
143 |
{ |
139 |
'doc_count' => 12, |
144 |
'doc_count' => 12, |
140 |
'key' => '' |
145 |
'key' => '' |
141 |
} |
146 |
} |
142 |
], |
147 |
], |
143 |
'doc_count_error_upper_bound' => 0 |
148 |
'doc_count_error_upper_bound' => 0 |
144 |
} |
149 |
} |
145 |
}; |
150 |
}; |
146 |
|
151 |
|
147 |
my $koha_facets = $searcher->_convert_facets($es_facets); |
152 |
my $koha_facets = $searcher->_convert_facets($es_facets); |
148 |
is(@{$koha_facets->[0]->{facets}},1,"We only get one facet, blank is removed"); |
153 |
is( @{ $koha_facets->[0]->{facets} }, 1, "We only get one facet, blank is removed" ); |
149 |
|
154 |
|
150 |
$es_facets->{ln}->{buckets}->[1]->{key} = '0'; |
155 |
$es_facets->{ln}->{buckets}->[1]->{key} = '0'; |
151 |
$koha_facets = $searcher->_convert_facets($es_facets); |
156 |
$koha_facets = $searcher->_convert_facets($es_facets); |
152 |
is(@{$koha_facets->[0]->{facets}},2,"We get two facets, '0' is not removed"); |
157 |
is( @{ $koha_facets->[0]->{facets} }, 2, "We get two facets, '0' is not removed" ); |
|
|
158 |
is( $koha_facets->[0]->{av_cat}, undef, "Not linked with an authorised value category" ); |
159 |
|
160 |
my $av_cat = $builder->build_object( { class => 'Koha::AuthorisedValueCategories' } ); |
161 |
Koha::SearchFields->find( { name => 'ln' } )->update( { authorised_value_category => $av_cat->category_name } ); |
162 |
$builder->build_object( |
163 |
{ |
164 |
class => 'Koha::AuthorisedValues', |
165 |
value => { category => $av_cat->category_name, authorised_value => 'eng', lib_opac => 'English' } |
166 |
} |
167 |
); |
168 |
$koha_facets = $searcher->_convert_facets($es_facets); |
169 |
is( $koha_facets->[0]->{av_cat}, $av_cat->category_name, "Linked with an authorised value category" ); |
170 |
is( |
171 |
$koha_facets->[0]->{facets}->[1]->{facet_label_value}, "English", |
172 |
"Value of the facet replaced with AV's description" |
173 |
); |
174 |
|
175 |
$schema->storage->txn_rollback; |
153 |
|
176 |
|
154 |
}; |
177 |
}; |
155 |
} |
178 |
} |
156 |
- |
|
|