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