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

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +71 lines)
Lines 17-30 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 12;
20
use Test::More tests => 13;
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 470-475 subtest 'suggestions() tests' => sub { Link Here
470
    $schema->storage->txn_rollback;
474
    $schema->storage->txn_rollback;
471
};
475
};
472
476
477
subtest 'components() tests' => sub {
478
479
    plan tests => 3;
480
481
    $schema->storage->txn_begin;
482
483
    my $host_bibnum = C4::Biblio::AddBiblio(host_record(), '');
484
    my $host_biblio = Koha::Biblios->find($host_bibnum);
485
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
486
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
487
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
488
489
    my @components = $host_biblio->components;
490
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
491
492
    is_deeply(
493
        [@components],
494
        [()],
495
        '->components returns an empty ARRAY'
496
    );
497
498
    $search_mod->unmock( 'simple_search_compat');
499
    $search_mod->mock( 'simple_search_compat', \&search_component_record1 );
500
    my $component_record = component_record1()->as_xml();
501
502
    is_deeply(
503
        $host_biblio->components,
504
        [($component_record)],
505
        '->components returns the related component part record'
506
    );
507
    $search_mod->unmock( 'simple_search_compat');
508
509
    $schema->storage->txn_rollback;
510
};
511
473
subtest 'orders() and active_orders() tests' => sub {
512
subtest 'orders() and active_orders() tests' => sub {
474
513
475
    plan tests => 5;
514
    plan tests => 5;
Lines 549-551 subtest 'subscriptions() tests' => sub { Link Here
549
588
550
    $schema->storage->txn_rollback;
589
    $schema->storage->txn_rollback;
551
};
590
};
552
- 
591
592
sub component_record1 {
593
    my $marc = MARC::Record->new;
594
    $marc->append_fields(
595
        MARC::Field->new( '001', '3456' ),
596
        MARC::Field->new( '245', '', '', a => 'Some title 1' ),
597
        MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
598
        MARC::Field->new( '999', '', '', c => '4568' ),
599
    );
600
    return $marc;
601
}
602
sub search_component_record1 {
603
    my @results = ( component_record1()->as_xml() );
604
    return ( undef, \@results, 1 );
605
}
606
607
sub search_component_record2 {
608
    my @results;
609
    return ( undef, \@results, 0 );
610
}
611
612
sub host_record {
613
    my $marc = MARC::Record->new;
614
    $marc->append_fields(
615
        MARC::Field->new( '001', '1234' ),
616
        MARC::Field->new( '003', 'FIRST' ),
617
        MARC::Field->new( '245', '', '', a => 'Some title' ),
618
        MARC::Field->new( '999', '', '', c => '4567' ),
619
    );
620
    return $marc;
621
}

Return to bug 11175