4 use Test::More tests => 25;
7 use_ok('C4::ItemType');
9 use Test::DBIx::Class {
10 schema_class => 'Koha::Schema',
11 connect_info => ['dbi:SQLite:dbname=:memory:','',''],
12 connect_opts => { name_sep => '.', quote_char => '`', },
13 fixture_class => '::Populate',
21 'itemtype', 'description', 'rentalcharge', 'notforloan',
22 'imageurl', 'summary', 'checkinmsg'
29 my $db = Test::MockModule->new('Koha::Database');
30 $db->mock( _new_schema => sub { return Schema(); } );
34 [ 'BK', 'Books', 0, 0, '', '', 'foo' ],
35 [ 'CD', 'CDRom', 0, 0, '', '', 'bar' ]
38 my @itemtypes = C4::ItemType->all();
39 is( @itemtypes, 0, 'Testing all itemtypes is empty' );
41 # Now lets mock some data
44 @itemtypes = C4::ItemType->all();
46 is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' );
48 is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' );
50 is( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' );
52 is( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' );
54 is( $itemtypes[0]->description, 'Books', 'First description is books' );
56 is( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' );
58 is( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' );
60 is( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' );
62 is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
64 is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' );
66 is( $itemtypes[0]->imageurl, '', 'first imageurl is undef' );
68 is( $itemtypes[1]->imageurl, '', 'second imageurl is undef' );
70 is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' );
72 is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' );
74 # Test get(), which should return one itemtype
75 my $itemtype = C4::ItemType->get( 'BK' );
77 is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' );
79 is( $itemtype->itemtype, 'BK', 'itemtype is bk' );
81 is( $itemtype->description, 'Books', 'description is books' );
83 is( $itemtype->rentalcharge, '0', 'rental charge is 0' );
85 is( $itemtype->notforloan, '0', 'not for loan is 0' );
87 is( $itemtype->imageurl, '', ' not for loan is undef' );
89 is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' );
91 $itemtype = C4::ItemType->get;
92 is( $itemtype, undef, 'C4::ItemType->get should return unless if no parameter is given' );