From 93b8ab42e208df0cbcb10dea07626f919ad227a0 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 16 Sep 2020 11:31:48 +0000 Subject: [PATCH] Bug 23828: Unit tests Signed-off-by: Heather Hernandez --- t/db_dependent/Koha/SearchEngine/Elasticsearch.t | 42 +++++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 96c8eda321..8808670497 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -318,7 +318,20 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' marc_type => 'marc21', marc_field => '008_/7-10', }, +<<<<<<< HEAD +======= + { + name => 'subject', + type => 'string', + facet => 0, + suggestible => 0, + searchable => 1, + sort => 1, + marc_type => 'marc21', + marc_field => '650(avxyz)', + }, +>>>>>>> Bug 23828: Unit tests ); my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); @@ -357,7 +370,12 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' MARC::Field->new('210', '', '', a => 'Title 1'), MARC::Field->new('240', '', '4', a => 'The uniform title with nonfiling indicator'), MARC::Field->new('245', '', '', a => 'Title:', b => 'first record'), +<<<<<<< HEAD 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'), +>>>>>>> Bug 23828: Unit tests 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 +421,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'); @@ -718,7 +739,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'); @@ -738,7 +759,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)', } ); @@ -778,16 +799,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; -- 2.11.0