Bug 18460: Fix undefined itemtype warning in Serials.t
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 19 Apr 2017 15:15:46 +0000 (12:15 -0300)
committerJulian Maurice <julian.maurice@biblibre.com>
Wed, 10 May 2017 09:53:22 +0000 (11:53 +0200)
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>
Signed-off-by: Mason James <mtj@kohaaloha.com>
(cherry picked from commit e7ee2fd59f39f6092cb2420c8fed25df096e1529)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

t/db_dependent/Serials.t

index fc8300a..d8e45c7 100755 (executable)
@@ -30,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);
@@ -141,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"| );
 };