From 3ffe4248a153ee0d07ffc3cc08bd4dd02b0d8448 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Fri, 15 Oct 2021 07:10:51 +0000 Subject: [PATCH] Bug 29191: Don't include subdivision names in heading search form with Elasticsearch --- C4/Heading/MARC21.pm | 3 ++- C4/Heading/UNIMARC.pm | 3 ++- t/db_dependent/Heading_MARC21.t | 46 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/C4/Heading/MARC21.pm b/C4/Heading/MARC21.pm index 011d16268c..01770c6bbb 100644 --- a/C4/Heading/MARC21.pm +++ b/C4/Heading/MARC21.pm @@ -411,7 +411,8 @@ sub _get_search_heading { $heading = $value; } else { - if ( exists $subdivisions{$code} ) { + if ( exists $subdivisions{$code} + && C4::Context->preference('SearchEngine') eq 'Zebra' ) { $heading .= " $subdivisions{$code} $value"; } else { diff --git a/C4/Heading/UNIMARC.pm b/C4/Heading/UNIMARC.pm index 9767f751a7..a8e0ae021f 100644 --- a/C4/Heading/UNIMARC.pm +++ b/C4/Heading/UNIMARC.pm @@ -166,7 +166,8 @@ sub _get_search_heading { $heading = $value; } else { - if ( exists $subdivisions{$code} ) { + if ( exists $subdivisions{$code} + && C4::Context->preference('SearchEngine') eq 'Zebra' ) { $heading .= " $subdivisions{$code} $value"; } else { diff --git a/t/db_dependent/Heading_MARC21.t b/t/db_dependent/Heading_MARC21.t index 357d3126d4..be1a2e63b4 100755 --- a/t/db_dependent/Heading_MARC21.t +++ b/t/db_dependent/Heading_MARC21.t @@ -7,14 +7,19 @@ use strict; use warnings; use Test::More tests => 5; +use t::lib::Mocks qw( mock_preference ); use C4::Context; BEGIN { use_ok('C4::Heading', qw( field new_from_field display_form search_form )); } -SKIP: { - skip "MARC21 heading tests not applicable to UNIMARC", 2 if C4::Context->preference('marcflavour') eq 'UNIMARC'; +subtest 'Search MARC21 heading with Zebra search engine' => sub { + plan tests => 4; + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); + my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); my $heading = C4::Heading->new_from_field($field); is($heading->display_form(), 'Uncles--Fiction', 'Display form generation'); @@ -24,5 +29,40 @@ SKIP: { $heading = C4::Heading->new_from_field($field); is($heading->display_form(), 'The dark is rising ;', 'Display form generation'); is($heading->search_form(), 'The dark is rising', 'Search form generation'); +}; -} +subtest 'Search UNIMARC heading with Zebra search engine' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); + t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); + + my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); + my $heading = C4::Heading->new_from_field($field); + is($heading->display_form(), 'Uncles--Fiction', 'Display form generation'); + is($heading->search_form(), 'Uncles generalsubdiv Fiction', 'Search form generation'); +}; + +subtest 'Search MARC21 heading with Elasticsearch search engine' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); + t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); + + my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); + my $heading = C4::Heading->new_from_field($field); + is($heading->display_form(), 'Uncles--Fiction', 'Display form generation'); + is($heading->search_form(), 'Uncles Fiction', 'Search form generation'); +}; + +subtest 'Search UNIMARC heading with Elasticsearch search engine' => sub { + plan tests => 2; + + t::lib::Mocks::mock_preference( 'marcflavour', 'UNIMARC' ); + t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); + + my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); + my $heading = C4::Heading->new_from_field($field); + is($heading->display_form(), 'Uncles--Fiction', 'Display form generation'); + is($heading->search_form(), 'Uncles Fiction', 'Search form generation'); +}; -- 2.11.0