1 package KohaTest::Items::GetItemsForInventory;
2 use base qw( KohaTest::Items );
11 =head2 STARTUP METHODS
13 These get run once, before the main test methods in this module
17 =head2 startup_90_add_item_get_callnumber
21 sub startup_90_add_item_get_callnumber : Test( startup => 13 ) {
24 $self->add_biblios( add_items => 1 );
26 ok( $self->{'items'}, 'An item has been aded' )
27 or diag( Data::Dumper->Dump( [ $self->{'items'} ], ['items'] ) );
29 my @biblioitems = C4::Biblio::GetBiblioItemByBiblioNumber( $self->{'items'}[0]{'biblionumber'} );
30 ok( $biblioitems[0]->{'biblioitemnumber'}, '...and it has a biblioitemnumber' )
31 or diag( Data::Dumper->Dump( [ \@biblioitems ], ['biblioitems'] ) );
33 my $items_info = GetItemsByBiblioitemnumber( $biblioitems[0]->{'biblioitemnumber'} );
34 isa_ok( $items_info, 'ARRAY', '...and we can search with that biblioitemnumber' )
35 or diag( Data::Dumper->Dump( [$items_info], ['items_info'] ) );
36 cmp_ok( scalar @$items_info, '>', 0, '...and we can find at least one item with that biblioitemnumber' );
38 my $item_info = $items_info->[0];
39 ok( $item_info->{'itemcallnumber'}, '...and the item we found has a call number: ' . $item_info->{'itemcallnumber'} )
40 or diag( Data::Dumper->Dump( [$item_info], ['item_info'] ) );
42 $self->{'callnumber'} = $item_info->{'itemcallnumber'};
50 =head3 missing_parameters
52 the minlocation and maxlocation parameters are required. If they are
53 not provided, this method should somehow complain, such as returning
54 undef or emitina warning or something.
58 sub missing_parameters : Test( 1 ) {
60 local $TODO = 'GetItemsForInventory should fail when missing required parameters';
62 my $items = C4::Items::GetItemsForInventory();
63 ok( ! defined $items, 'GetItemsForInventory fails when parameters are missing' )
64 or diag( Data::Dumper->Dump( [ $items ], [ 'items' ] ) );
72 sub basic_usage : Test( 4 ) {
75 ok( $self->{'callnumber'}, 'we have a call number to search for: ' . $self->{'callnumber'} );
76 my $items = C4::Items::GetItemsForInventory( $self->{'callnumber'}, $self->{'callnumber'} );
77 isa_ok( $items, 'ARRAY', 'We were able to call GetItemsForInventory with our call number' );
78 is( scalar @$items, 1, '...and we found only one item' );
79 my $our_item = $items->[0];
80 is( $our_item->{'itemnumber'}, $self->{'items'}[0]{'itemnumber'}, '...and the item we found has the right itemnumber' );
82 # diag( Data::Dumper->Dump( [$items], ['items'] ) );
90 sub date_last_seen : Test( 6 ) {
93 ok( $self->{'callnumber'}, 'we have a call number to search for: ' . $self->{'callnumber'} );
95 my $items = C4::Items::GetItemsForInventory(
96 $self->{'callnumber'}, # minlocation
97 $self->{'callnumber'}, # maxlocation
100 C4::Dates->new( $self->tomorrow(), 'iso' )->output, # datelastseen
103 isa_ok( $items, 'ARRAY', 'We were able to call GetItemsForInventory with our call number' );
104 is( scalar @$items, 1, '...and we found only one item' );
105 my $our_item = $items->[0];
106 is( $our_item->{'itemnumber'}, $self->{'items'}[0]{'itemnumber'}, '...and the item we found has the right itemnumber' );
108 # give a datelastseen of yesterday, and we should not get our item.
109 $items = C4::Items::GetItemsForInventory(
110 $self->{'callnumber'}, # minlocation
111 $self->{'callnumber'}, # maxlocation
114 C4::Dates->new( $self->yesterday(), 'iso' )->output, # datelastseen
117 isa_ok( $items, 'ARRAY', 'We were able to call GetItemsForInventory with our call number' );
118 is( scalar @$items, 0, '...and we found no items' );