3 # Add more tests here!!!
8 use Test
::More tests
=> 15;
12 use_ok
('C4::ItemType');
15 my $module = new Test
::MockModule
('C4::Context');
19 my $dbh = DBI
->connect( 'DBI:Mock:', '', '' )
20 || die "Cannot create handle: $DBI::errstr\n";
28 'itemtype', 'description', 'rentalcharge', 'notforloan',
31 [ 'BK', 'Books', 0, 0, '', '' ],
32 [ 'CD', 'CDRom', 0, 0, '', '' ]
35 my $itemtypes_empty = [
37 'itemtype', 'description', 'rentalcharge', 'notforloan',
42 my $dbh = C4
::Context
->dbh();
43 $dbh->{mock_add_resultset
} = $itemtypes_empty;
45 my @itemtypes = C4
::ItemType
->all();
46 is
( @itemtypes, 0, 'Testing all itemtypes is empty' );
48 # This should run exactly one query so we can test
49 my $history = $dbh->{mock_all_history
};
50 is
( scalar( @
{$history} ), 1, 'Correct number of statements executed' );
52 # Now lets mock some data
53 $dbh->{mock_add_resultset
} = $itemtypes;
55 @itemtypes = C4
::ItemType
->all();
56 is
( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' );
58 is
( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' );
60 is
( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' );
62 is
( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' );
64 is
( $itemtypes[0]->description, 'Books', 'First description is books' );
66 is
( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' );
68 is
( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' );
70 is
( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' );
72 is
( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
74 is
( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' );
76 is
( $itemtypes[0]->imageurl, '', 'first not for loan is undef' );
78 is
( $itemtypes[1]->imageurl, '', 'second not for loan is undef' );