Lines 17-30
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 14; |
20 |
use Test::More tests => 15; |
21 |
|
21 |
|
22 |
use C4::Biblio; |
22 |
use C4::Biblio; |
23 |
use Koha::Database; |
23 |
use Koha::Database; |
24 |
use Koha::Acquisition::Orders; |
24 |
use Koha::Acquisition::Orders; |
25 |
|
25 |
|
|
|
26 |
use MARC::Field; |
27 |
use MARC::Record; |
28 |
|
26 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
27 |
use t::lib::Mocks; |
30 |
use t::lib::Mocks; |
|
|
31 |
use Test::MockModule; |
28 |
|
32 |
|
29 |
BEGIN { |
33 |
BEGIN { |
30 |
use_ok('Koha::Biblio'); |
34 |
use_ok('Koha::Biblio'); |
Lines 472-477
subtest 'suggestions() tests' => sub {
Link Here
|
472 |
$schema->storage->txn_rollback; |
476 |
$schema->storage->txn_rollback; |
473 |
}; |
477 |
}; |
474 |
|
478 |
|
|
|
479 |
subtest 'components() tests' => sub { |
480 |
|
481 |
plan tests => 3; |
482 |
|
483 |
$schema->storage->txn_begin; |
484 |
|
485 |
my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), ''); |
486 |
my $host_biblio = Koha::Biblios->find($host_bibnum); |
487 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); |
488 |
my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); |
489 |
$search_mod->mock( 'simple_search_compat', \&search_component_record2 ); |
490 |
|
491 |
my @components = $host_biblio->components; |
492 |
is( ref(\@components), 'ARRAY', 'Return type is correct' ); |
493 |
|
494 |
is_deeply( |
495 |
[@components], |
496 |
[()], |
497 |
'->components returns an empty ARRAY' |
498 |
); |
499 |
|
500 |
$search_mod->unmock( 'simple_search_compat'); |
501 |
$search_mod->mock( 'simple_search_compat', \&search_component_record1 ); |
502 |
my $component_record = component_record1()->as_xml(); |
503 |
|
504 |
is_deeply( |
505 |
$host_biblio->components, |
506 |
[($component_record)], |
507 |
'->components returns the related component part record' |
508 |
); |
509 |
$search_mod->unmock( 'simple_search_compat'); |
510 |
|
511 |
$schema->storage->txn_rollback; |
512 |
}; |
513 |
|
475 |
subtest 'orders() and active_orders() tests' => sub { |
514 |
subtest 'orders() and active_orders() tests' => sub { |
476 |
|
515 |
|
477 |
plan tests => 5; |
516 |
plan tests => 5; |
Lines 552-612
subtest 'subscriptions() tests' => sub {
Link Here
|
552 |
$schema->storage->txn_rollback; |
591 |
$schema->storage->txn_rollback; |
553 |
}; |
592 |
}; |
554 |
|
593 |
|
555 |
subtest 'get_marc_notes() MARC21 tests' => sub { |
594 |
sub component_record1 { |
556 |
plan tests => 11; |
595 |
my $marc = MARC::Record->new; |
557 |
|
596 |
$marc->append_fields( |
558 |
$schema->storage->txn_begin; |
597 |
MARC::Field->new( '001', '3456' ), |
559 |
|
598 |
MARC::Field->new( '245', '', '', a => 'Some title 1' ), |
560 |
t::lib::Mocks::mock_preference( 'NotesToHide', '520' ); |
599 |
MARC::Field->new( '773', '', '', w => '(FIRST)1234' ), |
561 |
|
|
|
562 |
my $biblio = $builder->build_sample_biblio; |
563 |
my $record = $biblio->metadata->record; |
564 |
$record->append_fields( |
565 |
MARC::Field->new( '500', '', '', a => 'Note1' ), |
566 |
MARC::Field->new( '505', '', '', a => 'Note2', u => 'http://someserver.com' ), |
567 |
MARC::Field->new( '520', '', '', a => 'Note3 skipped' ), |
568 |
MARC::Field->new( '541', '0', '', a => 'Note4 skipped on opac' ), |
569 |
MARC::Field->new( '541', '', '', a => 'Note5' ), |
570 |
); |
600 |
); |
571 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
601 |
return $marc; |
572 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
602 |
} |
573 |
my $notes = $biblio->get_marc_notes({ marcflavour => 'MARC21' }); |
603 |
sub search_component_record1 { |
574 |
is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); |
604 |
my @results = ( component_record1()->as_xml() ); |
575 |
is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); |
605 |
return ( undef, \@results, 1 ); |
576 |
is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); |
606 |
} |
577 |
is( $notes->[3]->{marcnote}, 'Note4 skipped on opac',"Not shows if not opac" ); |
|
|
578 |
is( $notes->[4]->{marcnote}, 'Note5', 'Fifth note' ); |
579 |
is( @$notes, 5, 'No more notes' ); |
580 |
$notes = $biblio->get_marc_notes({ marcflavour => 'MARC21', opac => 1 }); |
581 |
is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); |
582 |
is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); |
583 |
is( $notes->[2]->{marcnote}, 'http://someserver.com', 'URL separated' ); |
584 |
is( $notes->[3]->{marcnote}, 'Note5', 'Fifth note shows after fourth skipped' ); |
585 |
is( @$notes, 4, 'No more notes' ); |
586 |
|
587 |
$schema->storage->txn_rollback; |
588 |
}; |
589 |
|
590 |
subtest 'get_marc_notes() UNIMARC tests' => sub { |
591 |
plan tests => 3; |
592 |
|
593 |
$schema->storage->txn_begin; |
594 |
|
607 |
|
595 |
t::lib::Mocks::mock_preference( 'NotesToHide', '310' ); |
608 |
sub search_component_record2 { |
|
|
609 |
my @results; |
610 |
return ( undef, \@results, 0 ); |
611 |
} |
596 |
|
612 |
|
597 |
my $biblio = $builder->build_sample_biblio; |
613 |
sub host_record { |
598 |
my $record = $biblio->metadata->record; |
614 |
my $marc = MARC::Record->new; |
599 |
$record->append_fields( |
615 |
$marc->append_fields( |
600 |
MARC::Field->new( '300', '', '', a => 'Note1' ), |
616 |
MARC::Field->new( '001', '1234' ), |
601 |
MARC::Field->new( '300', '', '', a => 'Note2' ), |
617 |
MARC::Field->new( '003', 'FIRST' ), |
602 |
MARC::Field->new( '310', '', '', a => 'Note3 skipped' ), |
618 |
MARC::Field->new( '245', '', '', a => 'Some title' ), |
603 |
); |
619 |
); |
604 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
620 |
return $marc; |
605 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
621 |
} |
606 |
my $notes = $biblio->get_marc_notes({ marcflavour => 'UNIMARC' }); |
|
|
607 |
is( $notes->[0]->{marcnote}, 'Note1', 'First note' ); |
608 |
is( $notes->[1]->{marcnote}, 'Note2', 'Second note' ); |
609 |
is( @$notes, 2, 'No more notes' ); |
610 |
|
611 |
$schema->storage->txn_rollback; |
612 |
}; |
613 |
- |
|
|