Followup Bug 9381 - Add Catalan language
[koha.git] / t / ItemType.t
blob87e090e2c63560228c18ec418e936cc36f070cb9
1 #!/usr/bin/perl
3 # Add more tests here!!!
5 use strict;
6 use warnings;
7 use DBI;
8 use Test::More tests => 15;
9 use Test::MockModule;
11 BEGIN {
12 use_ok('C4::ItemType');
15 my $module = new Test::MockModule('C4::Context');
16 $module->mock(
17 '_new_dbh',
18 sub {
19 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
20 || die "Cannot create handle: $DBI::errstr\n";
21 return $dbh;
25 # Mock data
26 my $itemtypes = [
28 'itemtype', 'description', 'rentalcharge', 'notforloan',
29 'imageurl', 'summary'
31 [ 'BK', 'Books', 0, 0, '', '' ],
32 [ 'CD', 'CDRom', 0, 0, '', '' ]
35 my $itemtypes_empty = [
37 'itemtype', 'description', 'rentalcharge', 'notforloan',
38 'imageurl', 'summary'
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' );