|
Lines 220-226
$schema->storage->txn_rollback;
Link Here
|
| 220 |
|
220 |
|
| 221 |
|
221 |
|
| 222 |
subtest 'pickup_locations' => sub { |
222 |
subtest 'pickup_locations' => sub { |
| 223 |
plan tests => 25; |
223 |
plan tests => 8; |
| 224 |
|
224 |
|
| 225 |
$schema->storage->txn_begin; |
225 |
$schema->storage->txn_begin; |
| 226 |
|
226 |
|
|
Lines 249-345
subtest 'pickup_locations' => sub {
Link Here
|
| 249 |
my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
249 |
my $library4 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 250 |
my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
250 |
my $library5 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 251 |
my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
251 |
my $library6 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
|
|
252 |
my $library7 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 253 |
my $library8 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); |
| 252 |
|
254 |
|
| 253 |
my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); |
|
|
| 254 |
my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); |
| 255 |
|
| 256 |
my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
| 257 |
my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
| 258 |
|
| 259 |
my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } ); |
| 260 |
my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } ); |
| 261 |
|
| 262 |
my $biblio1 = $builder->build_object( { class => 'Koha::Biblios' } ); |
| 263 |
my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } ); |
| 264 |
my $biblio2 = $builder->build_object( { class => 'Koha::Biblios' } ); |
| 265 |
my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } ); |
| 266 |
|
| 267 |
my $item1_1 = Koha::Item->new({ |
| 268 |
biblionumber => $biblio1->biblionumber, |
| 269 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 270 |
homebranch => $library1->branchcode, |
| 271 |
holdingbranch => $library2->branchcode, |
| 272 |
itype => 'test', |
| 273 |
barcode => "item11barcode", |
| 274 |
})->store; |
| 275 |
|
| 276 |
my $item1_3 = Koha::Item->new({ |
| 277 |
biblionumber => $biblio1->biblionumber, |
| 278 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 279 |
homebranch => $library3->branchcode, |
| 280 |
holdingbranch => $library4->branchcode, |
| 281 |
itype => 'test', |
| 282 |
barcode => "item13barcode", |
| 283 |
})->store; |
| 284 |
|
| 285 |
my $item2_2 = Koha::Item->new({ |
| 286 |
biblionumber => $biblio2->biblionumber, |
| 287 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 288 |
homebranch => $library2->branchcode, |
| 289 |
holdingbranch => $library1->branchcode, |
| 290 |
itype => 'test', |
| 291 |
barcode => "item22barcode", |
| 292 |
})->store; |
| 293 |
|
| 294 |
my $item2_3 = Koha::Item->new({ |
| 295 |
biblionumber => $biblio2->biblionumber, |
| 296 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 297 |
homebranch => $library3->branchcode, |
| 298 |
holdingbranch => $library3->branchcode, |
| 299 |
itype => 'test', |
| 300 |
barcode => "item23barcode", |
| 301 |
})->store; |
| 302 |
|
| 303 |
my $item2_4 = Koha::Item->new({ |
| 304 |
biblionumber => $biblio2->biblionumber, |
| 305 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 306 |
homebranch => $library4->branchcode, |
| 307 |
holdingbranch => $library4->branchcode, |
| 308 |
itype => 'test', |
| 309 |
barcode => "item24barcode", |
| 310 |
})->store; |
| 311 |
|
| 312 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library1->branchcode } } ); |
| 313 |
my $patron4 = $builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library4->branchcode } } ); |
| 314 |
|
| 315 |
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'homebranch'); |
| 316 |
|
| 317 |
#Case 1: holdallowed any, hold_fulfillment_policy any |
| 318 |
Koha::CirculationRules->set_rules( |
255 |
Koha::CirculationRules->set_rules( |
| 319 |
{ |
256 |
{ |
| 320 |
branchcode => undef, |
257 |
branchcode => $library1->branchcode, |
| 321 |
itemtype => undef, |
|
|
| 322 |
categorycode => undef, |
| 323 |
rules => { |
| 324 |
holdallowed => 2, |
| 325 |
hold_fulfillment_policy => 'any', |
| 326 |
returnbranch => 'any' |
| 327 |
} |
| 328 |
} |
| 329 |
); |
| 330 |
|
| 331 |
my @pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
| 332 |
my @pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 333 |
my @pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 334 |
my @pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 335 |
|
| 336 |
|
| 337 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations'); |
| 338 |
|
| 339 |
#Case 2: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'homebranch' |
| 340 |
Koha::CirculationRules->set_rules( |
| 341 |
{ |
| 342 |
branchcode => undef, |
| 343 |
itemtype => undef, |
258 |
itemtype => undef, |
| 344 |
categorycode => undef, |
259 |
categorycode => undef, |
| 345 |
rules => { |
260 |
rules => { |
|
Lines 350-452
subtest 'pickup_locations' => sub {
Link Here
|
| 350 |
} |
265 |
} |
| 351 |
); |
266 |
); |
| 352 |
|
267 |
|
| 353 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 354 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 355 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 356 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 357 |
|
| 358 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries that are pickup locations, when item\'s hombebranch equals patron\' homebranch'); |
| 359 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations'); |
| 360 |
|
| 361 |
#Case 3: holdallowed holdgroup, hold_fulfillment_policy any |
| 362 |
Koha::CirculationRules->set_rules( |
268 |
Koha::CirculationRules->set_rules( |
| 363 |
{ |
269 |
{ |
| 364 |
branchcode => undef, |
270 |
branchcode => $library2->branchcode, |
| 365 |
itemtype => undef, |
271 |
itemtype => undef, |
| 366 |
categorycode => undef, |
272 |
categorycode => undef, |
| 367 |
rules => { |
273 |
rules => { |
| 368 |
holdallowed => 3, |
274 |
holdallowed => 3, |
| 369 |
hold_fulfillment_policy => 'any', |
|
|
| 370 |
returnbranch => 'any' |
| 371 |
} |
| 372 |
} |
| 373 |
); |
| 374 |
|
| 375 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
| 376 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 377 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 378 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 379 |
|
| 380 |
ok(scalar(@pl_1_1) == 5 && scalar(@pl_2_4) == 5 && scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5, 'Returns all libraries that are pickup_locations, when item\'s hombebranch is in patron\' holdgroup'); |
| 381 |
|
| 382 |
#Case 4: holdallowed any, hold_fulfillment_policy holdgroup |
| 383 |
Koha::CirculationRules->set_rules( |
| 384 |
{ |
| 385 |
branchcode => undef, |
| 386 |
itemtype => undef, |
| 387 |
categorycode => undef, |
| 388 |
rules => { |
| 389 |
holdallowed => 2, |
| 390 |
hold_fulfillment_policy => 'holdgroup', |
275 |
hold_fulfillment_policy => 'holdgroup', |
| 391 |
returnbranch => 'any' |
276 |
returnbranch => 'any' |
| 392 |
} |
277 |
} |
| 393 |
} |
278 |
} |
| 394 |
); |
279 |
); |
| 395 |
|
280 |
|
| 396 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 397 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 398 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 399 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 400 |
|
| 401 |
ok(scalar(@pl_1_1) == 3 && scalar(@pl_2_4) == 3 && scalar(@pl_1_4) == 3 && scalar(@pl_2_1) == 3, 'Returns libraries in item\'s holdgroup, and that are pickup_locations'); |
| 402 |
|
| 403 |
#Case 5: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'homebranch' |
| 404 |
Koha::CirculationRules->set_rules( |
281 |
Koha::CirculationRules->set_rules( |
| 405 |
{ |
282 |
{ |
| 406 |
branchcode => undef, |
283 |
branchcode => $library3->branchcode, |
| 407 |
itemtype => undef, |
284 |
itemtype => undef, |
| 408 |
categorycode => undef, |
285 |
categorycode => undef, |
| 409 |
rules => { |
286 |
rules => { |
| 410 |
holdallowed => 1, |
287 |
holdallowed => 3, |
| 411 |
hold_fulfillment_policy => 'holdgroup', |
288 |
hold_fulfillment_policy => 'patrongroup', |
| 412 |
returnbranch => 'any' |
289 |
returnbranch => 'any' |
| 413 |
} |
290 |
} |
| 414 |
} |
291 |
} |
| 415 |
); |
292 |
); |
| 416 |
|
293 |
|
| 417 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 418 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 419 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 420 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 421 |
|
| 422 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch equals patron\'s homebranch, and that are pickup_locations'); |
| 423 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'Returns no pickup locations'); |
| 424 |
|
| 425 |
#Case 6: holdallowed holdgroup, hold_fulfillment_policy holdgroup |
| 426 |
Koha::CirculationRules->set_rules( |
294 |
Koha::CirculationRules->set_rules( |
| 427 |
{ |
295 |
{ |
| 428 |
branchcode => undef, |
296 |
branchcode => $library4->branchcode, |
| 429 |
itemtype => undef, |
297 |
itemtype => undef, |
| 430 |
categorycode => undef, |
298 |
categorycode => undef, |
| 431 |
rules => { |
299 |
rules => { |
| 432 |
holdallowed => 3, |
300 |
holdallowed => 2, |
| 433 |
hold_fulfillment_policy => 'holdgroup', |
301 |
hold_fulfillment_policy => 'holdingbranch', |
| 434 |
returnbranch => 'any' |
302 |
returnbranch => 'any' |
| 435 |
} |
303 |
} |
| 436 |
} |
304 |
} |
| 437 |
); |
305 |
); |
| 438 |
|
306 |
|
| 439 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 440 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 441 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 442 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 443 |
|
| 444 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1, 'Returns libraries in item\'s holdgroup whose homebranch is included patron\'s holdgroup, and that are pickup_locations'); |
| 445 |
|
| 446 |
#Case 7: holdallowed any, hold_fulfillment_policy homebranch |
| 447 |
Koha::CirculationRules->set_rules( |
307 |
Koha::CirculationRules->set_rules( |
| 448 |
{ |
308 |
{ |
| 449 |
branchcode => undef, |
309 |
branchcode => $library5->branchcode, |
| 450 |
itemtype => undef, |
310 |
itemtype => undef, |
| 451 |
categorycode => undef, |
311 |
categorycode => undef, |
| 452 |
rules => { |
312 |
rules => { |
|
Lines 457-667
subtest 'pickup_locations' => sub {
Link Here
|
| 457 |
} |
317 |
} |
| 458 |
); |
318 |
); |
| 459 |
|
319 |
|
| 460 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 461 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 462 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 463 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 464 |
|
| 465 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns homebranch of items in biblio, that are pickup_locations'); |
| 466 |
|
| 467 |
#Case 8: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'homebranch' |
| 468 |
Koha::CirculationRules->set_rules( |
320 |
Koha::CirculationRules->set_rules( |
| 469 |
{ |
321 |
{ |
| 470 |
branchcode => undef, |
322 |
branchcode => $library6->branchcode, |
| 471 |
itemtype => undef, |
323 |
itemtype => undef, |
| 472 |
categorycode => undef, |
324 |
categorycode => undef, |
| 473 |
rules => { |
325 |
rules => { |
| 474 |
holdallowed => 1, |
326 |
holdallowed => 1, |
| 475 |
hold_fulfillment_policy => 'homebranch', |
327 |
hold_fulfillment_policy => 'holdgroup', |
| 476 |
returnbranch => 'any' |
328 |
returnbranch => 'any' |
| 477 |
} |
329 |
} |
| 478 |
} |
330 |
} |
| 479 |
); |
331 |
); |
| 480 |
|
332 |
|
| 481 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 482 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 483 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 484 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 485 |
|
| 486 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && $pl_1_1[0]->{branchcode} eq $library1->branchcode && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Returns homebranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations'); |
| 487 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned'); |
| 488 |
|
| 489 |
#Case 9: holdallowed holdgroup, hold_fulfillment_policy homebranch |
| 490 |
Koha::CirculationRules->set_rules( |
333 |
Koha::CirculationRules->set_rules( |
| 491 |
{ |
334 |
{ |
| 492 |
branchcode => undef, |
335 |
branchcode => $library7->branchcode, |
| 493 |
itemtype => undef, |
336 |
itemtype => undef, |
| 494 |
categorycode => undef, |
337 |
categorycode => undef, |
| 495 |
rules => { |
338 |
rules => { |
| 496 |
holdallowed => 3, |
339 |
holdallowed => 3, |
| 497 |
hold_fulfillment_policy => 'homebranch', |
|
|
| 498 |
returnbranch => 'any' |
| 499 |
} |
| 500 |
} |
| 501 |
); |
| 502 |
|
| 503 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
| 504 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 505 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 506 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 507 |
|
| 508 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio that are within patron\'s holdgroup, and that are pickup_locations'); |
| 509 |
ok(scalar(@pl_1_4) == 0, 'No pickup locations returned'); |
| 510 |
|
| 511 |
#Case 10: holdallowed any, hold_fulfillment_policy holdingbranch |
| 512 |
Koha::CirculationRules->set_rules( |
| 513 |
{ |
| 514 |
branchcode => undef, |
| 515 |
itemtype => undef, |
| 516 |
categorycode => undef, |
| 517 |
rules => { |
| 518 |
holdallowed => 2, |
| 519 |
hold_fulfillment_policy => 'holdingbranch', |
340 |
hold_fulfillment_policy => 'holdingbranch', |
| 520 |
returnbranch => 'any' |
341 |
returnbranch => 'any' |
| 521 |
} |
342 |
} |
| 522 |
} |
343 |
} |
| 523 |
); |
344 |
); |
| 524 |
|
345 |
|
| 525 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
|
|
| 526 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 527 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 528 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 529 |
|
| 530 |
ok(scalar(@pl_1_1) == 2 && scalar(@pl_1_4) == 2 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 2, 'Returns holdingbranch of items in biblio, that are pickup_locations'); |
| 531 |
|
346 |
|
| 532 |
#Case 11: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'homebranch' |
|
|
| 533 |
Koha::CirculationRules->set_rules( |
347 |
Koha::CirculationRules->set_rules( |
| 534 |
{ |
348 |
{ |
| 535 |
branchcode => undef, |
349 |
branchcode => $library8->branchcode, |
| 536 |
itemtype => undef, |
350 |
itemtype => undef, |
| 537 |
categorycode => undef, |
351 |
categorycode => undef, |
| 538 |
rules => { |
352 |
rules => { |
| 539 |
holdallowed => 1, |
353 |
holdallowed => 2, |
| 540 |
hold_fulfillment_policy => 'holdingbranch', |
354 |
hold_fulfillment_policy => 'patrongroup', |
| 541 |
returnbranch => 'any' |
355 |
returnbranch => 'any' |
| 542 |
} |
356 |
} |
| 543 |
} |
357 |
} |
| 544 |
); |
358 |
); |
| 545 |
|
359 |
|
| 546 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
360 |
my $group1_1 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library1->branchcode } } ); |
| 547 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
361 |
my $group1_2 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root1->id, branchcode => $library2->branchcode } } ); |
| 548 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
|
|
| 549 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 550 |
|
362 |
|
| 551 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio, whose homebranch equals patron\'s, and that are pickup_locations'); |
363 |
my $group2_3 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library3->branchcode } } ); |
| 552 |
ok(scalar(@pl_1_4) == 0 && scalar(@pl_2_1) == 0, 'No pickup locations returned'); |
364 |
my $group2_4 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root2->id, branchcode => $library4->branchcode } } ); |
| 553 |
|
365 |
|
| 554 |
#Case 12: holdallowed holdgroup, hold_fulfillment_policy holdingbranch |
366 |
my $group3_5 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library5->branchcode } } ); |
| 555 |
Koha::CirculationRules->set_rules( |
367 |
my $group3_6 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library6->branchcode } } ); |
| 556 |
{ |
368 |
my $group3_7 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library7->branchcode } } ); |
| 557 |
branchcode => undef, |
369 |
my $group3_8 = $builder->build_object( { class => 'Koha::Library::Groups', value => { parent_id => $root3->id, branchcode => $library8->branchcode } } ); |
| 558 |
itemtype => undef, |
|
|
| 559 |
categorycode => undef, |
| 560 |
rules => { |
| 561 |
holdallowed => 3, |
| 562 |
hold_fulfillment_policy => 'holdingbranch', |
| 563 |
returnbranch => 'any' |
| 564 |
} |
| 565 |
} |
| 566 |
); |
| 567 |
|
370 |
|
| 568 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
371 |
my $biblio1 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '1'} } ); |
| 569 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
372 |
my $biblioitem1 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio1->biblionumber } } ); |
| 570 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
373 |
my $biblio2 = $builder->build_object( { class => 'Koha::Biblios', value => {title => '2'} } ); |
| 571 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
374 |
my $biblioitem2 = $builder->build_object( { class => 'Koha::Biblioitems', value => { biblionumber => $biblio2->biblionumber } } ); |
| 572 |
|
375 |
|
| 573 |
ok(scalar(@pl_1_1) == 1 && scalar(@pl_2_4) == 1 && scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1, 'Returns holdingbranch of items in biblio, whose homebranch are within patron\'s holdgroup, and that are pickup_locations'); |
376 |
my $item1_1 = Koha::Item->new({ |
|
|
377 |
biblionumber => $biblio1->biblionumber, |
| 378 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 379 |
homebranch => $library1->branchcode, |
| 380 |
holdingbranch => $library2->branchcode, |
| 381 |
itype => 'test', |
| 382 |
barcode => "item11barcode", |
| 383 |
})->store; |
| 574 |
|
384 |
|
| 575 |
t::lib::Mocks::mock_preference('HomeOrHoldingBranch', 'holdingbranch'); |
385 |
my $item1_3 = Koha::Item->new({ |
|
|
386 |
biblionumber => $biblio1->biblionumber, |
| 387 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 388 |
homebranch => $library3->branchcode, |
| 389 |
holdingbranch => $library4->branchcode, |
| 390 |
itype => 'test', |
| 391 |
barcode => "item13barcode", |
| 392 |
})->store; |
| 576 |
|
393 |
|
| 577 |
#Case 13: holdallowed homebranch, hold_fulfillment_policy any, HomeOrHoldingBranch 'holdingbranch' |
394 |
my $item1_7 = Koha::Item->new({ |
| 578 |
Koha::CirculationRules->set_rules( |
395 |
biblionumber => $biblio1->biblionumber, |
| 579 |
{ |
396 |
biblioitemnumber => $biblioitem1->biblioitemnumber, |
| 580 |
branchcode => undef, |
397 |
homebranch => $library7->branchcode, |
| 581 |
itemtype => undef, |
398 |
holdingbranch => $library4->branchcode, |
| 582 |
categorycode => undef, |
399 |
itype => 'test', |
| 583 |
rules => { |
400 |
barcode => "item17barcode", |
| 584 |
holdallowed => 1, |
401 |
})->store; |
| 585 |
hold_fulfillment_policy => 'any', |
|
|
| 586 |
returnbranch => 'any' |
| 587 |
} |
| 588 |
} |
| 589 |
); |
| 590 |
|
402 |
|
| 591 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
403 |
my $item2_2 = Koha::Item->new({ |
| 592 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
404 |
biblionumber => $biblio2->biblionumber, |
| 593 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
405 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 594 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
406 |
homebranch => $library2->branchcode, |
|
|
407 |
holdingbranch => $library1->branchcode, |
| 408 |
itype => 'test', |
| 409 |
barcode => "item22barcode", |
| 410 |
})->store; |
| 595 |
|
411 |
|
| 596 |
ok(scalar(@pl_1_4) == 5 && scalar(@pl_2_1) == 5 && scalar(@pl_2_4) == 5, 'Returns all libraries when item\'s holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
412 |
my $item2_4 = Koha::Item->new({ |
| 597 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
413 |
biblionumber => $biblio2->biblionumber, |
|
|
414 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 415 |
homebranch => $library4->branchcode, |
| 416 |
holdingbranch => $library3->branchcode, |
| 417 |
itype => 'test', |
| 418 |
barcode => "item23barcode", |
| 419 |
})->store; |
| 598 |
|
420 |
|
| 599 |
#Case 14: holdallowed homebranch, hold_fulfillment_policy holdgroup, HomeOrHoldingBranch 'holdingbranch' |
421 |
my $item2_6 = Koha::Item->new({ |
| 600 |
Koha::CirculationRules->set_rules( |
422 |
biblionumber => $biblio2->biblionumber, |
| 601 |
{ |
423 |
biblioitemnumber => $biblioitem2->biblioitemnumber, |
| 602 |
branchcode => undef, |
424 |
homebranch => $library6->branchcode, |
| 603 |
itemtype => undef, |
425 |
holdingbranch => $library4->branchcode, |
| 604 |
categorycode => undef, |
426 |
itype => 'test', |
| 605 |
rules => { |
427 |
barcode => "item26barcode", |
| 606 |
holdallowed => 1, |
428 |
})->store; |
| 607 |
hold_fulfillment_policy => 'holdgroup', |
|
|
| 608 |
returnbranch => 'any' |
| 609 |
} |
| 610 |
} |
| 611 |
); |
| 612 |
|
429 |
|
| 613 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
430 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'1', branchcode => $library1->branchcode } } ); |
| 614 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
431 |
my $patron8 = $builder->build_object( { class => 'Koha::Patrons', value => { firstname=>'8', branchcode => $library8->branchcode } } ); |
| 615 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
|
|
| 616 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 617 |
|
432 |
|
| 618 |
ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 2 && scalar(@pl_2_4) == 1, 'Returns libraries in item\'s holdgroup whose holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
433 |
my $results = { |
| 619 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
434 |
"ItemHomeLibrary-1-1" => 6, |
|
|
435 |
"ItemHomeLibrary-1-8" => 1, |
| 436 |
"ItemHomeLibrary-2-1" => 2, |
| 437 |
"ItemHomeLibrary-2-8" => 0, |
| 438 |
"PatronLibrary-1-1" => 6, |
| 439 |
"PatronLibrary-1-8" => 3, |
| 440 |
"PatronLibrary-2-1" => 0, |
| 441 |
"PatronLibrary-2-8" => 3, |
| 442 |
}; |
| 620 |
|
443 |
|
| 621 |
#Case 15: holdallowed homebranch, hold_fulfillment_policy homebranch, HomeOrHoldingBranch 'holdingbranch' |
444 |
sub _doTest { |
| 622 |
Koha::CirculationRules->set_rules( |
445 |
my ( $cbranch, $biblio, $patron, $results ) = @_; |
| 623 |
{ |
446 |
t::lib::Mocks::mock_preference('ReservesControlBranch', $cbranch); |
| 624 |
branchcode => undef, |
|
|
| 625 |
itemtype => undef, |
| 626 |
categorycode => undef, |
| 627 |
rules => { |
| 628 |
holdallowed => 1, |
| 629 |
hold_fulfillment_policy => 'homebranch', |
| 630 |
returnbranch => 'any' |
| 631 |
} |
| 632 |
} |
| 633 |
); |
| 634 |
|
447 |
|
| 635 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
448 |
my @pl = $biblio->pickup_locations( { patron => $patron} ); |
| 636 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
|
|
| 637 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 638 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 639 |
|
449 |
|
| 640 |
#ok(scalar(@pl_2_4) == 1 && $pl_2_4[0]->{branchcode} eq $library4->branchcode, 'Pickup location for patron 4 and item 3 renders item\'s holding branch'); |
450 |
ok(scalar(@pl) == $results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}, 'ReservesControlBranch: '.$cbranch.', biblio'.$biblio->title.', patron'.$patron->firstname.' should return '.$results->{$cbranch.'-'.$biblio->title.'-'.$patron->firstname}.' but returns '.scalar(@pl)); |
| 641 |
ok(scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns homebranch of items in biblio whose holdingbranch equals patron\'s homebranch, and that are pickup_locations'); |
451 |
} |
| 642 |
ok(scalar(@pl_1_1) == 0 && scalar(@pl_1_4) == 0, 'No pickup locations returned'); |
|
|
| 643 |
|
452 |
|
| 644 |
#Case 16: holdallowed homebranch, hold_fulfillment_policy holdingbranch, HomeOrHoldingBranch 'holdingbranch' |
453 |
foreach my $cbranch ('ItemHomeLibrary','PatronLibrary') { |
| 645 |
Koha::CirculationRules->set_rules( |
454 |
foreach my $biblio ($biblio1, $biblio2) { |
| 646 |
{ |
455 |
foreach my $patron ($patron1, $patron8) { |
| 647 |
branchcode => undef, |
456 |
_doTest($cbranch, $biblio, $patron, $results); |
| 648 |
itemtype => undef, |
|
|
| 649 |
categorycode => undef, |
| 650 |
rules => { |
| 651 |
holdallowed => 1, |
| 652 |
hold_fulfillment_policy => 'holdingbranch', |
| 653 |
returnbranch => 'any' |
| 654 |
} |
457 |
} |
| 655 |
} |
458 |
} |
| 656 |
); |
459 |
} |
| 657 |
|
|
|
| 658 |
@pl_1_1 = $biblio1->pickup_locations( { patron => $patron1 } ); |
| 659 |
@pl_1_4 = $biblio1->pickup_locations( { patron => $patron4 } ); |
| 660 |
@pl_2_1 = $biblio2->pickup_locations( { patron => $patron1 } ); |
| 661 |
@pl_2_4 = $biblio2->pickup_locations( { patron => $patron4 } ); |
| 662 |
|
| 663 |
ok(scalar(@pl_1_4) == 1 && scalar(@pl_2_1) == 1 && scalar(@pl_2_4) == 1, 'Returns holdingbranch of items in biblio that equals patron\'s homebranch, and that are pickup_locations'); |
| 664 |
ok(scalar(@pl_1_1) == 0, 'No pickup locations returned'); |
| 665 |
|
460 |
|
| 666 |
$schema->storage->txn_rollback; |
461 |
$schema->storage->txn_rollback; |
| 667 |
}; |
462 |
}; |