Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 65; |
20 |
use Test::More tests => 66; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
Lines 1190-1195
subtest 'AllowHoldOnPatronPossession test' => sub {
Link Here
|
1190 |
'Patron can place hold on an item loaned to itself'); |
1190 |
'Patron can place hold on an item loaned to itself'); |
1191 |
}; |
1191 |
}; |
1192 |
|
1192 |
|
|
|
1193 |
subtest 'Waiting item is marked as lost' => sub { |
1194 |
|
1195 |
plan tests => 15; |
1196 |
|
1197 |
# Set up data |
1198 |
my $biblio = $builder->build_sample_biblio(); |
1199 |
my $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
1200 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
1201 |
|
1202 |
## TEST 1: BIBLIO-LEVEL HOLD |
1203 |
|
1204 |
# place biblio-level hold |
1205 |
my $reserve_id = AddReserve({ |
1206 |
branchcode => $item->homebranch, |
1207 |
borrowernumber => $patron->borrowernumber, |
1208 |
biblionumber => $biblio->biblionumber, |
1209 |
}); |
1210 |
my $hold = Koha::Holds->find( $reserve_id ); |
1211 |
|
1212 |
is( $hold->item_level_hold, 0, 'Biblio-level hold placed' ); |
1213 |
|
1214 |
# set hold as waiting and assign item |
1215 |
$hold->set_waiting; |
1216 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1217 |
|
1218 |
# mark item in biblio as lost |
1219 |
$item->itemlost( 1 )->store; |
1220 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1221 |
|
1222 |
# do test |
1223 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1224 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1225 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1226 |
|
1227 |
# enable preference |
1228 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1229 |
|
1230 |
# try again |
1231 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1232 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1233 |
$hold = Koha::Holds->find( $reserve_id ); |
1234 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' ); |
1235 |
|
1236 |
# clean up |
1237 |
$hold->cancel; |
1238 |
$item->itemlost( 0 ); |
1239 |
|
1240 |
## TEST 2: ITEM-LEVEL HOLD, REVERT |
1241 |
|
1242 |
# place item-level hold |
1243 |
$reserve_id = AddReserve({ |
1244 |
branchcode => $item->homebranch, |
1245 |
borrowernumber => $patron->borrowernumber, |
1246 |
biblionumber => $biblio->biblionumber, |
1247 |
itemnumber => $item->itemnumber |
1248 |
}); |
1249 |
$hold = Koha::Holds->find( $reserve_id ); |
1250 |
|
1251 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1252 |
|
1253 |
# set hold as waiting and assign item |
1254 |
$hold->set_waiting; |
1255 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1256 |
|
1257 |
# mark item in biblio as lost |
1258 |
$item->itemlost( 1 ); |
1259 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1260 |
|
1261 |
# do test |
1262 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1263 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1264 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1265 |
|
1266 |
# enable preference |
1267 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1268 |
|
1269 |
# try again |
1270 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1271 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 }); |
1272 |
$hold = Koha::Holds->find( $reserve_id ); |
1273 |
is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel' ); |
1274 |
|
1275 |
# clean up |
1276 |
$hold->cancel; |
1277 |
$item->itemlost( 0 ); |
1278 |
|
1279 |
# TEST 3: ITEM-LEVEL HOLD, CANCEL |
1280 |
|
1281 |
# place item-level hold |
1282 |
$reserve_id = AddReserve({ |
1283 |
branchcode => $item->homebranch, |
1284 |
borrowernumber => $patron->borrowernumber, |
1285 |
biblionumber => $biblio->biblionumber, |
1286 |
itemnumber => $item->itemnumber |
1287 |
}); |
1288 |
$hold = Koha::Holds->find( $reserve_id ); |
1289 |
|
1290 |
is( $hold->item_level_hold, 1, 'Item-level hold placed' ); |
1291 |
|
1292 |
# set hold as waiting and assign item |
1293 |
$hold->set_waiting; |
1294 |
$hold->set({ itemnumber => $item->itemnumber, priority => 0 })->store; |
1295 |
|
1296 |
# mark item in biblio as lost |
1297 |
$item->itemlost( 1 ); |
1298 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1299 |
|
1300 |
# do test |
1301 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 ); |
1302 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1303 |
is( $hold->found, 'W', 'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled' ); |
1304 |
|
1305 |
# enable preference |
1306 |
t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 ); |
1307 |
|
1308 |
# try again |
1309 |
is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost'); |
1310 |
C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 }); |
1311 |
$hold = Koha::Holds->find( $reserve_id ); |
1312 |
is( Koha::Holds->find( $reserve_id ), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' ); |
1313 |
}; |
1314 |
|
1193 |
sub count_hold_print_messages { |
1315 |
sub count_hold_print_messages { |
1194 |
my $message_count = $dbh->selectall_arrayref(q{ |
1316 |
my $message_count = $dbh->selectall_arrayref(q{ |
1195 |
SELECT COUNT(*) |
1317 |
SELECT COUNT(*) |
1196 |
- |
|
|