|
Lines 24-35
use Test::More tests => 5;
Link Here
|
| 24 |
use Test::Exception; |
24 |
use Test::Exception; |
| 25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
| 26 |
|
26 |
|
|
|
27 |
use t::lib::Mocks; |
| 27 |
use t::lib::TestBuilder; |
28 |
use t::lib::TestBuilder; |
| 28 |
use t::lib::Mocks; |
29 |
use t::lib::Mocks; |
| 29 |
|
30 |
|
| 30 |
use Koha::ActionLogs; |
31 |
use Koha::ActionLogs; |
| 31 |
use Koha::Holds; |
32 |
use Koha::Holds; |
| 32 |
use Koha::Libraries; |
33 |
use Koha::Libraries; |
|
|
34 |
use Koha::Old::Holds; |
| 33 |
|
35 |
|
| 34 |
my $schema = Koha::Database->new->schema; |
36 |
my $schema = Koha::Database->new->schema; |
| 35 |
my $builder = t::lib::TestBuilder->new; |
37 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 382-384
subtest 'is_pickup_location_valid() tests' => sub {
Link Here
|
| 382 |
|
384 |
|
| 383 |
$schema->storage->txn_rollback; |
385 |
$schema->storage->txn_rollback; |
| 384 |
}; |
386 |
}; |
| 385 |
- |
387 |
|
|
|
388 |
subtest 'cancel() tests' => sub { |
| 389 |
|
| 390 |
plan tests => 4; |
| 391 |
|
| 392 |
$schema->storage->txn_begin; |
| 393 |
|
| 394 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 395 |
|
| 396 |
# reduce the tests noise |
| 397 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 398 |
t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', |
| 399 |
undef ); |
| 400 |
|
| 401 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); |
| 402 |
|
| 403 |
# 0 == keep forever |
| 404 |
$patron->privacy(0)->store; |
| 405 |
my $hold = $builder->build_object( |
| 406 |
{ |
| 407 |
class => 'Koha::Holds', |
| 408 |
value => { borrowernumber => $patron->id, status => undef } |
| 409 |
} |
| 410 |
); |
| 411 |
$hold->cancel(); |
| 412 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 413 |
$patron->borrowernumber, 'Patron link is kept' ); |
| 414 |
|
| 415 |
# 1 == "default", meaning it is not protected from removal |
| 416 |
$patron->privacy(1)->store; |
| 417 |
$hold = $builder->build_object( |
| 418 |
{ |
| 419 |
class => 'Koha::Holds', |
| 420 |
value => { borrowernumber => $patron->id, status => undef } |
| 421 |
} |
| 422 |
); |
| 423 |
$hold->cancel(); |
| 424 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 425 |
$patron->borrowernumber, 'Patron link is kept' ); |
| 426 |
|
| 427 |
# 2 == delete immediately |
| 428 |
$patron->privacy(2)->store; |
| 429 |
$hold = $builder->build_object( |
| 430 |
{ |
| 431 |
class => 'Koha::Holds', |
| 432 |
value => { borrowernumber => $patron->id, status => undef } |
| 433 |
} |
| 434 |
); |
| 435 |
$hold->cancel(); |
| 436 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 437 |
undef, 'Patron link is deleted immediately' ); |
| 438 |
|
| 439 |
my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 440 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); |
| 441 |
|
| 442 |
$hold = $builder->build_object( |
| 443 |
{ |
| 444 |
class => 'Koha::Holds', |
| 445 |
value => { borrowernumber => $patron->id, status => undef } |
| 446 |
} |
| 447 |
); |
| 448 |
$hold->cancel(); |
| 449 |
is( |
| 450 |
Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 451 |
$anonymous_patron->id, |
| 452 |
'Patron link is set to the configured anonymous patron immediately' |
| 453 |
); |
| 454 |
|
| 455 |
$schema->storage->txn_rollback; |
| 456 |
}; |