From 54d9eab353d4f498c5d3fdc0d92a0fa736ca9078 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Thu, 16 Apr 2020 14:51:13 +0200 Subject: [PATCH] Bug 24807: Update tests Signed-off-by: Nick Clemens --- t/Koha/SearchEngine/Elasticsearch.t | 39 +++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/t/Koha/SearchEngine/Elasticsearch.t b/t/Koha/SearchEngine/Elasticsearch.t index 319dce8e15..9d9871a48d 100644 --- a/t/Koha/SearchEngine/Elasticsearch.t +++ b/t/Koha/SearchEngine/Elasticsearch.t @@ -118,7 +118,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub { subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { - plan tests => 56; + plan tests => 58; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); t::lib::Mocks::mock_preference('ElasticsearchMARCFormat', 'ISO2709'); @@ -283,8 +283,18 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' sort => 1, marc_type => 'marc21', marc_field => '952l', - }, - { + }, + { + name => 'copydate', + type => 'year', + facet => 0, + suggestible => 0, + searchable => 1, + sort => 1, + marc_type => 'marc21', + marc_field => '260c', + }, + { name => 'date-of-publication', type => 'year', facet => 0, @@ -333,6 +343,7 @@ 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'), + MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => 'c1962'), 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), @@ -469,10 +480,16 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' 'First document uniform_title__sort field should contain the title with the first four initial characters removed' ); - # Tests for 'year' type and 'filter_callbacks' + # Tests for 'year' type is(scalar @{$docs->[0]->{'date-of-publication'}}, 1, 'First document date-of-publication field should contain one value'); is_deeply($docs->[0]->{'date-of-publication'}, ['1962'], 'First document date-of-publication field should be set correctly'); + is_deeply( + $docs->[0]->{'copydate'}, + ['1962'], + 'First document copydate field should be set correctly' + ); + # Second record: is(scalar @{$docs->[1]->{author}}, 1, 'Second document author field should contain one value'); @@ -497,8 +514,17 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' 'Second document local_classification__sort field should be set correctly' ); - # Tests for 'year' type and 'filter_callbacks' - ok(!(defined $docs->[1]->{'date-of-publication'}), "Second document invalid date-of-publication value should have been removed"); + # Tests for 'year' type + is_deeply( + $docs->[1]->{'copydate'}, + ['1963','2003'], + 'Second document copydate field should be set correctly' + ); + is_deeply( + $docs->[1]->{'date-of-publication'}, + ['1900'], + 'Second document date-of-publication field should be set correctly' + ); # Mappings marc_type: @@ -633,6 +659,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t MARC::Field->new('100', '', '', a => 'Author 2'), # MARC::Field->new('210', '', '', a => 'Title 2'), # MARC::Field->new('245', '', '', a => 'Title: second record'), + MARC::Field->new('260', '', '', a => 'New York :', b => 'Ace ,', c => '1963-2003'), MARC::Field->new('999', '', '', c => '1234568'), MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'), ); -- 2.11.0