Lines 19-29
use strict;
Link Here
|
19 |
use warnings; |
19 |
use warnings; |
20 |
|
20 |
|
21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
|
|
23 |
|
24 |
use open qw/ :std :utf8 /; |
23 |
|
25 |
|
24 |
use t::lib::Mocks; |
26 |
use t::lib::Mocks; |
25 |
use Test::MockModule; |
27 |
use Test::MockModule; |
26 |
|
28 |
|
|
|
29 |
use MARC::Record; |
30 |
use MARC::Field; |
31 |
use utf8; |
32 |
use C4::AuthoritiesMarc qw/ AddAuthority /; |
33 |
|
27 |
BEGIN { |
34 |
BEGIN { |
28 |
use_ok( 'C4::Heading', qw( field valid_heading_subfield ) ); |
35 |
use_ok( 'C4::Heading', qw( field valid_heading_subfield ) ); |
29 |
} |
36 |
} |
Lines 220-222
subtest "_search tests" => sub {
Link Here
|
220 |
); |
227 |
); |
221 |
|
228 |
|
222 |
}; |
229 |
}; |
223 |
- |
230 |
|
|
|
231 |
subtest "authorities exact match tests" => sub { |
232 |
|
233 |
plan tests => 3; |
234 |
|
235 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
236 |
|
237 |
my $schema = Koha::Database->new->schema; |
238 |
$schema->storage->txn_begin; |
239 |
|
240 |
my $authrec1 = MARC::Record->new; |
241 |
$authrec1->leader(' nz a22 o 4500'); |
242 |
$authrec1->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Rakowski, Albin', x => 'poetry' ) ); |
243 |
my $authid1 = AddAuthority( $authrec1, undef, 'PERSO_NAME', { skip_record_index => 1 } ); |
244 |
|
245 |
my $authrec2 = MARC::Record->new; |
246 |
$authrec2->leader(' nz a22 o 4500'); |
247 |
$authrec2->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Rąkowski, Albin', x => 'poetry' ) ); |
248 |
my $authid2 = AddAuthority( $authrec2, undef, 'PERSO_NAME', { skip_record_index => 1 } ); |
249 |
|
250 |
my $heading = Test::MockModule->new('C4::Heading'); |
251 |
$heading->mock( |
252 |
'_search', |
253 |
sub { |
254 |
my $self = shift; |
255 |
return ( [ { authid => $authid1 }, { authid => $authid2 } ], 2 ); |
256 |
} |
257 |
); |
258 |
|
259 |
my $biblio_field = MARC::Field->new( '600', '1', '1', a => 'Rakowski, Albin', x => 'poetry' ); |
260 |
my $biblio_heading = C4::Heading->new_from_field($biblio_field); |
261 |
|
262 |
t::lib::Mocks::mock_preference( 'LinkerConsiderDiacritics', '0' ); |
263 |
|
264 |
my $authorities = $biblio_heading->authorities(1); |
265 |
is_deeply( |
266 |
$authorities, [ { authid => $authid1 }, { authid => $authid2 } ], |
267 |
"Authorities diacritics filter off - two authids returned for authority search 'Rakowski' from biblio 600 field 'Rakowski'" |
268 |
); |
269 |
|
270 |
t::lib::Mocks::mock_preference( 'LinkerConsiderDiacritics', '1' ); |
271 |
|
272 |
$authorities = $biblio_heading->authorities(1); |
273 |
is_deeply( |
274 |
$authorities, [ { authid => $authid1 } ], |
275 |
"Authorities filter OK - remained authority 'Rakowski' for biblio 'Rakowski'" |
276 |
); |
277 |
|
278 |
my $authrec3 = MARC::Record->new; |
279 |
$authrec3->leader(' nz a22 o 4500'); |
280 |
$authrec3->insert_fields_ordered( MARC::Field->new( '100', '1', ' ', a => 'Bruckner, Karl' ) ); |
281 |
my $authid3 = AddAuthority( $authrec3, undef, 'PERSO_NAME', { skip_record_index => 1 } ); |
282 |
|
283 |
$heading->mock( |
284 |
'_search', |
285 |
sub { |
286 |
my $self = shift; |
287 |
return ( [ { authid => $authid3 } ], 1 ); |
288 |
} |
289 |
); |
290 |
|
291 |
$biblio_field = MARC::Field->new( '700', '1', ' ', a => 'Brückner, Karl' ); |
292 |
$biblio_heading = C4::Heading->new_from_field($biblio_field); |
293 |
|
294 |
$authorities = $biblio_heading->authorities(1); |
295 |
is_deeply( $authorities, [], "Authorities filter OK - 'Brückner' not matched with 'Bruckner'" ); |
296 |
|
297 |
$schema->storage->txn_rollback; |
298 |
|
299 |
}; |