[Koha-patches] [PATCH] Bug 1953: updating bad unit test for C4::Items::GetItemsForInventory

Galen Charlton galen.charlton at liblime.com
Thu Jul 31 15:58:43 CEST 2008


From: Andrew Moore <andrew.moore at liblime.com>

The tests I wrote for C4::Items::GetItemsForInventory confused the differences
between biblionumber and itemnumber. That wasn't uncovered on my limited test
database, but I uncovered it later.

This fixes that problem by populating a $self->{'items'} list with details of any items
added by KohaTest::add_biblios. Then, tests can probe there for the details of items
they should expect to find when searching.

Signed-off-by: Galen Charlton <galen.charlton at liblime.com>
---
 t/lib/KohaTest.pm                            |    5 +++++
 t/lib/KohaTest/Items/GetItemsForInventory.pm |   14 +++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/t/lib/KohaTest.pm b/t/lib/KohaTest.pm
index 7da8361..d42141c 100644
--- a/t/lib/KohaTest.pm
+++ b/t/lib/KohaTest.pm
@@ -582,6 +582,11 @@ sub add_biblios {
             is( $iteminfo[0], $biblionumber,     "biblionumber is $biblionumber" );
             is( $iteminfo[1], $biblioitemnumber, "biblioitemnumber is $biblioitemnumber" );
             ok( $iteminfo[2], "itemnumber is $iteminfo[2]" );
+        push @{ $self->{'items'} },
+          { biblionumber     => $iteminfo[0],
+            biblioitemnumber => $iteminfo[1],
+            itemnumber       => $iteminfo[2],
+          };
         }
         push @{$self->{'biblios'}}, $biblionumber;
     }
diff --git a/t/lib/KohaTest/Items/GetItemsForInventory.pm b/t/lib/KohaTest/Items/GetItemsForInventory.pm
index 03cb4a1..a56057e 100644
--- a/t/lib/KohaTest/Items/GetItemsForInventory.pm
+++ b/t/lib/KohaTest/Items/GetItemsForInventory.pm
@@ -23,10 +23,10 @@ sub startup_90_add_item_get_callnumber : Test( startup => 13 ) {
 
     $self->add_biblios( add_items => 1 );
 
-    ok( $self->{'biblios'}, 'An item has been aded' )
-      or diag( Data::Dumper->Dump( [ $self->{'biblios'} ], ['biblios'] ) );
+    ok( $self->{'items'}, 'An item has been aded' )
+      or diag( Data::Dumper->Dump( [ $self->{'items'} ], ['items'] ) );
 
-    my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber( $self->{'biblios'}[0] );
+    my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber( $self->{'items'}[0]{'biblionumber'} );
     ok( $biblioitems[0]->{'biblioitemnumber'}, '...and it has a biblioitemnumber' )
       or diag( Data::Dumper->Dump( [ \@biblioitems ], ['biblioitems'] ) );
 
@@ -60,7 +60,7 @@ sub missing_parameters : Test( 1 ) {
     local $TODO = 'GetItemsForInventory should fail when missing required parameters';
 
     my $items = C4::Items::GetItemsForInventory();
-    ok( not $items, 'GetItemsForInventory fails when parameters are missing' )
+    ok( ! defined $items, 'GetItemsForInventory fails when parameters are missing' )
       or diag( Data::Dumper->Dump( [ $items ], [ 'items' ] ) );
 }
 
@@ -77,9 +77,9 @@ sub basic_usage : Test( 4 ) {
     isa_ok( $items, 'ARRAY', 'We were able to call GetItemsForInventory with our call number' );
     is( scalar @$items, 1, '...and we found only one item' );
     my $our_item = $items->[0];
-    is( $our_item->{'itemnumber'},     $self->{'biblios'}[0],                 '...and the item we found has the right itemnumber' );
+    is( $our_item->{'itemnumber'},     $self->{'items'}[0]{'itemnumber'},                 '...and the item we found has the right itemnumber' );
 
-    diag( Data::Dumper->Dump( [$items], ['items'] ) );
+    # diag( Data::Dumper->Dump( [$items], ['items'] ) );
 }
 
 =head3 date_last_seen
@@ -103,7 +103,7 @@ sub date_last_seen : Test( 6 ) {
     isa_ok( $items, 'ARRAY', 'We were able to call GetItemsForInventory with our call number' );
     is( scalar @$items, 1, '...and we found only one item' );
     my $our_item = $items->[0];
-    is( $our_item->{'itemnumber'}, $self->{'biblios'}[0], '...and the item we found has the right itemnumber' );
+    is( $our_item->{'itemnumber'}, $self->{'items'}[0]{'itemnumber'}, '...and the item we found has the right itemnumber' );
 
     # give a datelastseen of yesterday, and we should not get our item.
     $items = C4::Items::GetItemsForInventory(
-- 
1.5.5.GIT




More information about the Koha-patches mailing list