|
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 1419-1424
subtest 'ModReserveAffect logging' => sub {
Link Here
|
| 1419 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
1419 |
like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); |
| 1420 |
}; |
1420 |
}; |
| 1421 |
|
1421 |
|
|
|
1422 |
subtest 'Waiting item is marked as lost' => sub { |
| 1423 |
|
| 1424 |
plan tests => 17; |
| 1425 |
|
| 1426 |
# Set up data |
| 1427 |
my $biblio = $builder->build_sample_biblio(); |
| 1428 |
my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 1429 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 1430 |
t::lib::Mocks::mock_preference( 'SendLostHoldNotices', 0 ); |
| 1431 |
my $original_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count; |
| 1432 |
## TEST 1: BIBLIO-LEVEL HOLD |
| 1433 |
|
| 1434 |
# place biblio-level hold |
| 1435 |
my $reserve_id = AddReserve( |
| 1436 |
{ |
| 1437 |
branchcode => $item->homebranch, |
| 1438 |
borrowernumber => $patron->borrowernumber, |
| 1439 |
biblionumber => $biblio->biblionumber, |
| 1440 |
} |
| 1441 |
); |
| 1442 |
my $hold = Koha::Holds->find($reserve_id); |
| 1443 |
|
| 1444 |
$dbh->do( |
| 1445 |
q{INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, message_transport_type, content) VALUES ('reserves','LOST_WAITING_HOLD','','Waiting hold marked lost','0','Your waiting hold has been marked lost','email',"Dear [% borrower.firstname %] [% borrowers.surname %],<br><br>Your hold awaiting pickup is no longer available. The item is lost.<br><br>Please contact the library for more information.<br><br>Thank you,<br><br>[% branch.branchname %]") } |
| 1446 |
); |
| 1447 |
|
| 1448 |
is( $hold->item_level_hold, 0, 'Biblio-level hold placed' ); |
| 1449 |
|
| 1450 |
# set hold as waiting and assign item |
| 1451 |
$hold->set( { itemnumber => $item->itemnumber } )->store; |
| 1452 |
$hold->set_waiting; |
| 1453 |
|
| 1454 |
# mark item in biblio as lost |
| 1455 |
$item->itemlost(1)->store; |
| 1456 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1457 |
|
| 1458 |
# do test |
| 1459 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
| 1460 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } ); |
| 1461 |
is( |
| 1462 |
$hold->found, 'W', |
| 1463 |
'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' |
| 1464 |
); |
| 1465 |
|
| 1466 |
# enable preference |
| 1467 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
| 1468 |
|
| 1469 |
# try again |
| 1470 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1471 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } ); |
| 1472 |
$hold = Koha::Holds->find($reserve_id); |
| 1473 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' ); |
| 1474 |
|
| 1475 |
# clean up |
| 1476 |
$hold->cancel; |
| 1477 |
$item->itemlost(0); |
| 1478 |
|
| 1479 |
## TEST 2: ITEM-LEVEL HOLD, REVERT |
| 1480 |
|
| 1481 |
# place item-level hold |
| 1482 |
$reserve_id = AddReserve( |
| 1483 |
{ |
| 1484 |
branchcode => $item->homebranch, |
| 1485 |
borrowernumber => $patron->borrowernumber, |
| 1486 |
biblionumber => $biblio->biblionumber, |
| 1487 |
itemnumber => $item->itemnumber |
| 1488 |
} |
| 1489 |
); |
| 1490 |
$hold = Koha::Holds->find($reserve_id); |
| 1491 |
|
| 1492 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
| 1493 |
|
| 1494 |
# set hold as waiting and assign item |
| 1495 |
$hold->set_waiting; |
| 1496 |
$hold->set( { itemnumber => $item->itemnumber, priority => 0 } )->store; |
| 1497 |
|
| 1498 |
# mark item in biblio as lost |
| 1499 |
$item->itemlost(1); |
| 1500 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1501 |
|
| 1502 |
# do test |
| 1503 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
| 1504 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } ); |
| 1505 |
is( |
| 1506 |
$hold->found, 'W', |
| 1507 |
'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' |
| 1508 |
); |
| 1509 |
|
| 1510 |
# enable preference |
| 1511 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
| 1512 |
|
| 1513 |
# try again |
| 1514 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1515 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } ); |
| 1516 |
$hold = Koha::Holds->find($reserve_id); |
| 1517 |
is( |
| 1518 |
$hold->found, undef, |
| 1519 |
'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel' |
| 1520 |
); |
| 1521 |
|
| 1522 |
# clean up |
| 1523 |
$hold->cancel; |
| 1524 |
$item->itemlost(0); |
| 1525 |
|
| 1526 |
my $current_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count; |
| 1527 |
is( $current_notice_count, $original_notice_count, 'No notices enqueued because SendLostHoldNotices disabled' ); |
| 1528 |
|
| 1529 |
# TEST 3: ITEM-LEVEL HOLD, CANCEL |
| 1530 |
t::lib::Mocks::mock_preference( 'SendLostHoldNotices', 1 ); |
| 1531 |
|
| 1532 |
# place item-level hold |
| 1533 |
$reserve_id = AddReserve( |
| 1534 |
{ |
| 1535 |
branchcode => $item->homebranch, |
| 1536 |
borrowernumber => $patron->borrowernumber, |
| 1537 |
biblionumber => $biblio->biblionumber, |
| 1538 |
itemnumber => $item->itemnumber |
| 1539 |
} |
| 1540 |
); |
| 1541 |
$hold = Koha::Holds->find($reserve_id); |
| 1542 |
|
| 1543 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
| 1544 |
|
| 1545 |
# set hold as waiting and assign item |
| 1546 |
$hold->set_waiting; |
| 1547 |
$hold->set( { itemnumber => $item->itemnumber, priority => 0 } )->store; |
| 1548 |
|
| 1549 |
# mark item in biblio as lost |
| 1550 |
$item->itemlost(1); |
| 1551 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1552 |
|
| 1553 |
# do test |
| 1554 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
| 1555 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 } ); |
| 1556 |
is( |
| 1557 |
$hold->found, 'W', |
| 1558 |
'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' |
| 1559 |
); |
| 1560 |
|
| 1561 |
# enable preference |
| 1562 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
| 1563 |
|
| 1564 |
# try again |
| 1565 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' ); |
| 1566 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 } ); |
| 1567 |
$hold = Koha::Holds->find($reserve_id); |
| 1568 |
is( Koha::Holds->find($reserve_id), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' ); |
| 1569 |
|
| 1570 |
$current_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count; |
| 1571 |
is( |
| 1572 |
$current_notice_count, $original_notice_count + 2, |
| 1573 |
'LOST_WAITING_HOLD notice enqueued with each call to LostItem' |
| 1574 |
); |
| 1575 |
}; |
| 1576 |
|
| 1422 |
sub count_hold_print_messages { |
1577 |
sub count_hold_print_messages { |
| 1423 |
my $message_count = $dbh->selectall_arrayref(q{ |
1578 |
my $message_count = $dbh->selectall_arrayref(q{ |
| 1424 |
SELECT COUNT(*) |
1579 |
SELECT COUNT(*) |
| 1425 |
- |
|
|