Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 77; |
20 |
use Test::More tests => 78; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1405-1410
subtest 'ModReserveAffect logging' => sub {
Link Here
|
1405 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1405 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1406 |
}; |
1406 |
}; |
1407 |
|
1407 |
|
|
|
1408 |
subtest 'Waiting item is marked as lost' => sub { |
1409 |
|
1410 |
plan tests => 15; |
1411 |
|
1412 |
# Set up data |
1413 |
my $biblio = $builder->build_sample_biblio(); |
1414 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
1415 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1416 |
|
1417 |
## TEST 1: BIBLIO-LEVEL HOLD |
1418 |
|
1419 |
# place biblio-level hold |
1420 |
my $reserve_id = AddReserve({ |
1421 |
branchcode => $item->homebranch, |
1422 |
borrowernumber => $patron->borrowernumber, |
1423 |
biblionumber => $biblio->biblionumber, |
1424 |
}); |
1425 |
my $hold = Koha::Holds->find( $reserve_id ); |
1426 |
|
1427 |
is( $hold->item_level_hold, 0, 'Biblio-level hold placed' ); |
1428 |
|
1429 |
# set hold as waiting and assign item |
1430 |
$hold->set_waiting; |
1431 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1432 |
|
1433 |
# mark item in biblio as lost |
1434 |
$item->itemlost( 1 )->store; |
1435 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1436 |
|
1437 |
# do test |
1438 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1439 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1440 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1441 |
|
1442 |
# enable preference |
1443 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1444 |
|
1445 |
# try again |
1446 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1447 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1448 |
$hold = Koha::Holds->find( $reserve_id ); |
1449 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' ); |
1450 |
|
1451 |
# clean up |
1452 |
$hold->cancel; |
1453 |
$item->itemlost( 0 ); |
1454 |
|
1455 |
## TEST 2: ITEM-LEVEL HOLD, REVERT |
1456 |
|
1457 |
# place item-level hold |
1458 |
$reserve_id = AddReserve({ |
1459 |
branchcode => $item->homebranch, |
1460 |
borrowernumber => $patron->borrowernumber, |
1461 |
biblionumber => $biblio->biblionumber, |
1462 |
itemnumber => $item->itemnumber |
1463 |
}); |
1464 |
$hold = Koha::Holds->find( $reserve_id ); |
1465 |
|
1466 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1467 |
|
1468 |
# set hold as waiting and assign item |
1469 |
$hold->set_waiting; |
1470 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1471 |
|
1472 |
# mark item in biblio as lost |
1473 |
$item->itemlost( 1 ); |
1474 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1475 |
|
1476 |
# do test |
1477 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1478 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1479 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1480 |
|
1481 |
# enable preference |
1482 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1483 |
|
1484 |
# try again |
1485 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1486 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1487 |
$hold = Koha::Holds->find( $reserve_id ); |
1488 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel' ); |
1489 |
|
1490 |
# clean up |
1491 |
$hold->cancel; |
1492 |
$item->itemlost( 0 ); |
1493 |
|
1494 |
# TEST 3: ITEM-LEVEL HOLD, CANCEL |
1495 |
|
1496 |
# place item-level hold |
1497 |
$reserve_id = AddReserve({ |
1498 |
branchcode => $item->homebranch, |
1499 |
borrowernumber => $patron->borrowernumber, |
1500 |
biblionumber => $biblio->biblionumber, |
1501 |
itemnumber => $item->itemnumber |
1502 |
}); |
1503 |
$hold = Koha::Holds->find( $reserve_id ); |
1504 |
|
1505 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1506 |
|
1507 |
# set hold as waiting and assign item |
1508 |
$hold->set_waiting; |
1509 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1510 |
|
1511 |
# mark item in biblio as lost |
1512 |
$item->itemlost( 1 ); |
1513 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1514 |
|
1515 |
# do test |
1516 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1517 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1518 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1519 |
|
1520 |
# enable preference |
1521 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1522 |
|
1523 |
# try again |
1524 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1525 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1526 |
$hold = Koha::Holds->find( $reserve_id ); |
1527 |
is( Koha::Holds->find( $reserve_id ), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' ); |
1528 |
}; |
1529 |
|
1408 |
sub count_hold_print_messages { |
1530 |
sub count_hold_print_messages { |
1409 |
my $message_count = $dbh->selectall_arrayref(q{ |
1531 |
my $message_count = $dbh->selectall_arrayref(q{ |
1410 |
SELECT COUNT(*) |
1532 |
SELECT COUNT(*) |
1411 |
- |
|
|