| Lines 36-44
          our $builder = t::lib::TestBuilder->new;
      
      
        Link Here | 
        
          | 36 | our $marc; | 36 | our $marc; | 
        
          | 37 |  | 37 |  | 
        
          | 38 | subtest 'host_record' => sub { | 38 | subtest 'host_record' => sub { | 
          
            
              | 39 |     plan tests => 9; | 39 |     plan tests => 10; | 
        
          | 40 |  | 40 |  | 
        
          | 41 |     t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); | 41 |     t::lib::Mocks::mock_preference( 'marcflavour', 'MARC21' ); | 
            
              |  |  | 42 |     t::lib::Mocks::mock_preference( 'MARCOrgCode', 'xyz' ); | 
        
          | 42 |     my $mod = Test::MockModule->new('C4::Biblio'); | 43 |     my $mod = Test::MockModule->new('C4::Biblio'); | 
        
          | 43 |     $mod->mock( 'GetMarcBiblio', sub { return $marc; } ); | 44 |     $mod->mock( 'GetMarcBiblio', sub { return $marc; } ); | 
        
          | 44 |  | 45 |  | 
  
    | Lines 48-75
          subtest 'host_record' => sub {
      
      
        Link Here | 
        
          | 48 |  | 49 |  | 
        
          | 49 |     is( $bib1->host_record, undef, 'Empty MARC record' ); | 50 |     is( $bib1->host_record, undef, 'Empty MARC record' ); | 
        
          | 50 |     $marc->append_fields( | 51 |     $marc->append_fields( | 
          
            
              | 51 |         MARC::Field->new( '773', '', '', g => 'relpart', w => 'xyz' ), | 52 |         MARC::Field->new( '773', '', '', g => 'g1', g => 'g2', w => '(xyz)' ), | 
        
          | 52 |     ); | 53 |     ); | 
        
          | 53 |     is( $bib1->host_record, undef, 'No control number found' ); | 54 |     is( $bib1->host_record, undef, 'No control number found' ); | 
          
            
              | 54 |     $marc->field('773')->update( w => 'xyz)' . ($bib2->biblionumber + 1) ); | 55 |     $marc->field('773')->update( w => '(xyz)' . ($bib2->biblionumber + 1) ); | 
        
          | 55 |     is( $bib1->host_record, undef, 'Control number does not exist' ); | 56 |     is( $bib1->host_record, undef, 'Control number does not exist' ); | 
          
            
              | 56 |     # Make it work now | 57 |  | 
            
              | 57 |     $marc->field('773')->update( w => 'xyz)' . $bib2->biblionumber ); | 58 |     # Now replace by number without code | 
            
              |  |  | 59 |     $marc->field('773')->update( w => $bib2->biblionumber ); | 
        
          | 58 |     my $host = $bib1->host_record; | 60 |     my $host = $bib1->host_record; | 
        
          | 59 |     is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); | 61 |     is( ref( $host ), 'Koha::Biblio', 'Correct object returned' ); | 
        
          | 60 |     is( $host->biblionumber, $bib2->biblionumber, 'Check biblionumber' ); | 62 |     is( $host->biblionumber, $bib2->biblionumber, 'Check biblionumber' ); | 
          
            
              | 61 |     # Add second 773 | 63 |     # Replace first $w, add second 773 with code and wrong number | 
            
              | 62 |     $marc->append_fields( MARC::Field->new( '773', '', '', w => 'second' ) ); | 64 |     $marc->field('773')->update( w => '(zzz)123' ); | 
            
              |  |  | 65 |     $marc->append_fields( MARC::Field->new( '773', '', '', w => '(xyz)'. ( $bib2->biblionumber + 1 ) ) ); | 
            
              | 66 |     is( $bib1->host_record, undef, 'No control number found' ); | 
            
              | 67 |     # Change second 773 to a correct number (adding another $w) | 
            
              | 68 |     ($marc->field('773'))[1]->update( w => '(zzz)'.$bib2->biblionumber ); | 
            
              | 69 |     ($marc->field('773'))[1]->add_subfields( w => '(xyz)'.$bib1->biblionumber ); | 
        
          | 63 |     $host = $bib1->host_record; | 70 |     $host = $bib1->host_record; | 
          
            
              | 64 |     is( $host->biblionumber, $bib2->biblionumber, 'Two 773s, record still found' ); | 71 |     is( $host->biblionumber, $bib1->biblionumber, 'Found last biblionumber' ); | 
            
              |  |  | 72 |     $marc->delete_fields( ($marc->field('773'))[1] ); # remove second 773 | 
            
              | 73 |  | 
        
          | 65 |     # Test no_items flag | 74 |     # Test no_items flag | 
            
              |  |  | 75 |     $marc->field('773')->update( w => '(xyz)'.$bib2->biblionumber ); | 
        
          | 66 |     $host = $bib1->host_record({ no_items => 1 }); | 76 |     $host = $bib1->host_record({ no_items => 1 }); | 
        
          | 67 |     is( $host->biblionumber, $bib2->biblionumber, 'Record found with no_items' ); | 77 |     is( $host->biblionumber, $bib2->biblionumber, 'Record found with no_items' ); | 
        
          | 68 |     $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); | 78 |     $builder->build({ source => 'Item', value => { biblionumber => $bib1->biblionumber } }); | 
        
          | 69 |     is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); | 79 |     is( $bib1->host_record({ no_items => 1 }), undef, 'Record not found with no_items flag after adding one item' ); | 
        
          | 70 |     # Test list context | 80 |     # Test list context | 
        
          | 71 |     my @temp = $bib1->host_record; | 81 |     my @temp = $bib1->host_record; | 
          
            
              | 72 |     is( $temp[1], 'relpart', 'Return $g in list context' ); | 82 |     is( $temp[1], 'g1;g2', 'Return $g in list context' ); | 
        
          | 73 | }; | 83 | }; | 
        
          | 74 |  | 84 |  | 
        
          | 75 | $schema->storage->txn_rollback(); | 85 | $schema->storage->txn_rollback(); | 
            
              | 76 | -  |  |  |