From 327462f69e6c3a1543925a1ae201381bef8b3299 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Wed, 19 Apr 2017 12:15:46 -0300
Subject: [PATCH] Bug 18460: Fix undefined itemtype warning in Serials.t
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This patch makes the test create an itemtype, and use it for the created item so there's no warning.

To test:
- Run:
  $ prove t/db_dependent/Serials.t
=> FAIL: item-level_itypes set but no itemtype set... warning raised
- Apply the patch
- Run:
  $ prove t/db_dependent/Serials.t
=> SUCCESS: Tests pass and no warning is raised
- Sign off :-D

Signed-off-by: Marc VĂ©ron <veron@veron.ch>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 t/db_dependent/Serials.t | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/t/db_dependent/Serials.t b/t/db_dependent/Serials.t
index dc6edd3..be7f010 100755
--- a/t/db_dependent/Serials.t
+++ b/t/db_dependent/Serials.t
@@ -17,6 +17,7 @@ use C4::Items;
 use Koha::DateUtils;
 use Koha::Acquisition::Booksellers;
 use t::lib::Mocks;
+use t::lib::TestBuilder;
 use Test::More tests => 49;
 
 BEGIN {
@@ -29,6 +30,8 @@ my $dbh = C4::Context->dbh;
 $dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
+my $builder = t::lib::TestBuilder->new();
+
 # This could/should be used for all untested methods
 my @methods = ('updateClaim');
 can_ok('C4::Serials', @methods);
@@ -140,17 +143,33 @@ ok(C4::Serials::GetSerialStatusFromSerialId($serial->{serialid}), 'test getting
 isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
 
 subtest 'Values should not be erased on editing' => sub {
+
     plan tests => 1;
+
     ( $biblionumber, $biblioitemnumber ) = get_biblio();
     my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber', '' );
-    my $item_record    = new MARC::Record;
+    my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype', '' );
+
+    my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
     my $itemcallnumber = 'XXXmy itemcallnumberXXX';
-    $item_record->append_fields( MARC::Field->new( '080', '', '', "a" => "default" ), MARC::Field->new( $icn_tag, '', '', $icn_sf => $itemcallnumber ), );
+
+    my $item_record    = new MARC::Record;
+
+    $item_record->append_fields(
+        MARC::Field->new( '080', '', '', "a" => "default" ),
+        MARC::Field->new(
+            $icn_tag, '', '',
+            $icn_sf => $itemcallnumber,
+            $it_sf  => $itemtype
+        )
+    );
     my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
-    my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber, 1, undef, undef, "publisheddatetext", "notes" );
+    my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber,
+                                          1, undef, undef, "publisheddatetext", "notes" );
     C4::Serials::AddItem2Serial( $serialid, $itemnumber );
     my $serial_info = C4::Serials::GetSerialInformation($serialid);
-    my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' } @{ $serial_info->{items}[0]->{iteminformation} };
+    my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' }
+                                     @{ $serial_info->{items}[0]->{iteminformation} };
     like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| );
 };
 
-- 
2.9.3