Bug 14910: Redirect to the circulation module after a renew
[koha.git] / t / ItemType.t
blob238fe2ce6c13824fef840f54c3df6e670c55d049
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use DBI;
5 use Test::More tests => 27;
6 use Test::MockModule;
8 BEGIN {
9 use_ok('C4::ItemType');
12 my $module = new Test::MockModule('C4::Context');
13 $module->mock(
14 '_new_dbh',
15 sub {
16 my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
17 || die "Cannot create handle: $DBI::errstr\n";
18 return $dbh;
22 # Mock data
23 my $itemtypes = [
25 'itemtype', 'description', 'rentalcharge', 'notforloan',
26 'imageurl', 'summary', 'checkinmsg'
28 [ 'BK', 'Books', 0, 0, '', '', 'foo' ],
29 [ 'CD', 'CDRom', 0, 0, '', '', 'bar' ]
32 my $itemtypes_empty = [
34 'itemtype', 'description', 'rentalcharge', 'notforloan',
35 'imageurl', 'summary', 'checkinmsg'
39 my $dbh = C4::Context->dbh();
40 $dbh->{mock_add_resultset} = $itemtypes_empty;
42 my @itemtypes = C4::ItemType->all();
43 is( @itemtypes, 0, 'Testing all itemtypes is empty' );
45 # This should run exactly one query so we can test
46 my $history = $dbh->{mock_all_history};
47 is( scalar( @{$history} ), 1, 'Correct number of statements executed' );
49 # Now lets mock some data
50 $dbh->{mock_add_resultset} = $itemtypes;
52 @itemtypes = C4::ItemType->all();
54 $history = $dbh->{mock_all_history};
55 is( scalar( @{$history} ), 2, 'Correct number of statements executed' );
57 is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' );
59 is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' );
61 is( $itemtypes[0]->itemtype, 'BK', 'First itemtype is bk' );
63 is( $itemtypes[1]->itemtype, 'CD', 'second itemtype is cd' );
65 is( $itemtypes[0]->description, 'Books', 'First description is books' );
67 is( $itemtypes[1]->description, 'CDRom', 'second description is CDRom' );
69 is( $itemtypes[0]->rentalcharge, '0', 'first rental charge is 0' );
71 is( $itemtypes[1]->rentalcharge, '0', 'second rental charge is 0' );
73 is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
75 is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' );
77 is( $itemtypes[0]->imageurl, '', 'first imageurl is undef' );
79 is( $itemtypes[1]->imageurl, '', 'second imageurl is undef' );
81 is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' );
83 is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' );
85 # Mock the data again
86 $dbh->{mock_add_resultset} = $itemtypes;
88 # Test get(), which should return one itemtype
89 my $itemtype = C4::ItemType->get( 'BK' );
91 $history = $dbh->{mock_all_history};
92 is( scalar( @{$history} ), 3, 'Correct number of statements executed' );
94 is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' );
96 is( $itemtype->itemtype, 'BK', 'itemtype is bk' );
98 is( $itemtype->description, 'Books', 'description is books' );
100 is( $itemtype->rentalcharge, '0', 'rental charge is 0' );
102 is( $itemtype->notforloan, '0', 'not for loan is 0' );
104 is( $itemtype->imageurl, '', ' not for loan is undef' );
106 is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' );
108 $itemtype = C4::ItemType->get;
109 is( $itemtype, undef, 'C4::ItemType->get should return unless if no parameter is given' );