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

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +69 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 16;
20
use Test::More tests => 17;
21
21
22
use C4::Biblio qw( AddBiblio ModBiblio );
22
use C4::Biblio qw( AddBiblio ModBiblio );
23
use Koha::Database;
23
use Koha::Database;
Lines 27-34 use Koha::AuthorisedValueCategories; Link Here
27
use Koha::AuthorisedValues;
27
use Koha::AuthorisedValues;
28
use Koha::MarcSubfieldStructures;
28
use Koha::MarcSubfieldStructures;
29
29
30
use MARC::Field;
31
use MARC::Record;
32
30
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
31
use t::lib::Mocks;
34
use t::lib::Mocks;
35
use Test::MockModule;
32
36
33
BEGIN {
37
BEGIN {
34
    use_ok('Koha::Biblio');
38
    use_ok('Koha::Biblio');
Lines 503-508 subtest 'suggestions() tests' => sub { Link Here
503
    $schema->storage->txn_rollback;
507
    $schema->storage->txn_rollback;
504
};
508
};
505
509
510
subtest 'components() tests' => sub {
511
512
    plan tests => 3;
513
514
    $schema->storage->txn_begin;
515
516
    my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), '');
517
    my $host_biblio = Koha::Biblios->find($host_bibnum);
518
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
519
    my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
520
    $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
521
522
    my @components = $host_biblio->components;
523
    is( ref(\@components), 'ARRAY', 'Return type is correct' );
524
525
    is_deeply(
526
        [@components],
527
        [()],
528
        '->components returns an empty ARRAY'
529
    );
530
531
    $search_mod->unmock( 'simple_search_compat');
532
    $search_mod->mock( 'simple_search_compat', \&search_component_record1 );
533
    my $component_record = component_record1()->as_xml();
534
535
    is_deeply(
536
        $host_biblio->components,
537
        [($component_record)],
538
        '->components returns the related component part record'
539
    );
540
    $search_mod->unmock( 'simple_search_compat');
541
542
    $schema->storage->txn_rollback;
543
};
544
506
subtest 'orders() and active_orders() tests' => sub {
545
subtest 'orders() and active_orders() tests' => sub {
507
546
508
    plan tests => 5;
547
    plan tests => 5;
Lines 736-738 subtest 'article_requests() tests' => sub { Link Here
736
775
737
    $schema->storage->txn_rollback;
776
    $schema->storage->txn_rollback;
738
};
777
};
739
- 
778
779
sub component_record1 {
780
    my $marc = MARC::Record->new;
781
    $marc->append_fields(
782
        MARC::Field->new( '001', '3456' ),
783
        MARC::Field->new( '245', '', '', a => 'Some title 1' ),
784
        MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
785
    );
786
    return $marc;
787
}
788
sub search_component_record1 {
789
    my @results = ( component_record1()->as_xml() );
790
    return ( undef, \@results, 1 );
791
}
792
793
sub search_component_record2 {
794
    my @results;
795
    return ( undef, \@results, 0 );
796
}
797
798
sub host_record {
799
    my $marc = MARC::Record->new;
800
    $marc->append_fields(
801
        MARC::Field->new( '001', '1234' ),
802
        MARC::Field->new( '003', 'FIRST' ),
803
        MARC::Field->new( '245', '', '', a => 'Some title' ),
804
    );
805
    return $marc;
806
}

Return to bug 11175