|
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 479-484
subtest 'suggestions() tests' => sub {
Link Here
|
| 479 |
$schema->storage->txn_rollback; |
483 |
$schema->storage->txn_rollback; |
| 480 |
}; |
484 |
}; |
| 481 |
|
485 |
|
|
|
486 |
subtest 'components() tests' => sub { |
| 487 |
|
| 488 |
plan tests => 3; |
| 489 |
|
| 490 |
$schema->storage->txn_begin; |
| 491 |
|
| 492 |
my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), ''); |
| 493 |
my $host_biblio = Koha::Biblios->find($host_bibnum); |
| 494 |
t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' ); |
| 495 |
my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' ); |
| 496 |
$search_mod->mock( 'simple_search_compat', \&search_component_record2 ); |
| 497 |
|
| 498 |
my @components = $host_biblio->components; |
| 499 |
is( ref(\@components), 'ARRAY', 'Return type is correct' ); |
| 500 |
|
| 501 |
is_deeply( |
| 502 |
[@components], |
| 503 |
[()], |
| 504 |
'->components returns an empty ARRAY' |
| 505 |
); |
| 506 |
|
| 507 |
$search_mod->unmock( 'simple_search_compat'); |
| 508 |
$search_mod->mock( 'simple_search_compat', \&search_component_record1 ); |
| 509 |
my $component_record = component_record1()->as_xml(); |
| 510 |
|
| 511 |
is_deeply( |
| 512 |
$host_biblio->components, |
| 513 |
[($component_record)], |
| 514 |
'->components returns the related component part record' |
| 515 |
); |
| 516 |
$search_mod->unmock( 'simple_search_compat'); |
| 517 |
|
| 518 |
$schema->storage->txn_rollback; |
| 519 |
}; |
| 520 |
|
| 482 |
subtest 'orders() and active_orders() tests' => sub { |
521 |
subtest 'orders() and active_orders() tests' => sub { |
| 483 |
|
522 |
|
| 484 |
plan tests => 5; |
523 |
plan tests => 5; |
|
Lines 558-560
subtest 'subscriptions() tests' => sub {
Link Here
|
| 558 |
|
597 |
|
| 559 |
$schema->storage->txn_rollback; |
598 |
$schema->storage->txn_rollback; |
| 560 |
}; |
599 |
}; |
| 561 |
- |
600 |
|
|
|
601 |
sub component_record1 { |
| 602 |
my $marc = MARC::Record->new; |
| 603 |
$marc->append_fields( |
| 604 |
MARC::Field->new( '001', '3456' ), |
| 605 |
MARC::Field->new( '245', '', '', a => 'Some title 1' ), |
| 606 |
MARC::Field->new( '773', '', '', w => '(FIRST)1234' ), |
| 607 |
); |
| 608 |
return $marc; |
| 609 |
} |
| 610 |
sub search_component_record1 { |
| 611 |
my @results = ( component_record1()->as_xml() ); |
| 612 |
return ( undef, \@results, 1 ); |
| 613 |
} |
| 614 |
|
| 615 |
sub search_component_record2 { |
| 616 |
my @results; |
| 617 |
return ( undef, \@results, 0 ); |
| 618 |
} |
| 619 |
|
| 620 |
sub host_record { |
| 621 |
my $marc = MARC::Record->new; |
| 622 |
$marc->append_fields( |
| 623 |
MARC::Field->new( '001', '1234' ), |
| 624 |
MARC::Field->new( '003', 'FIRST' ), |
| 625 |
MARC::Field->new( '245', '', '', a => 'Some title' ), |
| 626 |
); |
| 627 |
return $marc; |
| 628 |
} |