Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 66; |
20 |
use Test::More tests => 67; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1218-1223
subtest 'MergeHolds' => sub {
Link Here
|
1218 |
is( $biblio_2->holds->count, 1, 'Hold has been transferred' ); |
1218 |
is( $biblio_2->holds->count, 1, 'Hold has been transferred' ); |
1219 |
}; |
1219 |
}; |
1220 |
|
1220 |
|
|
|
1221 |
subtest 'Waiting item is marked as lost' => sub { |
1222 |
|
1223 |
plan tests => 15; |
1224 |
|
1225 |
# Set up data |
1226 |
my $biblio = $builder->build_sample_biblio(); |
1227 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
1228 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1229 |
|
1230 |
## TEST 1: BIBLIO-LEVEL HOLD |
1231 |
|
1232 |
# place biblio-level hold |
1233 |
my $reserve_id = AddReserve({ |
1234 |
branchcode => $item->homebranch, |
1235 |
borrowernumber => $patron->borrowernumber, |
1236 |
biblionumber => $biblio->biblionumber, |
1237 |
}); |
1238 |
my $hold = Koha::Holds->find( $reserve_id ); |
1239 |
|
1240 |
is( $hold->item_level_hold, 0, 'Biblio-level hold placed' ); |
1241 |
|
1242 |
# set hold as waiting and assign item |
1243 |
$hold->set_waiting; |
1244 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1245 |
|
1246 |
# mark item in biblio as lost |
1247 |
$item->itemlost( 1 )->store; |
1248 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1249 |
|
1250 |
# do test |
1251 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1252 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1253 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1254 |
|
1255 |
# enable preference |
1256 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1257 |
|
1258 |
# try again |
1259 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1260 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1261 |
$hold = Koha::Holds->find( $reserve_id ); |
1262 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' ); |
1263 |
|
1264 |
# clean up |
1265 |
$hold->cancel; |
1266 |
$item->itemlost( 0 ); |
1267 |
|
1268 |
## TEST 2: ITEM-LEVEL HOLD, REVERT |
1269 |
|
1270 |
# place item-level hold |
1271 |
$reserve_id = AddReserve({ |
1272 |
branchcode => $item->homebranch, |
1273 |
borrowernumber => $patron->borrowernumber, |
1274 |
biblionumber => $biblio->biblionumber, |
1275 |
itemnumber => $item->itemnumber |
1276 |
}); |
1277 |
$hold = Koha::Holds->find( $reserve_id ); |
1278 |
|
1279 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1280 |
|
1281 |
# set hold as waiting and assign item |
1282 |
$hold->set_waiting; |
1283 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1284 |
|
1285 |
# mark item in biblio as lost |
1286 |
$item->itemlost( 1 ); |
1287 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1288 |
|
1289 |
# do test |
1290 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1291 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1292 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1293 |
|
1294 |
# enable preference |
1295 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1296 |
|
1297 |
# try again |
1298 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1299 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1300 |
$hold = Koha::Holds->find( $reserve_id ); |
1301 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel' ); |
1302 |
|
1303 |
# clean up |
1304 |
$hold->cancel; |
1305 |
$item->itemlost( 0 ); |
1306 |
|
1307 |
# TEST 3: ITEM-LEVEL HOLD, CANCEL |
1308 |
|
1309 |
# place item-level hold |
1310 |
$reserve_id = AddReserve({ |
1311 |
branchcode => $item->homebranch, |
1312 |
borrowernumber => $patron->borrowernumber, |
1313 |
biblionumber => $biblio->biblionumber, |
1314 |
itemnumber => $item->itemnumber |
1315 |
}); |
1316 |
$hold = Koha::Holds->find( $reserve_id ); |
1317 |
|
1318 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1319 |
|
1320 |
# set hold as waiting and assign item |
1321 |
$hold->set_waiting; |
1322 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1323 |
|
1324 |
# mark item in biblio as lost |
1325 |
$item->itemlost( 1 ); |
1326 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1327 |
|
1328 |
# do test |
1329 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1330 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1331 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1332 |
|
1333 |
# enable preference |
1334 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1335 |
|
1336 |
# try again |
1337 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1338 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1339 |
$hold = Koha::Holds->find( $reserve_id ); |
1340 |
is( Koha::Holds->find( $reserve_id ), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' ); |
1341 |
}; |
1342 |
|
1221 |
sub count_hold_print_messages { |
1343 |
sub count_hold_print_messages { |
1222 |
my $message_count = $dbh->selectall_arrayref(q{ |
1344 |
my $message_count = $dbh->selectall_arrayref(q{ |
1223 |
SELECT COUNT(*) |
1345 |
SELECT COUNT(*) |
1224 |
- |
|
|