| Lines 518-524
          subtest 'get_marc_components() tests' => sub {
      
      
        Link Here | 
        
          | 518 |     my $host_biblio = Koha::Biblios->find($host_bibnum); | 518 |     my $host_biblio = Koha::Biblios->find($host_bibnum); | 
        
          | 519 |     t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); | 519 |     t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); | 
        
          | 520 |     my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); | 520 |     my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); | 
          
            
              | 521 |     $search_mod->mock( 'simple_search_compat', \&search_component_record2 ); | 521 |     $search_mod->mock( 'search_compat', \&search_component_record2 ); | 
        
          | 522 |  | 522 |  | 
        
          | 523 |     my $components = $host_biblio->get_marc_components; | 523 |     my $components = $host_biblio->get_marc_components; | 
        
          | 524 |     is( ref($components), 'ARRAY', 'Return type is correct' ); | 524 |     is( ref($components), 'ARRAY', 'Return type is correct' ); | 
  
    | Lines 529-536
          subtest 'get_marc_components() tests' => sub {
      
      
        Link Here | 
        
          | 529 |         '->get_marc_components returns an empty ARRAY' | 529 |         '->get_marc_components returns an empty ARRAY' | 
        
          | 530 |     ); | 530 |     ); | 
        
          | 531 |  | 531 |  | 
          
            
              | 532 |     $search_mod->unmock( 'simple_search_compat'); | 532 |     $search_mod->unmock( 'search_compat'); | 
            
              | 533 |     $search_mod->mock( 'simple_search_compat', \&search_component_record1 ); | 533 |     $search_mod->mock( 'search_compat', \&search_component_record1 ); | 
        
          | 534 |     my $component_record = component_record1()->as_xml(); | 534 |     my $component_record = component_record1()->as_xml(); | 
        
          | 535 |  | 535 |  | 
        
          | 536 |     is_deeply( | 536 |     is_deeply( | 
  
    | Lines 538-550
          subtest 'get_marc_components() tests' => sub {
      
      
        Link Here | 
        
          | 538 |         [$component_record], | 538 |         [$component_record], | 
        
          | 539 |         '->get_marc_components returns the related component part record' | 539 |         '->get_marc_components returns the related component part record' | 
        
          | 540 |     ); | 540 |     ); | 
          
            
              | 541 |     $search_mod->unmock( 'simple_search_compat'); | 541 |     $search_mod->unmock( 'search_compat'); | 
        
          | 542 |  | 542 |  | 
          
            
              | 543 |     $search_mod->mock( 'simple_search_compat', | 543 |     $search_mod->mock( 'search_compat', | 
        
          | 544 |         sub { Koha::Exception->throw("error searching analytics") } | 544 |         sub { Koha::Exception->throw("error searching analytics") } | 
        
          | 545 |     ); | 545 |     ); | 
        
          | 546 |     warning_like { $components = $host_biblio->get_marc_components } | 546 |     warning_like { $components = $host_biblio->get_marc_components } | 
          
            
              | 547 |         qr{Warning from simple_search_compat: .* 'error searching analytics'}; | 547 |         qr{Warning from search_compat: .* 'error searching analytics'}; | 
        
          | 548 |  | 548 |  | 
        
          | 549 |     is_deeply( | 549 |     is_deeply( | 
        
          | 550 |         $host_biblio->object_messages, | 550 |         $host_biblio->object_messages, | 
  
    | Lines 556-590
          subtest 'get_marc_components() tests' => sub {
      
      
        Link Here | 
        
          | 556 |             } | 556 |             } | 
        
          | 557 |         ] | 557 |         ] | 
        
          | 558 |     ); | 558 |     ); | 
          
            
              | 559 |     $search_mod->unmock( 'simple_search_compat'); | 559 |     $search_mod->unmock( 'search_compat'); | 
        
          | 560 |  | 560 |  | 
        
          | 561 |     $schema->storage->txn_rollback; | 561 |     $schema->storage->txn_rollback; | 
        
          | 562 | }; | 562 | }; | 
        
          | 563 |  | 563 |  | 
        
          | 564 | subtest 'get_components_query' => sub { | 564 | subtest 'get_components_query' => sub { | 
          
            
              | 565 |     plan tests => 3; | 565 |     plan tests => 6; | 
        
          | 566 |  | 566 |  | 
        
          | 567 |     my $biblio = $builder->build_sample_biblio(); | 567 |     my $biblio = $builder->build_sample_biblio(); | 
        
          | 568 |     my $biblionumber = $biblio->biblionumber; | 568 |     my $biblionumber = $biblio->biblionumber; | 
        
          | 569 |     my $record = $biblio->metadata->record; | 569 |     my $record = $biblio->metadata->record; | 
        
          | 570 |  | 570 |  | 
        
          | 571 |     t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); | 571 |     t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); | 
          
            
              | 572 |     is($biblio->get_components_query, "Host-item:(Some boring read)", "UseControlNumber disabled"); | 572 |     t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' ); | 
            
              |  |  | 573 |     t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' ); | 
            
              | 574 |     my ( $comp_q, $comp_s ) = $biblio->get_components_query; | 
            
              | 575 |     is($comp_q, "Host-item:(Some boring read)",, "UseControlNumber disabled"); | 
            
              | 576 |     is($comp_s, "author_za", "UseControlNumber disabled sort is correct"); | 
        
          | 573 |  | 577 |  | 
        
          | 574 |     t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); | 578 |     t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); | 
            
              |  |  | 579 |     t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' ); | 
        
          | 575 |     my $marc_001_field = MARC::Field->new('001', $biblionumber); | 580 |     my $marc_001_field = MARC::Field->new('001', $biblionumber); | 
        
          | 576 |     $record->append_fields($marc_001_field); | 581 |     $record->append_fields($marc_001_field); | 
        
          | 577 |     C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); | 582 |     C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); | 
        
          | 578 |     $biblio = Koha::Biblios->find( $biblio->biblionumber); | 583 |     $biblio = Koha::Biblios->find( $biblio->biblionumber); | 
        
          | 579 |  | 584 |  | 
          
            
              | 580 |     is($biblio->get_components_query, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); | 585 |     ( $comp_q, $comp_s ) = $biblio->get_components_query; | 
            
              |  |  | 586 |     is($comp_q, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); | 
            
              | 587 |     is($comp_s, "author_az", "UseControlNumber enabled without MarcOrgCode sort is correct"); | 
        
          | 581 |  | 588 |  | 
        
          | 582 |     my $marc_003_field = MARC::Field->new('003', 'OSt'); | 589 |     my $marc_003_field = MARC::Field->new('003', 'OSt'); | 
        
          | 583 |     $record->append_fields($marc_003_field); | 590 |     $record->append_fields($marc_003_field); | 
        
          | 584 |     C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); | 591 |     C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); | 
        
          | 585 |     $biblio = Koha::Biblios->find( $biblio->biblionumber); | 592 |     $biblio = Koha::Biblios->find( $biblio->biblionumber); | 
        
          | 586 |  | 593 |  | 
          
            
              | 587 |     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"); | 594 |     t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' ); | 
            
              |  |  | 595 |     t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' ); | 
            
              | 596 |     ( $comp_q, $comp_s ) = $biblio->get_components_query; | 
            
              | 597 |     is($comp_q, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode"); | 
            
              | 598 |     is($comp_s, "title_asc", "UseControlNumber enabled with MarcOrgCode sort if correct"); | 
        
          | 588 | }; | 599 | }; | 
        
          | 589 |  | 600 |  | 
        
          | 590 | subtest 'orders() and active_orders() tests' => sub { | 601 | subtest 'orders() and active_orders() tests' => sub { | 
  
    | Lines 1012-1023
          sub component_record1 {
      
      
        Link Here | 
        
          | 1012 | } | 1023 | } | 
        
          | 1013 | sub search_component_record1 { | 1024 | sub search_component_record1 { | 
        
          | 1014 |     my @results = ( component_record1()->as_xml() ); | 1025 |     my @results = ( component_record1()->as_xml() ); | 
          
            
              | 1015 |     return ( undef, \@results, 1 ); | 1026 |     return ( undef, { biblioserver => { RECORDS => \@results, hits => 1 } }, 1 ); | 
        
          | 1016 | } | 1027 | } | 
        
          | 1017 |  | 1028 |  | 
        
          | 1018 | sub search_component_record2 { | 1029 | sub search_component_record2 { | 
        
          | 1019 |     my @results; | 1030 |     my @results; | 
          
            
              | 1020 |     return ( undef, \@results, 0 ); | 1031 |     return ( undef, { biblioserver => { RECORDS => \@results, hits => 0 } }, 0 ); | 
        
          | 1021 | } | 1032 | } | 
        
          | 1022 |  | 1033 |  | 
        
          | 1023 | sub host_record { | 1034 | sub host_record { | 
            
              | 1024 | -  |  |  |