#!/usr/bin/perl
use Modern::Perl;
-use C4::Stats;
+use C4::Stats qw( UpdateStats );
+use Koha::Database;
-use Test::More tests => 17;
+use Test::More tests => 18;
BEGIN {
- use_ok('C4::Stats');
+ use_ok('C4::Stats', qw( UpdateStats ));
}
can_ok(
'C4::Stats',
- qw(UpdateStats
- TotalPaid
- )
+ qw(UpdateStats)
);
-#Start transaction
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
-$dbh->{RaiseError} = 1;
-$dbh->{AutoCommit} = 0;
#
# Test UpdateStats
amount =>5.1,
other => "bla",
itemtype => "BK",
- accountno => 51,
+ location => "LOC",
ccode => "CODE",
};
my $return_error;
isnt ($return_error,'',"UpdateStats returns undef and croaks if type is undef");
# returns undef and croaks if mandatory params are missing
-my @allowed_circulation_types = qw (renew issue localuse return);
+my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall);
my @allowed_accounts_types = qw (writeoff payment);
my @circulation_mandatory_keys = qw (branch borrowernumber itemnumber ccode itemtype); #don't check type here
my @accounts_mandatory_keys = qw (branch borrowernumber amount); #don't check type here
amount =>5.1,
other => "bla",
itemtype => "BK",
- accountno => 51,
+ location => "LOC",
ccode => "CODE",
type => "return"
};
my $sth = $dbh->prepare("SELECT * FROM statistics");
$sth->execute();
my $line = ${ $sth->fetchall_arrayref( {} ) }[0];
-is ($params-> {branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table");
-is ($params-> {type}, $line->{type}, "UpdateStats save type param in type field of statistics table");
-is ($params-> {borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table");
-cmp_ok($params-> {amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table");
-is ($params-> {other}, $line->{other}, "UpdateStats save other param in other field of statistics table");
-is ($params-> {itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table");
-is ($params-> {accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table");
-is ($params-> {ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table");
+is ($params->{branch}, $line->{branch}, "UpdateStats save branch param in branch field of statistics table");
+is ($params->{type}, $line->{type}, "UpdateStats save type param in type field of statistics table");
+is ($params->{borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table");
+cmp_ok($params->{amount},'==', $line->{value}, "UpdateStats save amount param in value field of statistics table");
+is ($params->{other}, $line->{other}, "UpdateStats save other param in other field of statistics table");
+is ($params->{itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table");
+is ($params->{location}, $line->{location}, "UpdateStats save location param in location field of statistics table");
+is ($params->{ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table");
-#
-# Test TotalPaid
-#
+$dbh->do(q|DELETE FROM statistics|);
+$params = {
+ branch => "BRA",
+ itemnumber => 31,
+ borrowernumber => 5,
+ amount => 5.1,
+ other => "bla",
+ itemtype => "BK",
+ ccode => "CODE",
+ type => "return"
+};
+UpdateStats($params);
+$sth = $dbh->prepare("SELECT * FROM statistics");
+$sth->execute();
+$line = ${ $sth->fetchall_arrayref( {} ) }[0];
+is( $line->{location}, undef,
+ "UpdateStats sets location to NULL if no location is passed in." );
-is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
-# More tests to write!
+$dbh->do(q|DELETE FROM statistics|);
+$params = {
+ branch => "BRA",
+ itemnumber => 31,
+ borrowernumber => 5,
+ amount => 5.1,
+ other => "bla",
+ itemtype => "BK",
+ location => undef,
+ ccode => "CODE",
+ type => "return"
+};
+UpdateStats($params);
+$sth = $dbh->prepare("SELECT * FROM statistics");
+$sth->execute();
+$line = ${ $sth->fetchall_arrayref( {} ) }[0];
+is( $line->{location}, undef,
+ "UpdateStats sets location to NULL if undef is passed in." );
-#End transaction
-$dbh->rollback;
+# More tests to write!