From be1ff2b3983b19ce3c334f27424c4645198dd23a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= <joonas.kylmala@helsinki.fi>
Date: Wed, 10 Jun 2020 20:21:46 +0300
Subject: [PATCH] Bug 11175: (follow-up) Add tests
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
---
t/db_dependent/Koha/Biblio.t | 70 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 69 insertions(+), 1 deletion(-)
diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t
index cf359edf32..d37060d0dd 100755
--- a/t/db_dependent/Koha/Biblio.t
+++ b/t/db_dependent/Koha/Biblio.t
@@ -17,14 +17,18 @@
use Modern::Perl;
-use Test::More tests => 12;
+use Test::More tests => 13;
use C4::Biblio;
use Koha::Database;
use Koha::Acquisition::Orders;
+use MARC::Field;
+use MARC::Record;
+
use t::lib::TestBuilder;
use t::lib::Mocks;
+use Test::MockModule;
BEGIN {
use_ok('Koha::Biblio');
@@ -479,6 +483,41 @@ subtest 'suggestions() tests' => sub {
$schema->storage->txn_rollback;
};
+subtest 'components() tests' => sub {
+
+ plan tests => 3;
+
+ $schema->storage->txn_begin;
+
+ my ($host_bibnum) = C4::Biblio::AddBiblio(host_record(), '');
+ my $host_biblio = Koha::Biblios->find($host_bibnum);
+ t::lib::Mocks::mock_preference( 'SearchEngine', 'Zebra' );
+ my $search_mod = Test::MockModule->new( 'Koha::SearchEngine::Zebra::Search' );
+ $search_mod->mock( 'simple_search_compat', \&search_component_record2 );
+
+ my @components = $host_biblio->components;
+ is( ref(\@components), 'ARRAY', 'Return type is correct' );
+
+ is_deeply(
+ [@components],
+ [()],
+ '->components returns an empty ARRAY'
+ );
+
+ $search_mod->unmock( 'simple_search_compat');
+ $search_mod->mock( 'simple_search_compat', \&search_component_record1 );
+ my $component_record = component_record1()->as_xml();
+
+ is_deeply(
+ $host_biblio->components,
+ [($component_record)],
+ '->components returns the related component part record'
+ );
+ $search_mod->unmock( 'simple_search_compat');
+
+ $schema->storage->txn_rollback;
+};
+
subtest 'orders() and active_orders() tests' => sub {
plan tests => 5;
@@ -558,3 +597,32 @@ subtest 'subscriptions() tests' => sub {
$schema->storage->txn_rollback;
};
+
+sub component_record1 {
+ my $marc = MARC::Record->new;
+ $marc->append_fields(
+ MARC::Field->new( '001', '3456' ),
+ MARC::Field->new( '245', '', '', a => 'Some title 1' ),
+ MARC::Field->new( '773', '', '', w => '(FIRST)1234' ),
+ );
+ return $marc;
+}
+sub search_component_record1 {
+ my @results = ( component_record1()->as_xml() );
+ return ( undef, \@results, 1 );
+}
+
+sub search_component_record2 {
+ my @results;
+ return ( undef, \@results, 0 );
+}
+
+sub host_record {
+ my $marc = MARC::Record->new;
+ $marc->append_fields(
+ MARC::Field->new( '001', '1234' ),
+ MARC::Field->new( '003', 'FIRST' ),
+ MARC::Field->new( '245', '', '', a => 'Some title' ),
+ );
+ return $marc;
+}
--
2.11.0