View | Details | Raw Unified | Return to bug 5327
Collapse All | Expand All

(-)a/t/ItemType.t (-3 / +61 lines)
Lines 5-14 Link Here
5
5
6
use strict;
6
use strict;
7
use warnings;
7
use warnings;
8
8
use DBI;
9
use Test::More tests => 1;
9
use Test::More tests => 15;
10
use Test::MockModule;
10
11
11
BEGIN {
12
BEGIN {
12
        use_ok('C4::ItemType');
13
        use_ok('C4::ItemType');
13
}
14
}
14
15
15
- 
16
17
my $module = new Test::MockModule('C4::Context');
18
$module->mock('_new_dbh', sub {
19
                             my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
20
                             || die "Cannot create handle: $DBI::errstr\n";
21
                             return $dbh });
22
23
# Mock data
24
my $itemtypes = [
25
    ['itemtype','description','rentalcharge','notforloan','imageurl','summary'],
26
    ['BK','Books',0,0,'',''],
27
    ['CD','CDRom',0,0,'','']
28
    ];
29
30
31
my $dbh = C4::Context->dbh();
32
33
my @itemtypes = C4::ItemType->all();
34
is(@itemtypes, 0, 'Testing all itemtypes is empty');
35
36
# This should run exactly one query so we can test
37
my $history = $dbh->{mock_all_history};
38
is(scalar(@{$history}), 1, 'Correct number of statements executed') ;
39
40
41
# Now lets mock some data
42
$dbh->{mock_add_resultset} = $itemtypes;
43
44
@itemtypes = C4::ItemType->all();
45
is(@itemtypes, 2, 'ItemType->all should return an array with 2 elements');
46
47
is($itemtypes[0]->fish,undef,'Calling a bad descriptor gives undef');
48
49
is($itemtypes[0]->itemtype, 'BK', 'First itemtype is bk');
50
51
is($itemtypes[1]->itemtype, 'CD', 'second itemtype is cd');
52
53
is($itemtypes[0]->description, 'Books', 'First description is books');
54
55
is($itemtypes[1]->description, 'CDRom', 'second description is CDRom');
56
57
is($itemtypes[0]->rentalcharge, '0', 'first rental charge is 0');
58
59
is($itemtypes[1]->rentalcharge, '0', 'second rental charge is 0');
60
61
is($itemtypes[0]->notforloan, '0', 'first not for loan is 0');
62
63
is($itemtypes[1]->notforloan, '0', 'second not for loan is 0');
64
65
is($itemtypes[0]->imageurl, '', 'first not for loan is undef');
66
67
is($itemtypes[1]->imageurl, '', 'second not for loan is undef');
68
69
70
71
72
73

Return to bug 5327