From c5b692bd02a15e2a283366353a70a58f6b2262a2 Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 6 Feb 2019 16:10:07 +0100 Subject: [PATCH] Bug 22140: Larger unit test for get_hostitemnumbers_of Add syspref EasyAnalyticalRecords impact in unit test for get_hostitemnumbers_of Test plan : Run t/db_dependent/Items.t Signed-off-by: Martin Renvoize --- t/db_dependent/Items.t | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 5cf8c07e4e..4341de2790 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -813,20 +813,40 @@ subtest '_mod_item_dates' => sub { }; subtest 'get_hostitemnumbers_of' => sub { - plan tests => 1; + plan tests => 3; $schema->storage->txn_begin; + t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); + my $builder = t::lib::TestBuilder->new; - my $bib = MARC::Record->new(); - $bib->append_fields( + # Host item field without 0 or 9 + my $bib1 = MARC::Record->new(); + $bib1->append_fields( MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), MARC::Field->new('773', ' ', ' ', b => 'b without 0 or 9'), ); - my ($biblionumber, $bibitemnum) = AddBiblio($bib, ''); - - my @itemnumbers = C4::Items::get_hostitemnumbers_of( $biblionumber ); - is( @itemnumbers, 0, ); + my ($biblionumber1, $bibitemnum1) = AddBiblio($bib1, ''); + my @itemnumbers1 = C4::Items::get_hostitemnumbers_of( $biblionumber1 ); + is( scalar @itemnumbers1, 0, '773 without 0 or 9'); + + # Correct host item field, analytical records on + t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 1); + my $hostitem = $builder->build_sample_item(); + my $bib2 = MARC::Record->new(); + $bib2->append_fields( + MARC::Field->new('100', ' ', ' ', a => 'Moffat, Steven'), + MARC::Field->new('245', ' ', ' ', a => 'Silence in the library'), + MARC::Field->new('773', ' ', ' ', 0 => $hostitem->biblionumber , 9 => $hostitem->itemnumber, b => 'b' ), + ); + my ($biblionumber2, $bibitemnum2) = AddBiblio($bib2, ''); + my @itemnumbers2 = C4::Items::get_hostitemnumbers_of( $biblionumber2 ); + is( scalar @itemnumbers2, 1, '773 with 0 and 9, EasyAnalyticalRecords on'); + + # Correct host item field, analytical records off + t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 0); + @itemnumbers2 = C4::Items::get_hostitemnumbers_of( $biblionumber2 ); + is( scalar @itemnumbers2, 0, '773 with 0 and 9, EasyAnalyticalRecords off'); $schema->storage->txn_rollback; }; -- 2.20.1