|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 12; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
|
24 |
|
| 25 |
use C4::Circulation qw( AddIssue ); |
25 |
use C4::Circulation qw( AddIssue ); |
|
Lines 371-376
subtest 'cancel all with reason' => sub {
Link Here
|
| 371 |
$message->delete; |
371 |
$message->delete; |
| 372 |
}; |
372 |
}; |
| 373 |
|
373 |
|
|
|
374 |
subtest 'cancel specific hold with ModReserveCancelAll' => sub { |
| 375 |
plan tests => 9; |
| 376 |
|
| 377 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 378 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 379 |
my $item = $builder->build_sample_item( { library => $library->branchcode } ); |
| 380 |
t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); |
| 381 |
|
| 382 |
my $patron = $builder->build_object( |
| 383 |
{ |
| 384 |
class => 'Koha::Patrons', |
| 385 |
value => { branchcode => $library->branchcode, } |
| 386 |
} |
| 387 |
); |
| 388 |
|
| 389 |
my $patron2 = $builder->build_object( |
| 390 |
{ |
| 391 |
class => 'Koha::Patrons', |
| 392 |
value => { branchcode => $library2->branchcode, } |
| 393 |
} |
| 394 |
); |
| 395 |
|
| 396 |
my $reserve = C4::Reserves::AddReserve( |
| 397 |
{ |
| 398 |
branchcode => $library->branchcode, |
| 399 |
borrowernumber => $patron->borrowernumber, |
| 400 |
biblionumber => $item->biblionumber, |
| 401 |
itemnumber => $item->itemnumber, |
| 402 |
priority => 0, |
| 403 |
found => 'W', |
| 404 |
} |
| 405 |
); |
| 406 |
|
| 407 |
my $reserve2 = C4::Reserves::AddReserve( |
| 408 |
{ |
| 409 |
branchcode => $library->branchcode, |
| 410 |
borrowernumber => $patron2->borrowernumber, |
| 411 |
biblionumber => $item->biblionumber, |
| 412 |
} |
| 413 |
); |
| 414 |
|
| 415 |
my $hold = Koha::Holds->find($reserve); |
| 416 |
my $hold2 = Koha::Holds->find($reserve2); |
| 417 |
|
| 418 |
my $messages; |
| 419 |
my $nextreservinfo; |
| 420 |
|
| 421 |
# Test case where there is another hold for the same branch |
| 422 |
( $messages, $nextreservinfo ) = ModReserveCancelAll( $item->itemnumber, $hold->borrowernumber ); |
| 423 |
my $old_hold = Koha::Old::Holds->find( $hold->reserve_id ); |
| 424 |
$hold = Koha::Holds->find( $hold->reserve_id ); |
| 425 |
|
| 426 |
is( $hold, undef, 'First hold should be removed from reserves table' ); |
| 427 |
isnt( $old_hold, undef, 'First hold should be moved to old_reserves table' ); |
| 428 |
is( $hold2->priority, 1, 'Next reserve in line should be priority 1' ); |
| 429 |
is( |
| 430 |
$nextreservinfo, $hold2->borrowernumber, |
| 431 |
'ModReserveCancelAll should return the borrowernumber for the next hold in line' |
| 432 |
); |
| 433 |
is( |
| 434 |
$messages->{'waiting'}, 1, |
| 435 |
'ModReserveCancelAll should return a waiting message if next hold is for current branch' |
| 436 |
); |
| 437 |
|
| 438 |
# Test case where there is another hold for a different branch |
| 439 |
$hold2->cancel; |
| 440 |
my $reserve3 = C4::Reserves::AddReserve( |
| 441 |
{ |
| 442 |
branchcode => $library->branchcode, |
| 443 |
borrowernumber => $patron->borrowernumber, |
| 444 |
biblionumber => $item->biblionumber, |
| 445 |
itemnumber => $item->itemnumber, |
| 446 |
priority => 0, |
| 447 |
found => 'W', |
| 448 |
} |
| 449 |
); |
| 450 |
|
| 451 |
my $reserve4 = C4::Reserves::AddReserve( |
| 452 |
{ |
| 453 |
branchcode => $library2->branchcode, |
| 454 |
borrowernumber => $patron2->borrowernumber, |
| 455 |
biblionumber => $item->biblionumber, |
| 456 |
} |
| 457 |
); |
| 458 |
|
| 459 |
my $hold3 = Koha::Holds->find($reserve3); |
| 460 |
my $hold4 = Koha::Holds->find($reserve4); |
| 461 |
|
| 462 |
( $messages, $nextreservinfo ) = ModReserveCancelAll( $item->itemnumber, $hold3->borrowernumber ); |
| 463 |
is( |
| 464 |
$nextreservinfo, $hold4->borrowernumber, |
| 465 |
'ModReserveCancelAll should return the borrowernumber for the next hold in line' |
| 466 |
); |
| 467 |
is( |
| 468 |
$messages->{'transfert'}, $hold4->branchcode, |
| 469 |
'Next hold is for a different branch - ModReserveCancelAll should return its pickup branch in transfer message' |
| 470 |
); |
| 471 |
|
| 472 |
# Test case where there are no other holds |
| 473 |
$hold4->cancel; |
| 474 |
my $reserve5 = C4::Reserves::AddReserve( |
| 475 |
{ |
| 476 |
branchcode => $library->branchcode, |
| 477 |
borrowernumber => $patron->borrowernumber, |
| 478 |
biblionumber => $item->biblionumber, |
| 479 |
itemnumber => $item->itemnumber, |
| 480 |
priority => 0, |
| 481 |
found => 'W', |
| 482 |
} |
| 483 |
); |
| 484 |
|
| 485 |
my $hold5 = Koha::Holds->find($reserve5); |
| 486 |
|
| 487 |
( $messages, $nextreservinfo ) = ModReserveCancelAll( $item->itemnumber, $hold5->borrowernumber ); |
| 488 |
is( $nextreservinfo, undef, 'No more holds, nextreservinfo should not be defined' ); |
| 489 |
is( $messages, undef, 'No more holds, messages should not be defined' ); |
| 490 |
}; |
| 491 |
|
| 374 |
subtest 'Desks' => sub { |
492 |
subtest 'Desks' => sub { |
| 375 |
plan tests => 5; |
493 |
plan tests => 5; |
| 376 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
494 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 377 |
- |
|
|