Lines 521-527
subtest 'get_marc_components() tests' => sub {
Link Here
|
521 |
my $host_biblio = Koha::Biblios->find($host_bibnum); |
521 |
my $host_biblio = Koha::Biblios->find($host_bibnum); |
522 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); |
522 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); |
523 |
my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); |
523 |
my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); |
524 |
$search_mod->mock( 'simple_search_compat', \&search_component_record2 ); |
524 |
$search_mod->mock( 'search_compat', \&search_component_record2 ); |
525 |
|
525 |
|
526 |
my $components = $host_biblio->get_marc_components; |
526 |
my $components = $host_biblio->get_marc_components; |
527 |
is( ref($components), 'ARRAY', 'Return type is correct' ); |
527 |
is( ref($components), 'ARRAY', 'Return type is correct' ); |
Lines 532-539
subtest 'get_marc_components() tests' => sub {
Link Here
|
532 |
'->get_marc_components returns an empty ARRAY' |
532 |
'->get_marc_components returns an empty ARRAY' |
533 |
); |
533 |
); |
534 |
|
534 |
|
535 |
$search_mod->unmock( 'simple_search_compat'); |
535 |
$search_mod->unmock( 'search_compat'); |
536 |
$search_mod->mock( 'simple_search_compat', \&search_component_record1 ); |
536 |
$search_mod->mock( 'search_compat', \&search_component_record1 ); |
537 |
my $component_record = component_record1()->as_xml(); |
537 |
my $component_record = component_record1()->as_xml(); |
538 |
|
538 |
|
539 |
is_deeply( |
539 |
is_deeply( |
Lines 541-553
subtest 'get_marc_components() tests' => sub {
Link Here
|
541 |
[$component_record], |
541 |
[$component_record], |
542 |
'->get_marc_components returns the related component part record' |
542 |
'->get_marc_components returns the related component part record' |
543 |
); |
543 |
); |
544 |
$search_mod->unmock( 'simple_search_compat'); |
544 |
$search_mod->unmock( 'search_compat'); |
545 |
|
545 |
|
546 |
$search_mod->mock( 'simple_search_compat', |
546 |
$search_mod->mock( 'search_compat', |
547 |
sub { Koha::Exceptions::Exception->throw("error searching analytics") } |
547 |
sub { Koha::Exceptions::Exception->throw("error searching analytics") } |
548 |
); |
548 |
); |
549 |
warning_like { $components = $host_biblio->get_marc_components } |
549 |
warning_like { $components = $host_biblio->get_marc_components } |
550 |
qr{^Warning from simple_search_compat: 'error searching analytics'}; |
550 |
qr{^Warning from search_compat: 'error searching analytics'}; |
551 |
|
551 |
|
552 |
is_deeply( |
552 |
is_deeply( |
553 |
$host_biblio->object_messages, |
553 |
$host_biblio->object_messages, |
Lines 559-593
subtest 'get_marc_components() tests' => sub {
Link Here
|
559 |
} |
559 |
} |
560 |
] |
560 |
] |
561 |
); |
561 |
); |
562 |
$search_mod->unmock( 'simple_search_compat'); |
562 |
$search_mod->unmock( 'search_compat'); |
563 |
|
563 |
|
564 |
$schema->storage->txn_rollback; |
564 |
$schema->storage->txn_rollback; |
565 |
}; |
565 |
}; |
566 |
|
566 |
|
567 |
subtest 'get_components_query' => sub { |
567 |
subtest 'get_components_query' => sub { |
568 |
plan tests => 3; |
568 |
plan tests => 6; |
569 |
|
569 |
|
570 |
my $biblio = $builder->build_sample_biblio(); |
570 |
my $biblio = $builder->build_sample_biblio(); |
571 |
my $biblionumber = $biblio->biblionumber; |
571 |
my $biblionumber = $biblio->biblionumber; |
572 |
my $record = $biblio->metadata->record; |
572 |
my $record = $biblio->metadata->record; |
573 |
|
573 |
|
574 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); |
574 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); |
575 |
is($biblio->get_components_query, 'Host-item:("Some boring read")', "UseControlNumber disabled"); |
575 |
t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' ); |
|
|
576 |
t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' ); |
577 |
my ( $comp_q, $comp_s ) = $biblio->get_components_query; |
578 |
is($comp_q, 'Host-item:("Some boring read")', "UseControlNumber disabled"); |
579 |
is($comp_s, "author_za", "UseControlNumber disabled sort is correct"); |
576 |
|
580 |
|
577 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); |
581 |
t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); |
|
|
582 |
t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' ); |
578 |
my $marc_001_field = MARC::Field->new('001', $biblionumber); |
583 |
my $marc_001_field = MARC::Field->new('001', $biblionumber); |
579 |
$record->append_fields($marc_001_field); |
584 |
$record->append_fields($marc_001_field); |
580 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
585 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
581 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
586 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
582 |
|
587 |
|
583 |
is($biblio->get_components_query, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); |
588 |
( $comp_q, $comp_s ) = $biblio->get_components_query; |
|
|
589 |
is($comp_q, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); |
590 |
is($comp_s, "author_az", "UseControlNumber enabled without MarcOrgCode sort is correct"); |
584 |
|
591 |
|
585 |
my $marc_003_field = MARC::Field->new('003', 'OSt'); |
592 |
my $marc_003_field = MARC::Field->new('003', 'OSt'); |
586 |
$record->append_fields($marc_003_field); |
593 |
$record->append_fields($marc_003_field); |
587 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
594 |
C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); |
588 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
595 |
$biblio = Koha::Biblios->find( $biblio->biblionumber); |
589 |
|
596 |
|
590 |
is($biblio->get_components_query, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode"); |
597 |
t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' ); |
|
|
598 |
t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' ); |
599 |
( $comp_q, $comp_s ) = $biblio->get_components_query; |
600 |
is($comp_q, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode"); |
601 |
is($comp_s, "title_asc", "UseControlNumber enabled with MarcOrgCode sort if correct"); |
591 |
}; |
602 |
}; |
592 |
|
603 |
|
593 |
subtest 'orders() and active_orders() tests' => sub { |
604 |
subtest 'orders() and active_orders() tests' => sub { |
Lines 883-894
sub component_record1 {
Link Here
|
883 |
} |
894 |
} |
884 |
sub search_component_record1 { |
895 |
sub search_component_record1 { |
885 |
my @results = ( component_record1()->as_xml() ); |
896 |
my @results = ( component_record1()->as_xml() ); |
886 |
return ( undef, \@results, 1 ); |
897 |
return ( undef, { biblioserver => { RECORDS => \@results, hits => 1 } }, 1 ); |
887 |
} |
898 |
} |
888 |
|
899 |
|
889 |
sub search_component_record2 { |
900 |
sub search_component_record2 { |
890 |
my @results; |
901 |
my @results; |
891 |
return ( undef, \@results, 0 ); |
902 |
return ( undef, { biblioserver => { RECORDS => \@results, hits => 0 } }, 0 ); |
892 |
} |
903 |
} |
893 |
|
904 |
|
894 |
sub host_record { |
905 |
sub host_record { |
895 |
- |
|
|