|
Lines 10-16
use C4::Circulation;
Link Here
|
| 10 |
use C4::Items; |
10 |
use C4::Items; |
| 11 |
use C4::Context; |
11 |
use C4::Context; |
| 12 |
|
12 |
|
| 13 |
use Test::More tests => 16; |
13 |
use Test::More tests => 24; |
| 14 |
|
14 |
|
| 15 |
BEGIN { |
15 |
BEGIN { |
| 16 |
use_ok('C4::Circulation'); |
16 |
use_ok('C4::Circulation'); |
|
Lines 38-57
$dbh->{RaiseError} = 1;
Link Here
|
| 38 |
$dbh->{AutoCommit} = 0; |
38 |
$dbh->{AutoCommit} = 0; |
| 39 |
|
39 |
|
| 40 |
$dbh->do(q|DELETE FROM issues|); |
40 |
$dbh->do(q|DELETE FROM issues|); |
| 41 |
$dbh->do(q|DELETE FROM borrowers|); |
|
|
| 42 |
$dbh->do(q|DELETE FROM items|); |
41 |
$dbh->do(q|DELETE FROM items|); |
|
|
42 |
$dbh->do(q|DELETE FROM borrowers|); |
| 43 |
$dbh->do(q|DELETE FROM branches|); |
43 |
$dbh->do(q|DELETE FROM branches|); |
| 44 |
$dbh->do(q|DELETE FROM categories|); |
44 |
$dbh->do(q|DELETE FROM categories|); |
| 45 |
$dbh->do(q|DELETE FROM accountlines|); |
45 |
$dbh->do(q|DELETE FROM accountlines|); |
|
|
46 |
$dbh->do(q|DELETE FROM issuingrules|); |
| 46 |
|
47 |
|
| 47 |
#Add sample datas |
48 |
#Add sample datas |
| 48 |
my @USERENV = ( 1, 'test', 'MASTERTEST', 'Test', 'Test', 't', 'Test', 0, ); |
|
|
| 49 |
|
| 50 |
C4::Context->_new_userenv('DUMMY_SESSION_ID'); |
| 51 |
C4::Context->set_userenv(@USERENV); |
| 52 |
|
| 53 |
my $userenv = C4::Context->userenv |
| 54 |
or BAIL_OUT("No userenv"); |
| 55 |
|
49 |
|
| 56 |
#Add Dates |
50 |
#Add Dates |
| 57 |
|
51 |
|
|
Lines 66-72
my $daysago10 = output_pref( $dt_today2, 'iso', '24hr', 1 );
Link Here
|
| 66 |
#Add branch and category |
60 |
#Add branch and category |
| 67 |
my $samplebranch1 = { |
61 |
my $samplebranch1 = { |
| 68 |
add => 1, |
62 |
add => 1, |
| 69 |
branchcode => 'SAB1', |
63 |
branchcode => 'CPL', |
| 70 |
branchname => 'Sample Branch', |
64 |
branchname => 'Sample Branch', |
| 71 |
branchaddress1 => 'sample adr1', |
65 |
branchaddress1 => 'sample adr1', |
| 72 |
branchaddress2 => 'sample adr2', |
66 |
branchaddress2 => 'sample adr2', |
|
Lines 85-91
my $samplebranch1 = {
Link Here
|
| 85 |
}; |
79 |
}; |
| 86 |
my $samplebranch2 = { |
80 |
my $samplebranch2 = { |
| 87 |
add => 1, |
81 |
add => 1, |
| 88 |
branchcode => 'SAB2', |
82 |
branchcode => 'MPL', |
| 89 |
branchname => 'Sample Branch2', |
83 |
branchname => 'Sample Branch2', |
| 90 |
branchaddress1 => 'sample adr1_2', |
84 |
branchaddress1 => 'sample adr1_2', |
| 91 |
branchaddress2 => 'sample adr2_2', |
85 |
branchaddress2 => 'sample adr2_2', |
|
Lines 137-147
$dbh->do(
Link Here
|
| 137 |
my $record = MARC::Record->new(); |
131 |
my $record = MARC::Record->new(); |
| 138 |
$record->append_fields( |
132 |
$record->append_fields( |
| 139 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
133 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
| 140 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '', ); |
134 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); |
| 141 |
|
135 |
|
| 142 |
my @sampleitem1 = C4::Items::AddItem( |
136 |
my @sampleitem1 = C4::Items::AddItem( |
| 143 |
{ |
137 |
{ |
| 144 |
barcode => 1, |
138 |
barcode => 'barcode_1', |
| 145 |
itemcallnumber => 'callnumber1', |
139 |
itemcallnumber => 'callnumber1', |
| 146 |
homebranch => $samplebranch1->{branchcode}, |
140 |
homebranch => $samplebranch1->{branchcode}, |
| 147 |
holdingbranch => $samplebranch1->{branchcode}, |
141 |
holdingbranch => $samplebranch1->{branchcode}, |
|
Lines 153-159
my @sampleitem1 = C4::Items::AddItem(
Link Here
|
| 153 |
my $item_id1 = $sampleitem1[2]; |
147 |
my $item_id1 = $sampleitem1[2]; |
| 154 |
my @sampleitem2 = C4::Items::AddItem( |
148 |
my @sampleitem2 = C4::Items::AddItem( |
| 155 |
{ |
149 |
{ |
| 156 |
barcode => 2, |
150 |
barcode => 'barcode_2', |
| 157 |
itemcallnumber => 'callnumber2', |
151 |
itemcallnumber => 'callnumber2', |
| 158 |
homebranch => $samplebranch2->{branchcode}, |
152 |
homebranch => $samplebranch2->{branchcode}, |
| 159 |
holdingbranch => $samplebranch2->{branchcode}, |
153 |
holdingbranch => $samplebranch2->{branchcode}, |
|
Lines 171-182
my $borrower_id1 = C4::Members::AddMember(
Link Here
|
| 171 |
categorycode => $samplecat->{categorycode}, |
165 |
categorycode => $samplecat->{categorycode}, |
| 172 |
branchcode => $samplebranch1->{branchcode}, |
166 |
branchcode => $samplebranch1->{branchcode}, |
| 173 |
); |
167 |
); |
|
|
168 |
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1); |
| 174 |
my $borrower_id2 = C4::Members::AddMember( |
169 |
my $borrower_id2 = C4::Members::AddMember( |
| 175 |
firstname => 'firstname2', |
170 |
firstname => 'firstname2', |
| 176 |
surname => 'surname2 ', |
171 |
surname => 'surname2 ', |
| 177 |
categorycode => $samplecat->{categorycode}, |
172 |
categorycode => $samplecat->{categorycode}, |
| 178 |
branchcode => $samplebranch2->{branchcode}, |
173 |
branchcode => $samplebranch2->{branchcode}, |
| 179 |
); |
174 |
); |
|
|
175 |
my $borrower_2 = C4::Members::GetMember(borrowernumber => $borrower_id2); |
| 176 |
|
| 177 |
# NEED TO BE FIXED !!! |
| 178 |
# The first parameter for set_userenv is the class ref |
| 179 |
#my @USERENV = ( $borrower_id1, 'test', 'MASTERTEST', 'firstname', 'username', 'CPL', 'CPL', 'email@example.org' ); |
| 180 |
my @USERENV = ( $borrower_id1, 'test', 'MASTERTEST', 'firstname', 'CPL', 'CPL', 'email@example.org' ); |
| 181 |
|
| 182 |
C4::Context->_new_userenv('DUMMY_SESSION_ID'); |
| 183 |
C4::Context->set_userenv(@USERENV); |
| 184 |
|
| 185 |
my $userenv = C4::Context->userenv |
| 186 |
or BAIL_OUT("No userenv"); |
| 180 |
|
187 |
|
| 181 |
#Begin Tests |
188 |
#Begin Tests |
| 182 |
|
189 |
|
|
Lines 186-192
my $sth = $dbh->prepare($query);
Link Here
|
| 186 |
$sth->execute; |
193 |
$sth->execute; |
| 187 |
my $countissue = $sth -> fetchrow_array; |
194 |
my $countissue = $sth -> fetchrow_array; |
| 188 |
is ($countissue ,0, "there is no issue"); |
195 |
is ($countissue ,0, "there is no issue"); |
| 189 |
my $datedue1 = C4::Circulation::AddIssue( $borrower_id1, "code", $daysago10,0, $today, '' ); |
196 |
my $datedue1 = C4::Circulation::AddIssue( $borrower_1, "code", $daysago10,0, $today, '' ); |
| 190 |
like( |
197 |
like( |
| 191 |
$datedue1, |
198 |
$datedue1, |
| 192 |
qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, |
199 |
qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/, |
|
Lines 194-200
like(
Link Here
|
| 194 |
); |
201 |
); |
| 195 |
my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef ); |
202 |
my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef ); |
| 196 |
|
203 |
|
| 197 |
my $datedue2 = C4::Circulation::AddIssue( $borrower_id1, 'Barcode2' ); |
204 |
my $datedue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' ); |
| 198 |
is( $datedue2, undef, "AddIssue returns undef if no datedue is specified" ); |
205 |
is( $datedue2, undef, "AddIssue returns undef if no datedue is specified" ); |
| 199 |
my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef ); |
206 |
my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef ); |
| 200 |
|
207 |
|
|
Lines 242-264
is(GetItemIssue,undef,"Without parameter GetItemIssue returns undef");
Link Here
|
| 242 |
is( GetOpenIssue(), undef, "Without parameter GetOpenIssue returns undef" ); |
249 |
is( GetOpenIssue(), undef, "Without parameter GetOpenIssue returns undef" ); |
| 243 |
is( GetOpenIssue(-1), undef, |
250 |
is( GetOpenIssue(-1), undef, |
| 244 |
"With wrong parameter GetOpenIssue returns undef" ); |
251 |
"With wrong parameter GetOpenIssue returns undef" ); |
| 245 |
my $openissue = GetOpenIssue($item_id1); |
252 |
my $openissue = GetOpenIssue($borrower_id1, $item_id1); |
| 246 |
|
253 |
|
|
|
254 |
my @renewcount; |
| 247 |
#Test GetRenewCount |
255 |
#Test GetRenewCount |
| 248 |
my @renewcount = C4::Circulation::GetRenewCount(); |
256 |
$datedue2 = C4::Circulation::AddIssue( $borrower_1, 'barcode_1' ); |
|
|
257 |
isnt( $datedue2, undef, "AddIssue does not return undef if datedue is specified" ); |
| 258 |
#Without anything in DB |
| 259 |
@renewcount = C4::Circulation::GetRenewCount(); |
| 249 |
is_deeply( |
260 |
is_deeply( |
| 250 |
\@renewcount, |
261 |
\@renewcount, |
| 251 |
[ 0, 1, 1 ], |
262 |
[ 0, undef, 0 ], # FIXME Need to be fixed |
| 252 |
"Without paramater, GetRenewCount returns renewcount0,renewsallowed = 0,renewsleft = 0" |
263 |
"Without issuing rules and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0" |
| 253 |
); |
264 |
); |
| 254 |
@renewcount = C4::Circulation::GetRenewCount(-1); |
265 |
@renewcount = C4::Circulation::GetRenewCount(-1); |
| 255 |
is_deeply( |
266 |
is_deeply( |
| 256 |
\@renewcount, |
267 |
\@renewcount, |
| 257 |
[ 0, 1, 1 ], |
268 |
[ 0, undef, 0 ], # FIXME Need to be fixed |
| 258 |
"Without wrong, GetRenewCount returns renewcount0,renewsallowed = 0,renewsleft = 0" |
269 |
"Without issuing rules and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = undef, renewsleft = 0" |
|
|
270 |
); |
| 271 |
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); |
| 272 |
is_deeply( |
| 273 |
\@renewcount, |
| 274 |
[ 0, undef, 0 ], # FIXME Need to be fixed |
| 275 |
"Without issuing rules and with a valid parameter, renewcount = 0, renewsallowed = undef, renewsleft = 0" |
| 259 |
); |
276 |
); |
| 260 |
@renewcount = C4::Circulation::GetRenewCount($item_id1); |
277 |
|
| 261 |
is_deeply( \@renewcount, [ 0, 1, 1 ], "Getrenewcount of item1 returns" ); |
278 |
#With something in DB |
|
|
279 |
# Add a default rule: No renewal allowed |
| 280 |
$dbh->do(q| |
| 281 |
INSERT INTO issuingrules( categorycode, itemtype, branchcode, issuelength, renewalsallowed ) |
| 282 |
VALUES ( '*', '*', '*', 10, 0 ) |
| 283 |
|); |
| 284 |
@renewcount = C4::Circulation::GetRenewCount(); |
| 285 |
is_deeply( |
| 286 |
\@renewcount, |
| 287 |
[ 0, 0, 0 ], |
| 288 |
"With issuing rules (renewal disallowed) and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0" |
| 289 |
); |
| 290 |
@renewcount = C4::Circulation::GetRenewCount(-1); |
| 291 |
is_deeply( |
| 292 |
\@renewcount, |
| 293 |
[ 0, 0, 0 ], |
| 294 |
"With issuing rules (renewal disallowed) and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = 0, renewsleft = 0" |
| 295 |
); |
| 296 |
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); |
| 297 |
is_deeply( |
| 298 |
\@renewcount, |
| 299 |
[ 0, 0, 0 ], |
| 300 |
"With issuing rules (renewal disallowed) and with a valid parameter, Getrenewcount returns renewcount = 0, renewsallowed = 0, renewsleft = 0" |
| 301 |
); |
| 302 |
|
| 303 |
# Add a default rule: renewal is allowed |
| 304 |
$dbh->do(q| |
| 305 |
UPDATE issuingrules SET renewalsallowed = 3 |
| 306 |
|); |
| 307 |
@renewcount = C4::Circulation::GetRenewCount(); |
| 308 |
is_deeply( |
| 309 |
\@renewcount, |
| 310 |
[ 0, 3, 3 ], |
| 311 |
"With issuing rules (renewal allowed) and without parameter, GetRenewCount returns renewcount = 0, renewsallowed = 3, renewsleft = 3" |
| 312 |
); |
| 313 |
@renewcount = C4::Circulation::GetRenewCount(-1); |
| 314 |
is_deeply( |
| 315 |
\@renewcount, |
| 316 |
[ 0, 3, 3 ], |
| 317 |
"With issuing rules (renewal allowed) and without wrong parameter, GetRenewCount returns renewcount = 0, renewsallowed = 3, renewsleft = 3" |
| 318 |
); |
| 319 |
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); |
| 320 |
is_deeply( |
| 321 |
\@renewcount, |
| 322 |
[ 0, 3, 3 ], |
| 323 |
"With issuing rules (renewal allowed) and with a valid parameter, Getrenewcount of item1 returns 3 renews left" |
| 324 |
); |
| 325 |
|
| 326 |
AddRenewal( $borrower_id1, $item_id1, $samplebranch1->{branchcode}, |
| 327 |
$datedue3, $daysago10 ); |
| 328 |
@renewcount = C4::Circulation::GetRenewCount($borrower_id1, $item_id1); |
| 329 |
is_deeply( |
| 330 |
\@renewcount, |
| 331 |
[ 1, 3, 2 ], |
| 332 |
"With issuing rules (renewal allowed, 2 remaining) and with a valid parameter, Getrenewcount of item1 returns 2 renews left" |
| 333 |
); |
| 334 |
|
| 262 |
|
335 |
|
| 263 |
#End transaction |
336 |
#End transaction |
| 264 |
$dbh->rollback; |
337 |
$dbh->rollback; |
| 265 |
- |
|
|