Lines 1-11
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
# |
|
|
3 |
# Add more tests here!!! |
4 |
|
2 |
|
5 |
use strict; |
3 |
use strict; |
6 |
use warnings; |
4 |
use warnings; |
7 |
use DBI; |
5 |
use DBI; |
8 |
use Test::More tests => 15; |
6 |
use Test::More tests => 26; |
9 |
use Test::MockModule; |
7 |
use Test::MockModule; |
10 |
|
8 |
|
11 |
BEGIN { |
9 |
BEGIN { |
Lines 26-41
$module->mock(
Link Here
|
26 |
my $itemtypes = [ |
24 |
my $itemtypes = [ |
27 |
[ |
25 |
[ |
28 |
'itemtype', 'description', 'rentalcharge', 'notforloan', |
26 |
'itemtype', 'description', 'rentalcharge', 'notforloan', |
29 |
'imageurl', 'summary' |
27 |
'imageurl', 'summary', 'checkinmsg' |
30 |
], |
28 |
], |
31 |
[ 'BK', 'Books', 0, 0, '', '' ], |
29 |
[ 'BK', 'Books', 0, 0, '', '', 'foo' ], |
32 |
[ 'CD', 'CDRom', 0, 0, '', '' ] |
30 |
[ 'CD', 'CDRom', 0, 0, '', '', 'bar' ] |
33 |
]; |
31 |
]; |
34 |
|
32 |
|
35 |
my $itemtypes_empty = [ |
33 |
my $itemtypes_empty = [ |
36 |
[ |
34 |
[ |
37 |
'itemtype', 'description', 'rentalcharge', 'notforloan', |
35 |
'itemtype', 'description', 'rentalcharge', 'notforloan', |
38 |
'imageurl', 'summary' |
36 |
'imageurl', 'summary', 'checkinmsg' |
39 |
], |
37 |
], |
40 |
]; |
38 |
]; |
41 |
|
39 |
|
Lines 53-58
is( scalar( @{$history} ), 1, 'Correct number of statements executed' );
Link Here
|
53 |
$dbh->{mock_add_resultset} = $itemtypes; |
51 |
$dbh->{mock_add_resultset} = $itemtypes; |
54 |
|
52 |
|
55 |
@itemtypes = C4::ItemType->all(); |
53 |
@itemtypes = C4::ItemType->all(); |
|
|
54 |
|
55 |
$history = $dbh->{mock_all_history}; |
56 |
is( scalar( @{$history} ), 2, 'Correct number of statements executed' ); |
57 |
|
56 |
is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' ); |
58 |
is( @itemtypes, 2, 'ItemType->all should return an array with 2 elements' ); |
57 |
|
59 |
|
58 |
is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' ); |
60 |
is( $itemtypes[0]->fish, undef, 'Calling a bad descriptor gives undef' ); |
Lines 73-78
is( $itemtypes[0]->notforloan, '0', 'first not for loan is 0' );
Link Here
|
73 |
|
75 |
|
74 |
is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' ); |
76 |
is( $itemtypes[1]->notforloan, '0', 'second not for loan is 0' ); |
75 |
|
77 |
|
76 |
is( $itemtypes[0]->imageurl, '', 'first not for loan is undef' ); |
78 |
is( $itemtypes[0]->imageurl, '', 'first imageurl is undef' ); |
|
|
79 |
|
80 |
is( $itemtypes[1]->imageurl, '', 'second imageurl is undef' ); |
81 |
|
82 |
is( $itemtypes[0]->checkinmsg, 'foo', 'first checkinmsg is foo' ); |
83 |
|
84 |
is( $itemtypes[1]->checkinmsg, 'bar', 'second checkinmsg is bar' ); |
85 |
|
86 |
# Mock the data again |
87 |
$dbh->{mock_add_resultset} = $itemtypes; |
88 |
|
89 |
# Test get(), which should return one itemtype |
90 |
my $itemtype = C4::ItemType->get( 'BK' ); |
91 |
|
92 |
$history = $dbh->{mock_all_history}; |
93 |
is( scalar( @{$history} ), 3, 'Correct number of statements executed' ); |
94 |
|
95 |
is( $itemtype->fish, undef, 'Calling a bad descriptor gives undef' ); |
96 |
|
97 |
is( $itemtype->itemtype, 'BK', 'itemtype is bk' ); |
98 |
|
99 |
is( $itemtype->description, 'Books', 'description is books' ); |
100 |
|
101 |
is( $itemtype->rentalcharge, '0', 'rental charge is 0' ); |
102 |
|
103 |
is( $itemtype->notforloan, '0', 'not for loan is 0' ); |
104 |
|
105 |
is( $itemtype->imageurl, '', ' not for loan is undef' ); |
77 |
|
106 |
|
78 |
is( $itemtypes[1]->imageurl, '', 'second not for loan is undef' ); |
107 |
is( $itemtype->checkinmsg, 'foo', 'checkinmsg is foo' ); |
79 |
- |
|
|