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