Bugzilla – Attachment 180903 Details for
Bug 39503
Linker should always respect thesaurus with LinkerConsiderThesaurus on
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39503: Unit tests
Bug-39503-Unit-tests.patch (text/plain), 6.54 KB, created by
Janusz Kaczmarek
on 2025-04-14 11:37:12 UTC
(
hide
)
Description:
Bug 39503: Unit tests
Filename:
MIME Type:
Creator:
Janusz Kaczmarek
Created:
2025-04-14 11:37:12 UTC
Size:
6.54 KB
patch
obsolete
>From f59b7bb88d3bf97b5e8859384c7f147a70ec94e4 Mon Sep 17 00:00:00 2001 >From: Janusz Kaczmarek <januszop@gmail.com> >Date: Tue, 1 Apr 2025 11:20:13 +0000 >Subject: [PATCH] Bug 39503: Unit tests > >NB, some previous test had to be adjusted to make it posible to call >search_auth_compat in _search and properly interpret its results. > >Signed-off-by: Roman Dolny <roman.dolny@jezuici.pl> >--- > t/db_dependent/Heading.t | 97 +++++++++++++++++++++++++++++----------- > 1 file changed, 71 insertions(+), 26 deletions(-) > >diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t >index 9e0cd90e3b..8ff1ab260d 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 => 10; >+ plan tests => 11; > > t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); > t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); >@@ -184,48 +184,93 @@ subtest "_search tests" => sub { > "Search formed as expected for a non-subject field with double punctuation, period+comma " > ); > >+ # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus >+ # In the ES index an auth rec. without 040 $f, so 'z' from 008/11 is present in subject-heading-thesaurus >+ my $expected_authid = 12345; > $search->mock( > 'search_auth_compat', > sub { > my $self = shift; > my $search_query = shift; >- if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 >- && $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq >- 'special_sauce' ) >- { >- return; >+ if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 ) { >+ if ( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq >+ 'special_sauce' ) >+ { >+ # no record with 'special_sauce' >+ return ( [], 0 ); >+ } elsif ( >+ $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'z' ) >+ { >+ # for 'notdefined' we return the only record with 008/11 = 'z' >+ return ( [ { authid => $expected_authid } ], 1 ); >+ } else { >+ >+ # other cases - nothing >+ return ( [], 0 ); >+ } >+ } elsif ( scalar @{ $search_query->{query}->{bool}->{must} } == 1 ) { >+ return ['no thesaurus checking at all']; > } >- return ( $search_query, 1 ); > } > ); >- >- # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus > $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); > $heading = C4::Heading->new_from_field($field); >- ($search_query) = $heading->_search('match-heading'); >- $terms = $search_query->{query}->{bool}->{must}; >- $expected_terms = [ >- { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, >- { term => { 'subject-heading-thesaurus.ci_raw' => 'z' } }, >- ]; >+ my ($matched_auths) = $heading->_search('match-heading'); >+ my $expected_result = [ { authid => $expected_authid } ]; > is_deeply( >- $terms, $expected_terms, >- "When thesaurus in subfield 2, and nothing is found, we should search again for notdefined (008_11 = z) " >+ $matched_auths, $expected_result, >+ "When thesaurus in subfield 2, we should search again for notdefined (008_11 = z) and get a result" > ); > >- t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); >+ # In the ES index an auth rec. with 040 $f 'special_sauce', so 'z' from 008/11 not present in subject-heading-thesaurus >+ $search->mock( >+ 'search_auth_compat', >+ sub { >+ my $self = shift; >+ my $search_query = shift; >+ if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 ) { >+ if ( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq >+ 'special_sauce' ) >+ { >+ # no record with 'special_sauce' >+ return ( [ { authid => $expected_authid } ], 1 ); >+ } elsif ( >+ $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'z' ) >+ { >+ # for 'notdefined' we return the only record with 008/11 = 'z' >+ return ( [], 0 ); >+ } else { >+ >+ # other cases - nothing >+ return ( [], 0 ); >+ } >+ } elsif ( scalar @{ $search_query->{query}->{bool}->{must} } == 1 ) { >+ return ['no thesaurus checking at all']; >+ } >+ } >+ ); > >- $search_query = undef; >- ($search_query) = $heading->_search('match-heading'); >- $terms = $search_query->{query}->{bool}->{must}; >- $expected_terms = [ >- { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, >- ]; >+ # Special case continued: but it should not match an authority record with a different thesaurus >+ # defined in 040 $f >+ $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce_2' ); >+ $heading = C4::Heading->new_from_field($field); >+ >+ ($matched_auths) = $heading->_search('match-heading'); >+ $expected_result = []; > is_deeply( >- $terms, $expected_terms, >- "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled" >+ $matched_auths, $expected_result, >+ 'When thesaurus in subfield 2, and nothing is found, we search again for notdefined (008_11 = z), and get no results because 040 $f with different value exists in the auth rec.' > ); > >+ # When LinkerConsiderThesaurus off, no attantion is being paid on the thesaurus >+ t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); >+ >+ ($matched_auths) = $heading->_search('match-heading'); >+ $expected_result = ['no thesaurus checking at all']; >+ is_deeply( >+ $matched_auths, $expected_result, >+ "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurus disabled" >+ ); > }; > > subtest "authorities exact match tests" => sub { >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39503
:
180082
|
180131
|
180200
|
180201
|
180844
|
180902
|
180903
|
180940
|
180941
|
181205
|
182182
|
182183