| Lines 35-41
          my $schema = Koha::Database->new->schema;
      
      
        Link Here | 
        
          | 35 | $schema->storage->txn_begin; | 35 | $schema->storage->txn_begin; | 
        
          | 36 | our $builder = t::lib::TestBuilder->new; | 36 | our $builder = t::lib::TestBuilder->new; | 
        
          | 37 |  | 37 |  | 
          
            
              | 38 | subtest 'host_record' => sub { | 38 | subtest 'get_marc_host' => sub { | 
        
          | 39 |     plan tests => 11; | 39 |     plan tests => 11; | 
        
          | 40 |  | 40 |  | 
        
          | 41 |     t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); | 41 |     t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); | 
  
    | Lines 58-97
          subtest 'host_record' => sub {
      
      
        Link Here | 
        
          | 58 |     $search_mod->mock( 'new', sub { return $engine; } ); | 58 |     $search_mod->mock( 'new', sub { return $engine; } ); | 
        
          | 59 |  | 59 |  | 
        
          | 60 |     # Case 1: Search engine does not return any results on controlnumber | 60 |     # Case 1: Search engine does not return any results on controlnumber | 
          
            
              | 61 |     is( $bib1->host_record, undef, 'Empty MARC record' ); | 61 |     is( $bib1->get_marc_host, undef, 'Empty MARC record' ); | 
        
          | 62 |     $marc->append_fields( | 62 |     $marc->append_fields( | 
        
          | 63 |         MARC::Field->new( '773', '', '', g => 'relpart', w => '(xyz)123' ), | 63 |         MARC::Field->new( '773', '', '', g => 'relpart', w => '(xyz)123' ), | 
        
          | 64 |     ); | 64 |     ); | 
          
            
              | 65 |     is( $bib1->host_record, undef, '773 looks fine, but no search results' ); | 65 |     is( $bib1->get_marc_host, undef, '773 looks fine, but no search results' ); | 
        
          | 66 |  | 66 |  | 
        
          | 67 |     # Case 2: Search engine returns (at maximum) one result | 67 |     # Case 2: Search engine returns (at maximum) one result | 
        
          | 68 |     $results = [ $bib1->biblionumber ]; # will be found because 773w is in shape | 68 |     $results = [ $bib1->biblionumber ]; # will be found because 773w is in shape | 
          
            
              | 69 |     my $host = $bib1->host_record; | 69 |     my $host = $bib1->get_marc_host; | 
        
          | 70 |     is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); | 70 |     is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); | 
        
          | 71 |     is( $host->biblionumber, $bib1->biblionumber, 'Check biblionumber' ); | 71 |     is( $host->biblionumber, $bib1->biblionumber, 'Check biblionumber' ); | 
        
          | 72 |     $marc->field('773')->update( w => '(xyz) bad data' ); # causes no results | 72 |     $marc->field('773')->update( w => '(xyz) bad data' ); # causes no results | 
          
            
              | 73 |     $host = $bib1->host_record; | 73 |     $host = $bib1->get_marc_host; | 
            
              | 74 |     is( $bib1->host_record, undef, 'No results for bad 773' ); | 74 |     is( $bib1->get_marc_host, undef, 'No results for bad 773' ); | 
        
          | 75 |     # Add second 773 | 75 |     # Add second 773 | 
        
          | 76 |     $marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) ); | 76 |     $marc->append_fields( MARC::Field->new( '773', '', '', g => 'relpart2', w => '234' ) ); | 
          
            
              | 77 |     $host = $bib1->host_record; | 77 |     $host = $bib1->get_marc_host; | 
        
          | 78 |     is( $host->biblionumber, $bib1->biblionumber, 'Result triggered by second 773' ); | 78 |     is( $host->biblionumber, $bib1->biblionumber, 'Result triggered by second 773' ); | 
        
          | 79 |     # Replace orgcode | 79 |     # Replace orgcode | 
        
          | 80 |     ($marc->field('773'))[1]->update( w => '(abc)345' ); | 80 |     ($marc->field('773'))[1]->update( w => '(abc)345' ); | 
          
            
              | 81 |     is( $bib1->host_record, undef, 'No results for two 773s' ); | 81 |     is( $bib1->get_marc_host, undef, 'No results for two 773s' ); | 
        
          | 82 |     # Test no_items flag | 82 |     # Test no_items flag | 
        
          | 83 |     ($marc->field('773'))[1]->update( w => '234' ); # restore | 83 |     ($marc->field('773'))[1]->update( w => '234' ); # restore | 
          
            
              | 84 |     $host = $bib1->host_record({ no_items => 1 }); | 84 |     $host = $bib1->get_marc_host({ no_items => 1 }); | 
        
          | 85 |     is( $host->biblionumber, $bib1->biblionumber, 'Record found with no_items' ); | 85 |     is( $host->biblionumber, $bib1->biblionumber, 'Record found with no_items' ); | 
        
          | 86 |     $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); | 86 |     $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); | 
          
            
              | 87 |     is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); | 87 |     is( $bib1->get_marc_host({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); | 
        
          | 88 |     # Test list context | 88 |     # Test list context | 
          
            
              | 89 |     my @temp = $bib1->host_record; | 89 |     my @temp = $bib1->get_marc_host; | 
        
          | 90 |     is( $temp[1], 'relpart2', 'Return $g in list context' ); | 90 |     is( $temp[1], 'relpart2', 'Return $g in list context' ); | 
        
          | 91 |  | 91 |  | 
        
          | 92 |     # Case 3: Search engine returns more results | 92 |     # Case 3: Search engine returns more results | 
        
          | 93 |     $results = [ 1, 2 ]; | 93 |     $results = [ 1, 2 ]; | 
          
            
              | 94 |     is( $bib1->host_record, undef, 'host_record returns undef for non-unique control number' ); | 94 |     is( $bib1->get_marc_host, undef, 'get_marc_host returns undef for non-unique control number' ); | 
        
          | 95 | }; | 95 | }; | 
        
          | 96 |  | 96 |  | 
        
          | 97 | sub mocked_search { | 97 | sub mocked_search { | 
            
              | 98 | -  |  |  |