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