Lines 3-12
Link Here
|
3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
4 |
use C4::Stats; |
4 |
use C4::Stats; |
5 |
|
5 |
|
6 |
use Test::More tests => 17; |
6 |
use Test::More tests => 29; |
|
|
7 |
use Test::MockModule; |
8 |
use t::lib::TestBuilder; |
9 |
use t::lib::Mocks; |
7 |
|
10 |
|
8 |
BEGIN { |
11 |
BEGIN { |
9 |
use_ok('C4::Stats'); |
12 |
use_ok('C4::Stats'); |
|
|
13 |
use_ok('Koha::Statistic'); |
14 |
use_ok('Koha::Statistics'); |
10 |
} |
15 |
} |
11 |
can_ok( |
16 |
can_ok( |
12 |
'C4::Stats', |
17 |
'C4::Stats', |
Lines 113-126
UpdateStats ($params);
Link Here
|
113 |
my $sth = $dbh->prepare("SELECT * FROM statistics"); |
118 |
my $sth = $dbh->prepare("SELECT * FROM statistics"); |
114 |
$sth->execute(); |
119 |
$sth->execute(); |
115 |
my $line = ${ $sth->fetchall_arrayref( {} ) }[0]; |
120 |
my $line = ${ $sth->fetchall_arrayref( {} ) }[0]; |
116 |
is ($params-> {branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table"); |
121 |
is ($params->{branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table"); |
117 |
is ($params-> {type}, $line->{type}, "UpdateStats save type param in type field of statistics table"); |
122 |
is ($params->{type}, $line->{type}, "UpdateStats save type param in type field of statistics table"); |
118 |
is ($params-> {borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table"); |
123 |
is ($params->{borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table"); |
119 |
cmp_ok($params-> {amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table"); |
124 |
cmp_ok($params->{amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table"); |
120 |
is ($params-> {other}, $line->{other}, "UpdateStats save other param in other field of statistics table"); |
125 |
is ($params->{other}, $line->{other}, "UpdateStats save other param in other field of statistics table"); |
121 |
is ($params-> {itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table"); |
126 |
is ($params->{itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table"); |
122 |
is ($params-> {accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table"); |
127 |
is ($params->{accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table"); |
123 |
is ($params-> {ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table"); |
128 |
is ($params->{ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table"); |
124 |
|
129 |
|
125 |
# |
130 |
# |
126 |
# Test TotalPaid |
131 |
# Test TotalPaid |
Lines 129-133
is ($params-> {ccode}, $line->{ccode}, "UpdateStats save ccode
Link Here
|
129 |
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given"); |
134 |
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given"); |
130 |
# More tests to write! |
135 |
# More tests to write! |
131 |
|
136 |
|
|
|
137 |
my $builder = t::lib::TestBuilder->new; |
138 |
my $library = $builder->build( { source => 'Branch' } ); |
139 |
my $branchcode = $library->{branchcode}; |
140 |
my $context = new Test::MockModule('C4::Context'); |
141 |
$context->mock( |
142 |
'userenv', |
143 |
sub { |
144 |
return { |
145 |
flags => 1, |
146 |
id => 'my_userid', |
147 |
branch => $branchcode, |
148 |
number => '-1', |
149 |
}; |
150 |
} |
151 |
); |
152 |
# Test Koha::Statistic->invalid_patron |
153 |
$dbh->do(q{DELETE FROM statistics}); |
154 |
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 0 ); |
155 |
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } ); |
156 |
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidPatrons is disabled' ); |
157 |
|
158 |
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 1 ); |
159 |
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } ); |
160 |
my $stat = Koha::Statistics->search()->next(); |
161 |
is( $stat->type, 'invalid_patron', 'Type set to invalid_patron' ); |
162 |
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' ); |
163 |
is( $stat->other, 'InvalidCardnumber', 'Invalid cardnumber is set correctly' ); |
164 |
is( $stat->branch, $branchcode, 'Branchcode is set correctly' ); |
165 |
|
166 |
# Test Koha::Statistic->invalid_item |
167 |
$dbh->do(q{DELETE FROM statistics}); |
168 |
t::lib::Mocks::mock_preference( "LogInvalidItems", 0 ); |
169 |
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } ); |
170 |
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidItems is disabled' ); |
171 |
|
172 |
t::lib::Mocks::mock_preference( "LogInvalidItems", 1 ); |
173 |
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } ); |
174 |
$stat = Koha::Statistics->search()->next(); |
175 |
is( $stat->type, 'invalid_item', 'Type set to invalid_item' ); |
176 |
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' ); |
177 |
is( $stat->other, 'InvalidBarcode', 'Invalid barcode is set correctly' ); |
178 |
is( $stat->branch, $branchcode, 'Branchcode is set correctly' ); |
179 |
|
180 |
|
132 |
#End transaction |
181 |
#End transaction |
133 |
$dbh->rollback; |
182 |
$dbh->rollback; |
134 |
- |
|
|