Bug 5327 shifting database dependent modules and scripts to t/db_dependent
[koha.git] / t / db_dependent / lib / KohaTest / Koha / get_itemtypeinfos_of.pm
1 package KohaTest::Koha::get_itemtypeinfos_of;
2 use base qw( KohaTest::Koha );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8
9 use C4::Koha;
10
11 =head2 get_one
12
13 calls get_itemtypeinfos_of on one item type and checks that it gets
14 back something sane.
15
16 =cut
17
18 sub get_one : Test( 8 ) {
19     my $self = shift;
20
21     my $itemtype_info = C4::Koha::get_itemtypeinfos_of( 'BK' );
22     ok( $itemtype_info, 'we got back something from get_itemtypeinfos_of' );
23     isa_ok( $itemtype_info, 'HASH', '...and it' );
24     ok( exists $itemtype_info->{'BK'}, '...and it has a BK key' )
25       or diag( Data::Dumper->Dump( [ $itemtype_info ], [ 'itemtype_info' ] ) );
26     is( scalar keys %$itemtype_info, 1, '...and it has 1 key' );
27     foreach my $key ( qw( imageurl itemtype notforloan description ) ) {
28         ok( exists $itemtype_info->{'BK'}{$key}, "...and the BK info has a $key key" );
29     }
30     
31 }
32
33 =head2 get_two
34
35 calls get_itemtypeinfos_of on a list of item types and verifies the
36 results.
37
38 =cut
39
40 sub get_two : Test( 13 ) {
41     my $self = shift;
42
43     my @itemtypes = qw( BK MU );
44     my $itemtype_info = C4::Koha::get_itemtypeinfos_of( @itemtypes );
45     ok( $itemtype_info, 'we got back something from get_itemtypeinfos_of' );
46     isa_ok( $itemtype_info, 'HASH', '...and it' );
47     is( scalar keys %$itemtype_info, scalar @itemtypes, '...and it has ' . scalar @itemtypes . ' keys' );
48     foreach my $it ( @itemtypes ) {
49         ok( exists $itemtype_info->{$it}, "...and it has a $it key" )
50           or diag( Data::Dumper->Dump( [ $itemtype_info ], [ 'itemtype_info' ] ) );
51         foreach my $key ( qw( imageurl itemtype notforloan description ) ) {
52             ok( exists $itemtype_info->{$it}{$key}, "...and the $it info has a $key key" );
53         }
54     }
55     
56 }
57
58   
59 1;