Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 68; |
20 |
use Test::More tests => 69; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1332-1337
subtest 'ModReserveAffect logging' => sub {
Link Here
|
1332 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1332 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1333 |
}; |
1333 |
}; |
1334 |
|
1334 |
|
|
|
1335 |
subtest 'Waiting item is marked as lost' => sub { |
1336 |
|
1337 |
plan tests => 15; |
1338 |
|
1339 |
# Set up data |
1340 |
my $biblio = $builder->build_sample_biblio(); |
1341 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
1342 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1343 |
|
1344 |
## TEST 1: BIBLIO-LEVEL HOLD |
1345 |
|
1346 |
# place biblio-level hold |
1347 |
my $reserve_id = AddReserve({ |
1348 |
branchcode => $item->homebranch, |
1349 |
borrowernumber => $patron->borrowernumber, |
1350 |
biblionumber => $biblio->biblionumber, |
1351 |
}); |
1352 |
my $hold = Koha::Holds->find( $reserve_id ); |
1353 |
|
1354 |
is( $hold->item_level_hold, 0, 'Biblio-level hold placed' ); |
1355 |
|
1356 |
# set hold as waiting and assign item |
1357 |
$hold->set_waiting; |
1358 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1359 |
|
1360 |
# mark item in biblio as lost |
1361 |
$item->itemlost( 1 )->store; |
1362 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1363 |
|
1364 |
# do test |
1365 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1366 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1367 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1368 |
|
1369 |
# enable preference |
1370 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1371 |
|
1372 |
# try again |
1373 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1374 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1375 |
$hold = Koha::Holds->find( $reserve_id ); |
1376 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' ); |
1377 |
|
1378 |
# clean up |
1379 |
$hold->cancel; |
1380 |
$item->itemlost( 0 ); |
1381 |
|
1382 |
## TEST 2: ITEM-LEVEL HOLD, REVERT |
1383 |
|
1384 |
# place item-level hold |
1385 |
$reserve_id = AddReserve({ |
1386 |
branchcode => $item->homebranch, |
1387 |
borrowernumber => $patron->borrowernumber, |
1388 |
biblionumber => $biblio->biblionumber, |
1389 |
itemnumber => $item->itemnumber |
1390 |
}); |
1391 |
$hold = Koha::Holds->find( $reserve_id ); |
1392 |
|
1393 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1394 |
|
1395 |
# set hold as waiting and assign item |
1396 |
$hold->set_waiting; |
1397 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1398 |
|
1399 |
# mark item in biblio as lost |
1400 |
$item->itemlost( 1 ); |
1401 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1402 |
|
1403 |
# do test |
1404 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1405 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1406 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1407 |
|
1408 |
# enable preference |
1409 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1410 |
|
1411 |
# try again |
1412 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1413 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1414 |
$hold = Koha::Holds->find( $reserve_id ); |
1415 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel' ); |
1416 |
|
1417 |
# clean up |
1418 |
$hold->cancel; |
1419 |
$item->itemlost( 0 ); |
1420 |
|
1421 |
# TEST 3: ITEM-LEVEL HOLD, CANCEL |
1422 |
|
1423 |
# place item-level hold |
1424 |
$reserve_id = AddReserve({ |
1425 |
branchcode => $item->homebranch, |
1426 |
borrowernumber => $patron->borrowernumber, |
1427 |
biblionumber => $biblio->biblionumber, |
1428 |
itemnumber => $item->itemnumber |
1429 |
}); |
1430 |
$hold = Koha::Holds->find( $reserve_id ); |
1431 |
|
1432 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1433 |
|
1434 |
# set hold as waiting and assign item |
1435 |
$hold->set_waiting; |
1436 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1437 |
|
1438 |
# mark item in biblio as lost |
1439 |
$item->itemlost( 1 ); |
1440 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1441 |
|
1442 |
# do test |
1443 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1444 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1445 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1446 |
|
1447 |
# enable preference |
1448 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1449 |
|
1450 |
# try again |
1451 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1452 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1453 |
$hold = Koha::Holds->find( $reserve_id ); |
1454 |
is( Koha::Holds->find( $reserve_id ), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' ); |
1455 |
}; |
1456 |
|
1335 |
sub count_hold_print_messages { |
1457 |
sub count_hold_print_messages { |
1336 |
my $message_count = $dbh->selectall_arrayref(q{ |
1458 |
my $message_count = $dbh->selectall_arrayref(q{ |
1337 |
SELECT COUNT(*) |
1459 |
SELECT COUNT(*) |
1338 |
- |
|
|