Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 24; |
20 |
use Test::More tests => 25; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use List::MoreUtils qw( uniq ); |
23 |
use List::MoreUtils qw( uniq ); |
Lines 29-34
use t::lib::TestBuilder;
Link Here
|
29 |
use Koha::ActionLogs; |
29 |
use Koha::ActionLogs; |
30 |
use Koha::Database; |
30 |
use Koha::Database; |
31 |
use Koha::Caches; |
31 |
use Koha::Caches; |
|
|
32 |
use Koha::Cache::Memory::Lite; |
32 |
use Koha::MarcSubfieldStructures; |
33 |
use Koha::MarcSubfieldStructures; |
33 |
|
34 |
|
34 |
use C4::Linker::Default qw( get_link ); |
35 |
use C4::Linker::Default qw( get_link ); |
Lines 229-234
subtest "Authority creation with default linker" => sub {
Link Here
|
229 |
ok( !defined $results->{added}, "If we have multiple matches, we shouldn't create a new record on second instance"); |
230 |
ok( !defined $results->{added}, "If we have multiple matches, we shouldn't create a new record on second instance"); |
230 |
}; |
231 |
}; |
231 |
|
232 |
|
|
|
233 |
subtest "Test caching of authority types in LinkBibHeadingsToAuthorities" => sub { |
234 |
plan tests => 3; |
235 |
Koha::Cache::Memory::Lite->flush(); #Clear cache like we have a new request |
236 |
my $cache = Koha::Cache::Memory::Lite->get_instance(); |
237 |
|
238 |
# No automatic authority creation |
239 |
t::lib::Mocks::mock_preference( 'LinkerModule', 'Default' ); |
240 |
t::lib::Mocks::mock_preference( 'AutoLinkBiblios', 1 ); |
241 |
t::lib::Mocks::mock_preference( 'AutoCreateAuthorities', 0 ); |
242 |
t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); |
243 |
my $linker = C4::Linker::Default->new( {} ); |
244 |
my $authorities_mod = Test::MockModule->new('C4::Heading'); |
245 |
$authorities_mod->mock( |
246 |
'authorities', |
247 |
sub { |
248 |
my $results = []; |
249 |
return $results; |
250 |
} |
251 |
); |
252 |
my $authorities_type = Test::MockModule->new('Koha::Authority::Types'); |
253 |
$authorities_type->mock( |
254 |
'find', |
255 |
sub { |
256 |
my ( $self, $params ) = @_; |
257 |
warn "Finding auth type $params"; |
258 |
return $authorities_type->original("find")->( $self, $params ); |
259 |
} |
260 |
); |
261 |
my $marc_record = MARC::Record->new(); |
262 |
my $field1 = MARC::Field->new( 655, ' ', ' ', 'a' => 'Magical realism' ); |
263 |
my $field2 = MARC::Field->new( 655, ' ', ' ', 'a' => 'Magical falsism' ); |
264 |
$marc_record->append_fields( ( $field1, $field2 ) ); |
265 |
my ( $num_changed, $results ); |
266 |
warning_like { ( $num_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $marc_record, "", undef ) } |
267 |
qr/Finding auth type GENRE\/FORM/, |
268 |
"Type fetched only once"; |
269 |
my $gf_type = $cache->get_from_cache("LinkBibHeadingsToAuthorities:AuthorityType:GENRE/FORM"); |
270 |
ok( $gf_type, "GENRE/FORM type is found in cache" ); |
271 |
|
272 |
warning_like { ( $num_changed, $results ) = LinkBibHeadingsToAuthorities( $linker, $marc_record, "", undef ) } |
273 |
undef, |
274 |
"Type not fetched a second time"; |
275 |
|
276 |
}; |
277 |
|
232 |
|
278 |
|
233 |
|
279 |
|
234 |
# Mocking variables |
280 |
# Mocking variables |
Lines 280-285
$currency->mock(
Link Here
|
280 |
|
326 |
|
281 |
sub run_tests { |
327 |
sub run_tests { |
282 |
|
328 |
|
|
|
329 |
Koha::Cache::Memory::Lite->flush(); #Clear cache like we have a new request |
283 |
my $marcflavour = shift; |
330 |
my $marcflavour = shift; |
284 |
t::lib::Mocks::mock_preference('marcflavour', $marcflavour); |
331 |
t::lib::Mocks::mock_preference('marcflavour', $marcflavour); |
285 |
# Authority tests don't interact well with Elasticsearch at the moment due to the fact that there's currently no way to |
332 |
# Authority tests don't interact well with Elasticsearch at the moment due to the fact that there's currently no way to |
Lines 465-471
sub run_tests {
Link Here
|
465 |
is( @$marcurl, 2, 'GetMarcUrls returns two URLs' ); |
512 |
is( @$marcurl, 2, 'GetMarcUrls returns two URLs' ); |
466 |
like( $marcurl->[0]->{MARCURL}, qr/^https/, 'GetMarcUrls did not stumble over a preceding space' ); |
513 |
like( $marcurl->[0]->{MARCURL}, qr/^https/, 'GetMarcUrls did not stumble over a preceding space' ); |
467 |
ok( $marcflavour ne 'MARC21' || $marcurl->[1]->{MARCURL} =~ /^http:\/\//, |
514 |
ok( $marcflavour ne 'MARC21' || $marcurl->[1]->{MARCURL} =~ /^http:\/\//, |
468 |
'GetMarcUrls prefixed a MARC21 URL with http://' ); |
515 |
"GetMarcUrls prefixed a $marcflavour URL with http://" ); |
469 |
|
516 |
|
470 |
# Automatic authority creation |
517 |
# Automatic authority creation |
471 |
t::lib::Mocks::mock_preference('AutoLinkBiblios', 1); |
518 |
t::lib::Mocks::mock_preference('AutoLinkBiblios', 1); |
Lines 514-519
sub run_tests {
Link Here
|
514 |
# Reset settings |
561 |
# Reset settings |
515 |
t::lib::Mocks::mock_preference('AutoLinkBiblios', 0); |
562 |
t::lib::Mocks::mock_preference('AutoLinkBiblios', 0); |
516 |
t::lib::Mocks::mock_preference('AutoCreateAuthorities', 0); |
563 |
t::lib::Mocks::mock_preference('AutoCreateAuthorities', 0); |
|
|
564 |
Koha::Cache::Memory::Lite->flush(); # Since we may have changed flavours |
517 |
} |
565 |
} |
518 |
|
566 |
|
519 |
sub get_title_field { |
567 |
sub get_title_field { |
520 |
- |
|
|