diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 8db9e9a663..79c198c3f2 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -132,7 +132,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub { subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { - plan tests => 61; + plan tests => 63; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); @@ -318,7 +318,16 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' marc_type => 'marc21', marc_field => '008_/7-10', }, - + { + name => 'subject', + type => 'string', + facet => 0, + suggestible => 0, + searchable => 1, + sort => 1, + marc_type => 'marc21', + marc_field => '650(avxyz)', + }, ); my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); @@ -358,6 +367,8 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' MARC::Field->new('240', '', '4', a => 'The uniform title with nonfiling indicator'), MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => 'c1962'), + MARC::Field->new('650', '', '', a => 'Heading', z => 'Geohead', v => 'Formhead'), + MARC::Field->new('650', '', '', a => 'Heading', x => 'Gensubhead', z => 'Geohead'), MARC::Field->new('999', '', '', c => '1234567'), # ' ' for testing trimming of white space in boolean value callback: MARC::Field->new('952', '', '', 0 => ' ', g => '123.30', o => $callno, l => 3), @@ -403,6 +414,9 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' is(scalar @{$docs->[0]->{author}}, 2, 'First document author field should contain two values'); is_deeply($docs->[0]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); + is(scalar @{$docs->[0]->{subject}}, 2, 'First document subject field should contain two values'); + is_deeply($docs->[0]->{subject}, ['Heading Geohead Formhead', 'Heading Gensubhead Geohead'], 'First document asubject field should be set correctly, record order preserved for grouped subfield mapping'); + is(scalar @{$docs->[0]->{author__sort}}, 1, 'First document author__sort field should have a single value'); is_deeply($docs->[0]->{author__sort}, ['Author 1 Corp Author'], 'First document author__sort field should be set correctly'); @@ -733,7 +747,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 => 3; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); @@ -753,7 +767,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori searchable => 1, sort => 0, marc_type => 'marc21', - marc_field => '150(ae)', + marc_field => '150(aevxyz)', } ); @@ -793,16 +807,21 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori my $docs = $see->marc_records_to_documents($records); - ok( - any { $_ eq "Subject formsubdiv Genresubdiv generalsubdiv Generalsubdiv geographicsubdiv Geosubdiv" } - @{$docs->[0]->{'match-heading'}}, + is_deeply( + [ "Subject formsubdiv Genresubdiv generalsubdiv Generalsubdiv geographicsubdiv Geosubdiv" ], + $docs->[0]->{'match-heading'}, "First record match-heading should contain the correctly formatted heading" ); - ok( - any { $_ eq "Subject formsubdiv Genresubdiv geographicsubdiv Geosubdiv generalsubdiv Generalsubdiv" } - @{$docs->[1]->{'match-heading'}}, + is_deeply( + [ "Subject formsubdiv Genresubdiv geographicsubdiv Geosubdiv generalsubdiv Generalsubdiv" ], + $docs->[1]->{'match-heading'}, "Second record match-heading should contain the correctly formatted heading without wrong subfield" ); + is_deeply( + [ "Subject Genresubdiv Geosubdiv Generalsubdiv wrongsubdiv" ], + $docs->[1]->{'match'} , + "Second record heading should contain the subfields with record order retained" + ); }; $schema->storage->txn_rollback;