|
Lines 24-34
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 |
|
29 |
|
| 29 |
use Koha::ActionLogs; |
30 |
use Koha::ActionLogs; |
| 30 |
use Koha::Holds; |
31 |
use Koha::Holds; |
| 31 |
use Koha::Libraries; |
32 |
use Koha::Libraries; |
|
|
33 |
use Koha::Old::Holds; |
| 32 |
|
34 |
|
| 33 |
my $schema = Koha::Database->new->schema; |
35 |
my $schema = Koha::Database->new->schema; |
| 34 |
my $builder = t::lib::TestBuilder->new; |
36 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 335-337
subtest 'is_pickup_location_valid() tests' => sub {
Link Here
|
| 335 |
|
337 |
|
| 336 |
$schema->storage->txn_rollback; |
338 |
$schema->storage->txn_rollback; |
| 337 |
}; |
339 |
}; |
| 338 |
- |
340 |
|
|
|
341 |
subtest 'cancel() tests' => sub { |
| 342 |
|
| 343 |
plan tests => 4; |
| 344 |
|
| 345 |
$schema->storage->txn_begin; |
| 346 |
|
| 347 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 348 |
|
| 349 |
# reduce the tests noise |
| 350 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 351 |
t::lib::Mocks::mock_preference( 'ExpireReservesMaxPickUpDelayCharge', |
| 352 |
undef ); |
| 353 |
|
| 354 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', undef ); |
| 355 |
|
| 356 |
# 0 == keep forever |
| 357 |
$patron->privacy(0)->store; |
| 358 |
my $hold = $builder->build_object( |
| 359 |
{ |
| 360 |
class => 'Koha::Holds', |
| 361 |
value => { borrowernumber => $patron->id, status => undef } |
| 362 |
} |
| 363 |
); |
| 364 |
$hold->cancel(); |
| 365 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 366 |
$patron->borrowernumber, 'Patron link is kept' ); |
| 367 |
|
| 368 |
# 1 == "default", meaning it is not protected from removal |
| 369 |
$patron->privacy(1)->store; |
| 370 |
$hold = $builder->build_object( |
| 371 |
{ |
| 372 |
class => 'Koha::Holds', |
| 373 |
value => { borrowernumber => $patron->id, status => undef } |
| 374 |
} |
| 375 |
); |
| 376 |
$hold->cancel(); |
| 377 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 378 |
$patron->borrowernumber, 'Patron link is kept' ); |
| 379 |
|
| 380 |
# 2 == delete immediately |
| 381 |
$patron->privacy(2)->store; |
| 382 |
$hold = $builder->build_object( |
| 383 |
{ |
| 384 |
class => 'Koha::Holds', |
| 385 |
value => { borrowernumber => $patron->id, status => undef } |
| 386 |
} |
| 387 |
); |
| 388 |
$hold->cancel(); |
| 389 |
is( Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 390 |
undef, 'Patron link is deleted immediately' ); |
| 391 |
|
| 392 |
my $anonymous_patron = $builder->build_object({ class => 'Koha::Patrons' }); |
| 393 |
t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous_patron->id ); |
| 394 |
|
| 395 |
$hold = $builder->build_object( |
| 396 |
{ |
| 397 |
class => 'Koha::Holds', |
| 398 |
value => { borrowernumber => $patron->id, status => undef } |
| 399 |
} |
| 400 |
); |
| 401 |
$hold->cancel(); |
| 402 |
is( |
| 403 |
Koha::Old::Holds->find( $hold->id )->borrowernumber, |
| 404 |
$anonymous_patron->id, |
| 405 |
'Patron link is set to the configured anonymous patron immediately' |
| 406 |
); |
| 407 |
|
| 408 |
$schema->storage->txn_rollback; |
| 409 |
}; |