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;
22
use C4::Biblio;
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 472-477 subtest 'suggestions() tests' => sub { Link Here
472
    $schema->storage->txn_rollback;
476
    $schema->storage->txn_rollback;
473
};
477
};
474
478
479
subtest 'components() tests' => sub {
480
481
    plan tests => 3;
482
483
    $schema->storage->txn_begin;
484
485
    my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), '');
486
    my $host_biblio = Koha::Biblios->find($host_bibnum);
487
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
488
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
489
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
490
491
    my @components = $host_biblio->components;
492
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
493
494
    is_deeply(
495
        [@components],
496
        [()],
497
        '->components returns an empty ARRAY'
498
    );
499
500
    $search_mod->unmock( 'simple_search_compat');
501
    $search_mod->mock( 'simple_search_compat', \&search_component_record1 );
502
    my $component_record = component_record1()->as_xml();
503
504
    is_deeply(
505
        $host_biblio->components,
506
        [($component_record)],
507
        '->components returns the related component part record'
508
    );
509
    $search_mod->unmock( 'simple_search_compat');
510
511
    $schema->storage->txn_rollback;
512
};
513
475
subtest 'orders() and active_orders() tests' => sub {
514
subtest 'orders() and active_orders() tests' => sub {
476
515
477
    plan tests => 5;
516
    plan tests => 5;
Lines 610-612 subtest 'get_marc_notes() UNIMARC tests' => sub { Link Here
610
649
611
    $schema->storage->txn_rollback;
650
    $schema->storage->txn_rollback;
612
};
651
};
613
- 
652
653
sub component_record1 {
654
    my $marc = MARC::Record->new;
655
    $marc->append_fields(
656
        MARC::Field->new( '001', '3456' ),
657
        MARC::Field->new( '245', '', '', a => 'Some title 1' ),
658
        MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
659
    );
660
    return $marc;
661
}
662
sub search_component_record1 {
663
    my @results = ( component_record1()->as_xml() );
664
    return ( undef, \@results, 1 );
665
}
666
667
sub search_component_record2 {
668
    my @results;
669
    return ( undef, \@results, 0 );
670
}
671
672
sub host_record {
673
    my $marc = MARC::Record->new;
674
    $marc->append_fields(
675
        MARC::Field->new( '001', '1234' ),
676
        MARC::Field->new( '003', 'FIRST' ),
677
        MARC::Field->new( '245', '', '', a => 'Some title' ),
678
    );
679
    return $marc;
680
}

Return to bug 11175