Lines 25-32
use t::lib::Mocks;
Link Here
|
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
27 |
use MARC::Record; |
27 |
use MARC::Record; |
|
|
28 |
use Try::Tiny; |
28 |
|
29 |
|
29 |
use Koha::SearchEngine::Elasticsearch; |
30 |
use Koha::SearchEngine::Elasticsearch; |
|
|
31 |
use Koha::SearchEngine::Elasticsearch::Search; |
30 |
|
32 |
|
31 |
subtest '_read_configuration() tests' => sub { |
33 |
subtest '_read_configuration() tests' => sub { |
32 |
|
34 |
|
Lines 115-126
subtest 'get_elasticsearch_mappings() tests' => sub {
Link Here
|
115 |
|
117 |
|
116 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { |
118 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { |
117 |
|
119 |
|
118 |
plan tests => 32; |
120 |
plan tests => 45; |
119 |
|
121 |
|
120 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
122 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
121 |
|
123 |
|
122 |
my @mappings = ( |
124 |
my @mappings = ( |
123 |
{ |
125 |
{ |
|
|
126 |
name => 'control_number', |
127 |
type => 'string', |
128 |
facet => 0, |
129 |
suggestible => 0, |
130 |
sort => undef, |
131 |
marc_type => 'marc21', |
132 |
marc_field => '001', |
133 |
}, |
134 |
{ |
124 |
name => 'author', |
135 |
name => 'author', |
125 |
type => 'string', |
136 |
type => 'string', |
126 |
facet => 1, |
137 |
facet => 1, |
Lines 166-171
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
166 |
marc_field => '220', |
177 |
marc_field => '220', |
167 |
}, |
178 |
}, |
168 |
{ |
179 |
{ |
|
|
180 |
name => 'title_wildcard', |
181 |
type => 'string', |
182 |
facet => 0, |
183 |
suggestible => 0, |
184 |
sort => undef, |
185 |
marc_type => 'marc21', |
186 |
marc_field => '245', |
187 |
}, |
188 |
{ |
169 |
name => 'sum_item_price', |
189 |
name => 'sum_item_price', |
170 |
type => 'sum', |
190 |
type => 'sum', |
171 |
facet => 0, |
191 |
facet => 0, |
Lines 220-230
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
220 |
} |
240 |
} |
221 |
}); |
241 |
}); |
222 |
|
242 |
|
223 |
my $see = Koha::SearchEngine::Elasticsearch->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
243 |
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
224 |
|
244 |
|
225 |
my $marc_record_1 = MARC::Record->new(); |
245 |
my $marc_record_1 = MARC::Record->new(); |
226 |
$marc_record_1->leader(' cam 22 a 4500'); |
246 |
$marc_record_1->leader(' cam 22 a 4500'); |
227 |
$marc_record_1->append_fields( |
247 |
$marc_record_1->append_fields( |
|
|
248 |
MARC::Field->new('001', '123'), |
228 |
MARC::Field->new('100', '', '', a => 'Author 1'), |
249 |
MARC::Field->new('100', '', '', a => 'Author 1'), |
229 |
MARC::Field->new('110', '', '', a => 'Corp Author'), |
250 |
MARC::Field->new('110', '', '', a => 'Corp Author'), |
230 |
MARC::Field->new('210', '', '', a => 'Title 1'), |
251 |
MARC::Field->new('210', '', '', a => 'Title 1'), |
Lines 255-260
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
255 |
|
276 |
|
256 |
is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple'); |
277 |
is($docs->[0][0], '1234567', 'First document biblionumber should be set as first element in document touple'); |
257 |
|
278 |
|
|
|
279 |
is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly'); |
280 |
|
258 |
is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values'); |
281 |
is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values'); |
259 |
is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); |
282 |
is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); |
260 |
|
283 |
|
Lines 264-269
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
264 |
is(scalar @{$docs->[0][1]->{title__sort}}, 3, 'First document title__sort field should have three values'); |
287 |
is(scalar @{$docs->[0][1]->{title__sort}}, 3, 'First document title__sort field should have three values'); |
265 |
is_deeply($docs->[0][1]->{title__sort}, ['Title:', 'first record', 'Title: first record'], 'First document title__sort field should be set correctly'); |
288 |
is_deeply($docs->[0][1]->{title__sort}, ['Title:', 'first record', 'Title: first record'], 'First document title__sort field should be set correctly'); |
266 |
|
289 |
|
|
|
290 |
is(scalar @{$docs->[0][1]->{title_wildcard}}, 2, 'First document title_wildcard field should have two values'); |
291 |
is_deeply($docs->[0][1]->{title_wildcard}, ['Title:', 'first record'], 'First document title_wildcard field should be set correctly'); |
292 |
|
267 |
is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values'); |
293 |
is(scalar @{$docs->[0][1]->{author__suggestion}}, 2, 'First document author__suggestion field should contain two values'); |
268 |
is_deeply( |
294 |
is_deeply( |
269 |
$docs->[0][1]->{author__suggestion}, |
295 |
$docs->[0][1]->{author__suggestion}, |
Lines 312-322
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
312 |
); |
338 |
); |
313 |
|
339 |
|
314 |
ok(defined $docs->[0][1]->{marc_data}, 'First document marc_data field should be set'); |
340 |
ok(defined $docs->[0][1]->{marc_data}, 'First document marc_data field should be set'); |
315 |
|
|
|
316 |
ok(defined $docs->[0][1]->{marc_format}, 'First document marc_format field should be set'); |
341 |
ok(defined $docs->[0][1]->{marc_format}, 'First document marc_format field should be set'); |
317 |
|
|
|
318 |
is($docs->[0][1]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly'); |
342 |
is($docs->[0][1]->{marc_format}, 'base64ISO2709', 'First document marc_format should be set correctly'); |
319 |
|
343 |
|
|
|
344 |
my $decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); |
345 |
|
346 |
ok($decoded_marc_record->isa('MARC::Record'), "base64ISO2709 record successfully decoded from result"); |
347 |
is($decoded_marc_record->as_usmarc(), $marc_record_1->as_usmarc(), "Decoded base64ISO2709 record has same data as original record"); |
348 |
|
320 |
is(scalar @{$docs->[0][1]->{type_of_record}}, 1, 'First document type_of_record field should have one value'); |
349 |
is(scalar @{$docs->[0][1]->{type_of_record}}, 1, 'First document type_of_record field should have one value'); |
321 |
is_deeply( |
350 |
is_deeply( |
322 |
$docs->[0][1]->{type_of_record}, |
351 |
$docs->[0][1]->{type_of_record}, |
Lines 376-379
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests'
Link Here
|
376 |
|
405 |
|
377 |
is($docs->[0][1]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); |
406 |
is($docs->[0][1]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly'); |
378 |
|
407 |
|
|
|
408 |
$decoded_marc_record = $see->decode_record_from_result($docs->[0][1]); |
409 |
|
410 |
ok($decoded_marc_record->isa('MARC::Record'), "MARCXML record successfully decoded from result"); |
411 |
is($decoded_marc_record->as_xml_record(), $large_marc_record->as_xml_record(), "Decoded MARCXML record has same data as original record"); |
412 |
|
413 |
push @mappings, { |
414 |
name => 'title', |
415 |
type => 'string', |
416 |
facet => 0, |
417 |
suggestible => 1, |
418 |
sort => 1, |
419 |
marc_type => 'marc21', |
420 |
marc_field => '245((ab)ab', |
421 |
}; |
422 |
|
423 |
my $exception = try { |
424 |
$see->marc_records_to_documents($records); |
425 |
} |
426 |
catch { |
427 |
return $_; |
428 |
}; |
429 |
|
430 |
ok(defined $exception, "Exception has been thrown when processing mapping with unmatched opening parenthesis"); |
431 |
ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class"); |
432 |
ok($exception->message =~ /Unmatched opening parenthesis/, "Exception has the correct message"); |
433 |
|
434 |
pop @mappings; |
435 |
push @mappings, { |
436 |
name => 'title', |
437 |
type => 'string', |
438 |
facet => 0, |
439 |
suggestible => 1, |
440 |
sort => 1, |
441 |
marc_type => 'marc21', |
442 |
marc_field => '245(ab))ab', |
443 |
}; |
444 |
|
445 |
$exception = try { |
446 |
$see->marc_records_to_documents($records); |
447 |
} |
448 |
catch { |
449 |
return $_; |
450 |
}; |
451 |
|
452 |
ok(defined $exception, "Exception has been thrown when processing mapping with unmatched closing parenthesis"); |
453 |
ok($exception->isa("Koha::Exceptions::Elasticsearch::MARCFieldExprParseError"), "Exception is of correct class"); |
454 |
ok($exception->message =~ /Unmatched closing parenthesis/, "Exception has the correct message"); |
379 |
}; |
455 |
}; |
380 |
- |
|
|