6 use Test
::More tests
=> 20;
19 my $dbh = C4
::Context
->dbh;
20 $dbh->{RaiseError
} = 1;
21 $dbh->{AutoCommit
} = 0;
27 is
(UpdateStats
() ,undef, "UpdateStats returns undef if no params");
42 # returns undef and croaks if type is not allowed
43 $params -> {type
} = "bla";
44 eval {UpdateStats
($params)};
46 isnt
($return_error,'',"UpdateStats returns undef and croaks if type is not allowed");
48 delete $params->{type
};
49 # returns undef and croaks if type is missing
50 eval {UpdateStats
($params)};
52 isnt
($return_error,'',"UpdateStats returns undef and croaks if no type given");
54 $params -> {type
} = undef;
55 # returns undef and croaks if type is undef
56 eval {UpdateStats
($params)};
58 isnt
($return_error,'',"UpdateStats returns undef and croaks if type is undef");
60 # returns undef and croaks if mandatory params are missing
61 my @allowed_circulation_types = qw
(renew issue localuse
return);
62 my @allowed_accounts_types = qw
(writeoff payment
);
63 my @circulation_mandatory_keys = qw
(branch borrowernumber itemnumber ccode itemtype
); #don't check type here
64 my @accounts_mandatory_keys = qw
(branch borrowernumber amount
); #don't check type here
66 my @missing_errors = ();
67 foreach my $key (@circulation_mandatory_keys) {
68 my $value = $params->{$key};
69 delete $params->{$key};
70 foreach my $type (@allowed_circulation_types) {
71 $params->{type
} = $type;
72 eval {UpdateStats
($params)};
74 push @missing_errors, "key:$key for type:$type" unless $return_error;
76 $params->{$key} = $value;
78 foreach my $key (@accounts_mandatory_keys) {
79 my $value = $params->{$key};
80 delete $params->{$key};
81 foreach my $type (@allowed_accounts_types) {
82 $params->{type
} = $type;
83 eval {UpdateStats
($params)};
85 push @missing_errors, "key:$key for type:$type" unless $return_error;
87 $params->{$key} = $value;
90 is
(join (", ", @missing_errors),'',"UpdateStats returns undef and croaks if mandatory params are missing");
92 # returns undef and croaks if forbidden params are given
93 $params -> {type
} = "return";
94 $params -> {newparam
} = "true";
95 eval {UpdateStats
($params)};
97 isnt
($return_error,'',"UpdateStats returns undef and croaks if a forbidden param is given");
98 delete $params->{newparam
};
100 # save the params in the right database fields
101 $dbh->do(q
|DELETE FROM statistics
|);
114 UpdateStats
($params);
115 my $sth = $dbh->prepare("SELECT * FROM statistics");
117 my $line = ${ $sth->fetchall_arrayref( {} ) }[0];
118 is
($params->{branch
}, $line->{branch
}, "UpdateStats save branch param in branch field of statistics table");
119 is
($params->{type
}, $line->{type
}, "UpdateStats save type param in type field of statistics table");
120 is
($params->{borrowernumber
}, $line->{borrowernumber
}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table");
121 cmp_ok
($params->{amount
},'==', $line->{value
}, "UpdateStats save amount param in value field of statistics table");
122 is
($params->{other
}, $line->{other
}, "UpdateStats save other param in other field of statistics table");
123 is
($params->{itemtype
}, $line->{itemtype
}, "UpdateStats save itemtype param in itemtype field of statistics table");
124 is
($params->{location
}, $line->{location
}, "UpdateStats save location param in location field of statistics table");
125 is
($params->{accountno
}, $line->{proccode
}, "UpdateStats save accountno param in proccode field of statistics table");
126 is
($params->{ccode
}, $line->{ccode
}, "UpdateStats save ccode param in ccode field of statistics table");
128 $dbh->do(q
|DELETE FROM statistics
|);
140 UpdateStats
($params);
141 $sth = $dbh->prepare("SELECT * FROM statistics");
143 $line = ${ $sth->fetchall_arrayref( {} ) }[0];
144 is
( $line->{location
}, undef,
145 "UpdateStats sets location to NULL if no location is passed in." );
147 $dbh->do(q
|DELETE FROM statistics
|);
160 UpdateStats
($params);
161 $sth = $dbh->prepare("SELECT * FROM statistics");
163 $line = ${ $sth->fetchall_arrayref( {} ) }[0];
164 is
( $line->{location
}, undef,
165 "UpdateStats sets location to NULL if undef is passed in." );
171 is
(TotalPaid
(),undef,"TotalPaid returns undef if no params are given");
172 # More tests to write!