View | Details | Raw Unified | Return to bug 11175
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +69 lines)
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 qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
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 499-504 subtest 'suggestions() tests' => sub { Link Here
499
    $schema->storage->txn_rollback;
503
    $schema->storage->txn_rollback;
500
};
504
};
501
505
506
subtest 'components() tests' => sub {
507
508
    plan tests => 3;
509
510
    $schema->storage->txn_begin;
511
512
    my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), '');
513
    my $host_biblio = Koha::Biblios->find($host_bibnum);
514
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
515
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
516
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
517
518
    my @components = $host_biblio->components;
519
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
520
521
    is_deeply(
522
        [@components],
523
        [()],
524
        '->components returns an empty ARRAY'
525
    );
526
527
    $search_mod->unmock( 'simple_search_compat');
528
    $search_mod->mock( 'simple_search_compat', \&search_component_record1 );
529
    my $component_record = component_record1()->as_xml();
530
531
    is_deeply(
532
        $host_biblio->components,
533
        [($component_record)],
534
        '->components returns the related component part record'
535
    );
536
    $search_mod->unmock( 'simple_search_compat');
537
538
    $schema->storage->txn_rollback;
539
};
540
502
subtest 'orders() and active_orders() tests' => sub {
541
subtest 'orders() and active_orders() tests' => sub {
503
542
504
    plan tests => 5;
543
    plan tests => 5;
Lines 637-639 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
637
676
638
    $schema->storage->txn_rollback;
677
    $schema->storage->txn_rollback;
639
};
678
};
640
- 
679
680
sub component_record1 {
681
    my $marc = MARC::Record->new;
682
    $marc->append_fields(
683
        MARC::Field->new( '001', '3456' ),
684
        MARC::Field->new( '245', '', '', a => 'Some title 1' ),
685
        MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
686
    );
687
    return $marc;
688
}
689
sub search_component_record1 {
690
    my @results = ( component_record1()->as_xml() );
691
    return ( undef, \@results, 1 );
692
}
693
694
sub search_component_record2 {
695
    my @results;
696
    return ( undef, \@results, 0 );
697
}
698
699
sub host_record {
700
    my $marc = MARC::Record->new;
701
    $marc->append_fields(
702
        MARC::Field->new( '001', '1234' ),
703
        MARC::Field->new( '003', 'FIRST' ),
704
        MARC::Field->new( '245', '', '', a => 'Some title' ),
705
    );
706
    return $marc;
707
}

Return to bug 11175