From ab1bed4f46632d8b69e2d82aa93710737e5b892a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 26 Feb 2021 14:28:16 +0000 Subject: [PATCH] Bug 27784: Unit tests Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 5e0dbf0adb63818b08ee77843706255dcaf00051) Signed-off-by: Fridolin Somers (cherry picked from commit e16cd2afc5a2e651ab3b0bf9ab2ff8c40f3c169f) Signed-off-by: Andrew Fuerste-Henry (cherry picked from commit 9dda7ba2d37293e962819c9755aa867cbfa6681d) Signed-off-by: Victor Grousset/tuxayo --- .../Koha/SearchEngine/Elasticsearch.t | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 3509fd1414..3a229fc65c 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -641,7 +641,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authority tests' => sub { - plan tests => 2; + plan tests => 4; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); @@ -662,6 +662,16 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori sort => 0, marc_type => 'marc21', marc_field => '150(ae)', + }, + { + name => 'match', + type => 'string', + facet => 0, + suggestible => 0, + searchable => 1, + sort => 0, + marc_type => 'marc21', + marc_field => '185v', } ); @@ -695,7 +705,11 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori $marc_record_2->append_fields( MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', z => 'Geosubdiv', x => 'Generalsubdiv', e => 'wrongsubdiv' ), ); - my $records = [ $marc_record_1, $marc_record_2 ]; + my $marc_record_3 = MARC::Record->new(); + $marc_record_3->append_fields( + MARC::Field->new('185', '', '', v => 'Formsubdiv' ), + ); + my $records = [ $marc_record_1, $marc_record_2, $marc_record_3 ]; $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first @@ -711,6 +725,13 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori @{$docs->[1]->{'match-heading'}}, "Second record match-heading should contain the correctly formatted heading without wrong subfield" ); + ok( !exists $docs->[2]->{'match-heading'}, "No match heading defined for subdivision record"); + is_deeply( + [ "Formsubdiv" ], + $docs->[2]->{'match'} , + "Third record heading should contain the subfield" + ); + }; $schema->storage->txn_rollback; -- 2.39.5