3 # This Koha test module is a stub!
4 # Add more tests here!!!
9 use Test::More tests => 15;
13 use_ok('C4::ItemType');
16 my $module = new Test::MockModule('C4::Context');
20 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
21 || die "Cannot create handle: $DBI::errstr\n";
29 'itemtype', 'description', 'rentalcharge', 'notforloan',
32 [ 'BK', 'Books', 0, 0, '', '' ],
33 [ 'CD', 'CDRom', 0, 0, '', '' ]
36 my $dbh = C4::Context->dbh();
38 my @itemtypes = C4::ItemType->all();
39 is( @itemtypes, 0, 'Testing all itemtypes is empty' );
41 # This should run exactly one query so we can test
42 my $history = $dbh->{mock_all_history};
43 is( scalar( @{$history} ), 1, 'Correct number of statements executed' );
45 # Now lets mock some data
46 $dbh->{mock_add_resultset} = $itemtypes;
48 @itemtypes = C4::ItemType->all();
49 is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' );
51 is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' );
53 is( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' );
55 is( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' );
57 is( $itemtypes[0]->description, 'Books', 'First description is books' );
59 is( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' );
61 is( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' );
63 is( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' );
65 is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
67 is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' );
69 is( $itemtypes[0]->imageurl, '', 'first not for loan is undef' );
71 is( $itemtypes[1]->imageurl, '', 'second not for loan is undef' );