From 56eb9faa2e234d401e45fd2a56471949e10ab8bb Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Fri, 23 May 2025 10:48:07 +0000 Subject: [PATCH] Bug 33296: Unit tests Unit tests for Bug 33296. Signed-off-by: Roman Dolny --- t/db_dependent/Heading.t | 63 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t index 8ff1ab260d..3224bd0d9d 100755 --- a/t/db_dependent/Heading.t +++ b/t/db_dependent/Heading.t @@ -73,7 +73,7 @@ subtest "UNIMARC tests" => sub { subtest "_search tests" => sub { - plan tests => 11; + plan tests => 15; t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); @@ -93,6 +93,7 @@ subtest "_search tests" => sub { ); t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); + t::lib::Mocks::mock_preference( 'ConsiderHeadingUse', '0' ); my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' ); my $heading = C4::Heading->new_from_field($field); @@ -271,6 +272,66 @@ subtest "_search tests" => sub { $matched_auths, $expected_result, "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurus disabled" ); + + # return to the "original" mocked version of search_auth_compat: + $search->mock( + 'search_auth_compat', + sub { + my $self = shift; + my $search_query = shift; + return ( $search_query, 1 ); + } + ); + t::lib::Mocks::mock_preference( 'ConsiderHeadingUse', '1' ); + + ($search_query) = $heading->_search('match-heading'); + $terms = $search_query->{query}->{bool}->{must}; + $expected_terms = [ + { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, + { term => { 'heading-use-subject-added-entry.ci_raw' => 'a' } }, + ]; + is_deeply( + $terms, $expected_terms, + "With ConsiderHeadingUse on and 650 tag Heading-use-subject-added-entry = 'a' is required in search query" + ); + + my $field_700 = MARC::Field->new( '700', '1', '2', a => 'Shakespeare William', t => 'Othello' ); + my $heading_700 = C4::Heading->new_from_field($field_700); + ($search_query) = $heading_700->_search('match-heading'); + $terms = $search_query->{query}->{bool}->{must}; + $expected_terms = [ + { term => { 'match-heading.ci_raw' => 'Shakespeare William Othello' } }, + { term => { 'heading-use-main-or-added-entry.ci_raw' => 'a' } }, + ]; + is_deeply( + $terms, $expected_terms, + "With ConsiderHeadingUse on and 700 tag Heading-use-main-or-added-entry = 'a' is required in search query" + ); + + my $field_800 = MARC::Field->new( '800', '1', ' ', a => 'Shakespeare William', t => 'Collected works' ); + my $heading_800 = C4::Heading->new_from_field($field_800); + ($search_query) = $heading_800->_search('match-heading'); + $terms = $search_query->{query}->{bool}->{must}; + $expected_terms = [ + { term => { 'match-heading.ci_raw' => 'Shakespeare William Collected works' } }, + { term => { 'heading-use-series-added-entry.ci_raw' => 'a' } }, + ]; + is_deeply( + $terms, $expected_terms, + "With ConsiderHeadingUse on and 800 tag Heading-use-series-added-entry = 'a' is required in search query" + ); + + t::lib::Mocks::mock_preference( 'ConsiderHeadingUse', '0' ); + + ($search_query) = $heading_800->_search('match-heading'); + $terms = $search_query->{query}->{bool}->{must}; + $expected_terms = [ + { term => { 'match-heading.ci_raw' => 'Shakespeare William Collected works' } }, + ]; + is_deeply( + $terms, $expected_terms, + "With ConsiderHeadingUse off and 800 tag there is no Heading-use-series-added-entry condition in search query" + ); }; subtest "authorities exact match tests" => sub { -- 2.39.5