|
Lines 7-23
use C4::Branch;
Link Here
|
| 7 |
use C4::Circulation; |
7 |
use C4::Circulation; |
| 8 |
use C4::Items; |
8 |
use C4::Items; |
| 9 |
use C4::Context; |
9 |
use C4::Context; |
| 10 |
|
10 |
use Data::Dumper; |
| 11 |
use Test::More tests => 10; |
11 |
use Test::More tests => 13; |
| 12 |
|
12 |
|
| 13 |
BEGIN { |
13 |
BEGIN { |
| 14 |
use_ok('C4::Circulation'); |
14 |
use_ok('C4::Circulation'); |
| 15 |
} |
15 |
} |
| 16 |
|
16 |
|
| 17 |
can_ok( 'C4::Circulation', qw( |
17 |
can_ok( 'C4::Circulation', qw( |
| 18 |
GetBranchBorrowerCircRule |
18 |
AddIssue |
| 19 |
GetBranchItemRule |
19 |
AddReturn |
| 20 |
) |
20 |
GetBranchBorrowerCircRule |
|
|
21 |
GetBranchItemRule |
| 22 |
GetIssuingRule |
| 23 |
) |
| 21 |
); |
24 |
); |
| 22 |
|
25 |
|
| 23 |
#Start transaction |
26 |
#Start transaction |
|
Lines 160-165
$sth->execute(
Link Here
|
| 160 |
$sampleitemtype2->{imageurl}, $sampleitemtype2->{summary} |
163 |
$sampleitemtype2->{imageurl}, $sampleitemtype2->{summary} |
| 161 |
); |
164 |
); |
| 162 |
|
165 |
|
|
|
166 |
#Add biblio and item |
| 167 |
my $record = MARC::Record->new(); |
| 168 |
$record->append_fields( |
| 169 |
MARC::Field->new( '952', '0', '0', a => $samplebranch1->{branchcode} ) ); |
| 170 |
my ( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $record, '' ); |
| 171 |
|
| 172 |
# item 2 has home branch and holding branch samplebranch1 |
| 173 |
my @sampleitem1 = C4::Items::AddItem( |
| 174 |
{ |
| 175 |
barcode => 'barcode_1', |
| 176 |
itemcallnumber => 'callnumber1', |
| 177 |
homebranch => $samplebranch1->{branchcode}, |
| 178 |
holdingbranch => $samplebranch1->{branchcode} |
| 179 |
}, |
| 180 |
$biblionumber |
| 181 |
); |
| 182 |
my $item_id1 = $sampleitem1[2]; |
| 183 |
|
| 184 |
# item 2 has holding branch samplebranch2 |
| 185 |
my @sampleitem2 = C4::Items::AddItem( |
| 186 |
{ |
| 187 |
barcode => 'barcode_2', |
| 188 |
itemcallnumber => 'callnumber2', |
| 189 |
homebranch => $samplebranch2->{branchcode}, |
| 190 |
holdingbranch => $samplebranch1->{branchcode} |
| 191 |
}, |
| 192 |
$biblionumber |
| 193 |
); |
| 194 |
my $item_id2 = $sampleitem2[2]; |
| 195 |
|
| 196 |
# item 3 has item type sampleitemtype2 with noreturn policy |
| 197 |
my @sampleitem3 = C4::Items::AddItem( |
| 198 |
{ |
| 199 |
barcode => 'barcode_3', |
| 200 |
itemcallnumber => 'callnumber3', |
| 201 |
homebranch => $samplebranch2->{branchcode}, |
| 202 |
holdingbranch => $samplebranch2->{branchcode}, |
| 203 |
itype => $sampleitemtype2->{itemtype} |
| 204 |
}, |
| 205 |
$biblionumber |
| 206 |
); |
| 207 |
my $item_id3 = $sampleitem3[2]; |
| 208 |
|
| 209 |
#Add borrower |
| 210 |
my $borrower_id1 = C4::Members::AddMember( |
| 211 |
firstname => 'firstname1', |
| 212 |
surname => 'surname1 ', |
| 213 |
categorycode => $samplecat->{categorycode}, |
| 214 |
branchcode => $samplebranch1->{branchcode}, |
| 215 |
); |
| 216 |
my $borrower_1 = C4::Members::GetMember(borrowernumber => $borrower_id1); |
| 217 |
|
| 163 |
$query = |
218 |
$query = |
| 164 |
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)"; |
219 |
"INSERT INTO branch_borrower_circ_rules (branchcode,categorycode,maxissueqty) VALUES( ?,?,?)"; |
| 165 |
$dbh->do( |
220 |
$dbh->do( |
|
Lines 167-179
$dbh->do(
Link Here
|
| 167 |
$samplebranch1->{branchcode}, |
222 |
$samplebranch1->{branchcode}, |
| 168 |
$samplecat->{categorycode}, 5 |
223 |
$samplecat->{categorycode}, 5 |
| 169 |
); |
224 |
); |
| 170 |
$query = |
225 |
|
| 171 |
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
|
|
| 172 |
$dbh->do( $query, {}, $samplebranch2->{branchcode}, |
| 173 |
3, 1, $samplebranch2->{branchcode} ); |
| 174 |
$query = |
226 |
$query = |
| 175 |
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
227 |
"INSERT INTO default_circ_rules (singleton,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
| 176 |
$dbh->do( $query, {}, 'singleton', 4, 3, $samplebranch1->{branchcode} ); |
228 |
$dbh->do( $query, {}, 'singleton', 4, 3, 'homebranch' ); |
|
|
229 |
|
| 230 |
$query = |
| 231 |
"INSERT INTO default_branch_circ_rules (branchcode,maxissueqty,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
| 232 |
$dbh->do( $query, {}, $samplebranch2->{branchcode}, 3, 1, 'holdingbranch' ); |
| 177 |
|
233 |
|
| 178 |
$query = |
234 |
$query = |
| 179 |
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
235 |
"INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; |
|
Lines 181-192
$sth = $dbh->prepare($query);
Link Here
|
| 181 |
$sth->execute( |
237 |
$sth->execute( |
| 182 |
$samplebranch1->{branchcode}, |
238 |
$samplebranch1->{branchcode}, |
| 183 |
$sampleitemtype1->{itemtype}, |
239 |
$sampleitemtype1->{itemtype}, |
| 184 |
5, $samplebranch1->{branchcode} |
240 |
5, 'homebranch' |
|
|
241 |
); |
| 242 |
$sth->execute( |
| 243 |
$samplebranch2->{branchcode}, |
| 244 |
$sampleitemtype1->{itemtype}, |
| 245 |
5, 'holdingbranch' |
| 185 |
); |
246 |
); |
| 186 |
$sth->execute( |
247 |
$sth->execute( |
| 187 |
$samplebranch2->{branchcode}, |
248 |
$samplebranch2->{branchcode}, |
| 188 |
$sampleitemtype2->{itemtype}, |
249 |
$sampleitemtype2->{itemtype}, |
| 189 |
5, $samplebranch1->{branchcode} |
250 |
5, 'noreturn' |
| 190 |
); |
251 |
); |
| 191 |
|
252 |
|
| 192 |
#Test GetBranchBorrowerCircRule |
253 |
#Test GetBranchBorrowerCircRule |
|
Lines 220-242
is_deeply(
Link Here
|
| 220 |
$samplebranch1->{branchcode}, |
281 |
$samplebranch1->{branchcode}, |
| 221 |
$sampleitemtype1->{itemtype} |
282 |
$sampleitemtype1->{itemtype} |
| 222 |
), |
283 |
), |
| 223 |
{ returnbranch => $samplebranch1->{branchcode}, holdallowed => 5 }, |
284 |
{ returnbranch => 'homebranch', holdallowed => 5 }, |
| 224 |
"GetBranchitem returns holdallowed and return branch" |
285 |
"GetBranchitem returns holdallowed and return branch" |
| 225 |
); |
286 |
); |
| 226 |
is_deeply( |
287 |
is_deeply( |
| 227 |
GetBranchItemRule(), |
288 |
GetBranchItemRule(), |
| 228 |
{ returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 }, |
289 |
{ returnbranch => 'homebranch', holdallowed => 3 }, |
| 229 |
"Without parameters GetBranchItemRule returns the values in default_circ_rules" |
290 |
"Without parameters GetBranchItemRule returns the values in default_circ_rules" |
| 230 |
); |
291 |
); |
| 231 |
is_deeply( |
292 |
is_deeply( |
| 232 |
GetBranchItemRule( $samplebranch1->{branchcode} ), |
293 |
GetBranchItemRule( $samplebranch2->{branchcode} ), |
| 233 |
{ returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 }, |
294 |
{ returnbranch => 'holdingbranch', holdallowed => 1 }, |
| 234 |
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules" |
295 |
"With only a branchcode GetBranchItemRule returns values in default_branch_circ_rules" |
| 235 |
); |
296 |
); |
| 236 |
is_deeply( |
297 |
is_deeply( |
| 237 |
GetBranchItemRule( -1, -1 ), |
298 |
GetBranchItemRule( -1, -1 ), |
| 238 |
{ returnbranch => $samplebranch1->{branchcode}, holdallowed => 3 }, |
299 |
{ returnbranch => 'homebranch', holdallowed => 3 }, |
| 239 |
"With only one parametern GetBranchItemRule returns default values" |
300 |
"With only one parametern GetBranchItemRule returns default values" |
| 240 |
); |
301 |
); |
| 241 |
|
302 |
|
|
|
303 |
# Test return policies |
| 304 |
C4::Context->set_preference('AutomaticItemReturn','0'); |
| 305 |
|
| 306 |
# item1 returned at branch2 should trigger transfer to homebranch |
| 307 |
$query = |
| 308 |
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )"; |
| 309 |
$dbh->do( $query, {}, $borrower_id1, $item_id1, $samplebranch1->{branchcode} ); |
| 310 |
|
| 311 |
my ($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_1', |
| 312 |
$samplebranch2->{branchcode}); |
| 313 |
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects default return policy - return to homebranch" ); |
| 314 |
|
| 315 |
# item2 returned at branch2 should trigger transfer to holding branch |
| 316 |
$query = |
| 317 |
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )"; |
| 318 |
$dbh->do( $query, {}, $borrower_id1, $item_id2, $samplebranch2->{branchcode} ); |
| 319 |
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_2', |
| 320 |
$samplebranch2->{branchcode}); |
| 321 |
is( $messages->{NeedsTransfer}, $samplebranch1->{branchcode}, "AddReturn respects branch return policy - item2->homebranch policy = 'holdingbranch'" ); |
| 322 |
|
| 323 |
# item3 should not trigger transfer - floating collection |
| 324 |
$query = |
| 325 |
"INSERT INTO issues (borrowernumber,itemnumber,branchcode) VALUES( ?,?,? )"; |
| 326 |
$dbh->do( $query, {}, $borrower_id1, $item_id3, $samplebranch1->{branchcode} ); |
| 327 |
($doreturn, $messages, $iteminformation, $borrower) = AddReturn('barcode_3', |
| 328 |
$samplebranch1->{branchcode}); |
| 329 |
is($messages->{NeedsTransfer},undef,"AddReturn respects branch item return policy - noreturn"); |
| 330 |
|
| 331 |
|
| 242 |
$dbh->rollback; |
332 |
$dbh->rollback; |
| 243 |
- |
|
|