Lines 24-29
use Test::More tests => 5;
Link Here
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
|
|
27 |
use C4::AuthoritiesMarc qw/ AddAuthority ModAuthority /; |
28 |
|
27 |
BEGIN { |
29 |
BEGIN { |
28 |
use_ok( 'C4::Heading', qw( field valid_heading_subfield ) ); |
30 |
use_ok( 'C4::Heading', qw( field valid_heading_subfield ) ); |
29 |
} |
31 |
} |
Lines 66-72
subtest "UNIMARC tests" => sub {
Link Here
|
66 |
|
68 |
|
67 |
subtest "_search tests" => sub { |
69 |
subtest "_search tests" => sub { |
68 |
|
70 |
|
69 |
plan tests => 10; |
71 |
plan tests => 11; |
|
|
72 |
|
73 |
my $schema = Koha::Database->new->schema; |
74 |
$schema->storage->txn_begin; |
70 |
|
75 |
|
71 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
76 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
72 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); |
77 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' ); |
Lines 177-222
subtest "_search tests" => sub {
Link Here
|
177 |
"Search formed as expected for a non-subject field with double punctuation, period+comma " |
182 |
"Search formed as expected for a non-subject field with double punctuation, period+comma " |
178 |
); |
183 |
); |
179 |
|
184 |
|
|
|
185 |
# Special case where thesaurus defined in subfield 2 should also match record with no thesaurus |
186 |
my $auth_record_1 = MARC::Record->new(); |
187 |
$auth_record_1->insert_fields_ordered( MARC::Field->new( '008', ' ' x 10 . 'z' . ' ' x 29 ) ); |
188 |
$auth_record_1->insert_fields_ordered( MARC::Field->new( '150', ' ', ' ', a => 'Uncles', x => 'Fiction' ) ); |
189 |
my $authid_1 = AddAuthority( |
190 |
$auth_record_1, undef, 'TOPIC_TERM', |
191 |
{ skip_record_index => 1 } |
192 |
); |
193 |
|
180 |
$search->mock( |
194 |
$search->mock( |
181 |
'search_auth_compat', |
195 |
'search_auth_compat', |
182 |
sub { |
196 |
sub { |
183 |
my $self = shift; |
197 |
my $self = shift; |
184 |
my $search_query = shift; |
198 |
my $search_query = shift; |
185 |
if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 |
199 |
if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 ) { |
186 |
&& $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq |
200 |
if ( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq |
187 |
'special_sauce' ) |
201 |
'special_sauce' ) |
188 |
{ |
202 |
{ |
189 |
return; |
203 |
# no record with 'special_sauce' |
|
|
204 |
return ( [], 0 ); |
205 |
} elsif ( |
206 |
$search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'z' ) |
207 |
{ |
208 |
# for 'notdefined' we return the only record with 008/11 = 'z' |
209 |
return ( [ { authid => $authid_1 } ], 1 ); |
210 |
} else { |
211 |
|
212 |
# other cases - nothing |
213 |
return ( [], 0 ); |
214 |
} |
215 |
} elsif ( scalar @{ $search_query->{query}->{bool}->{must} } == 1 ) { |
216 |
return ['no thesaurus checking at all']; |
190 |
} |
217 |
} |
191 |
return ( $search_query, 1 ); |
|
|
192 |
} |
218 |
} |
193 |
); |
219 |
); |
194 |
|
220 |
|
195 |
# Special case where thesaurus defined in subfield 2 should also match record with no thesaurus |
|
|
196 |
$field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); |
221 |
$field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' ); |
197 |
$heading = C4::Heading->new_from_field($field); |
222 |
$heading = C4::Heading->new_from_field($field); |
198 |
($search_query) = $heading->_search('match-heading'); |
223 |
my ($matched_auths) = $heading->_search('match-heading'); |
199 |
$terms = $search_query->{query}->{bool}->{must}; |
224 |
my $expected_result = [ { authid => $authid_1 } ]; |
200 |
$expected_terms = [ |
|
|
201 |
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, |
202 |
{ term => { 'subject-heading-thesaurus.ci_raw' => 'z' } }, |
203 |
]; |
204 |
is_deeply( |
225 |
is_deeply( |
205 |
$terms, $expected_terms, |
226 |
$matched_auths, $expected_result, |
206 |
"When thesaurus in subfield 2, and nothing is found, we should search again for notdefined (008_11 = z) " |
227 |
"When thesaurus in subfield 2, and nothing is found, we should search again for notdefined (008_11 = z) and get a result" |
|
|
228 |
); |
229 |
|
230 |
# Special case continued: but it should not match an authority record with a different thesaurus |
231 |
# defined in 040 $f |
232 |
$auth_record_1->insert_fields_ordered( MARC::Field->new( '040', ' ', ' ', f => 'special_sauce_2' ) ); |
233 |
$authid_1 = ModAuthority( |
234 |
$authid_1, $auth_record_1, 'TOPIC_TERM', |
235 |
{ skip_record_index => 1 } |
236 |
); |
237 |
|
238 |
($matched_auths) = $heading->_search('match-heading'); |
239 |
$expected_result = []; |
240 |
is_deeply( |
241 |
$matched_auths, $expected_result, |
242 |
'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' |
207 |
); |
243 |
); |
208 |
|
244 |
|
|
|
245 |
# When LinkerConsiderThesaurus off, no attantion is being paid on the thesaurus |
209 |
t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); |
246 |
t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' ); |
210 |
|
247 |
|
211 |
$search_query = undef; |
248 |
($matched_auths) = $heading->_search('match-heading'); |
212 |
($search_query) = $heading->_search('match-heading'); |
249 |
$expected_result = ['no thesaurus checking at all']; |
213 |
$terms = $search_query->{query}->{bool}->{must}; |
|
|
214 |
$expected_terms = [ |
215 |
{ term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } }, |
216 |
]; |
217 |
is_deeply( |
250 |
is_deeply( |
218 |
$terms, $expected_terms, |
251 |
$matched_auths, $expected_result, |
219 |
"When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled" |
252 |
"When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurus disabled" |
220 |
); |
253 |
); |
221 |
|
254 |
|
|
|
255 |
$schema->storage->txn_rollback; |
222 |
}; |
256 |
}; |
223 |
- |
|
|