Bugzilla – Attachment 180131 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), 5.82 KB, created by
Janusz Kaczmarek
on 2025-04-01 11:24:28 UTC
(
hide
)
Description:
Bug 39503: Unit tests
Filename:
MIME Type:
Creator:
Janusz Kaczmarek
Created:
2025-04-01 11:24:28 UTC
Size:
5.82 KB
patch
obsolete
>From b186d8901f32e276b407f1b5716490069c0b2fd7 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. >--- > t/db_dependent/Heading.t | 82 ++++++++++++++++++++++++++++------------ > 1 file changed, 58 insertions(+), 24 deletions(-) > >diff --git a/t/db_dependent/Heading.t b/t/db_dependent/Heading.t >index 1356bca8a0..e93750a5f5 100755 >--- a/t/db_dependent/Heading.t >+++ b/t/db_dependent/Heading.t >@@ -24,6 +24,8 @@ use Test::More tests => 5; > use t::lib::Mocks; > use Test::MockModule; > >+use C4::AuthoritiesMarc qw/ AddAuthority ModAuthority /; >+ > BEGIN { > use_ok( 'C4::Heading', qw( field valid_heading_subfield ) ); > } >@@ -66,7 +68,10 @@ subtest "UNIMARC tests" => sub { > > subtest "_search tests" => sub { > >- plan tests => 10; >+ plan tests => 11; >+ >+ my $schema = Koha::Database->new->schema; >+ $schema->storage->txn_begin; > > t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); > t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); >@@ -177,46 +182,75 @@ 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 >+ my $auth_record_1 = MARC::Record->new(); >+ $auth_record_1->insert_fields_ordered( MARC::Field->new( '008', ' ' x 10 . 'z' . ' ' x 29 ) ); >+ $auth_record_1->insert_fields_ordered( MARC::Field->new( '150', ' ', ' ', a => 'Uncles', x => 'Fiction' ) ); >+ my $authid_1 = AddAuthority( >+ $auth_record_1, undef, 'TOPIC_TERM', >+ { skip_record_index => 1 } >+ ); >+ > $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 => $authid_1 } ], 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 => $authid_1 } ]; > 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, and nothing is found, we should search again for notdefined (008_11 = z) and get a result" >+ ); >+ >+ # Special case continued: but it should not match an authority record with a different thesaurus >+ # defined in 040 $f >+ $auth_record_1->insert_fields_ordered( MARC::Field->new( '040', ' ', ' ', f => 'special_sauce_2' ) ); >+ $authid_1 = ModAuthority( >+ $authid_1, $auth_record_1, 'TOPIC_TERM', >+ { skip_record_index => 1 } >+ ); >+ >+ ($matched_auths) = $heading->_search('match-heading'); >+ $expected_result = []; >+ is_deeply( >+ $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 biblio\'s subfield $2 does not conform to auth\'s 040 $f' > ); > >+ # When LinkerConsiderThesaurus off, no attantion is being paid on the thesaurus > t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); > >- $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' } }, >- ]; >+ ($matched_auths) = $heading->_search('match-heading'); >+ $expected_result = ['no thesaurus checking at all']; > 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 don't search again if LinkerConsiderThesaurus disabled" > ); > >+ $schema->storage->txn_rollback; > }; >-- >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