Lines 20-26
Link Here
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use utf8; |
21 |
use utf8; |
22 |
|
22 |
|
23 |
use Test::More tests => 34; |
23 |
use Test::More tests => 35; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
Lines 1198-1205
subtest 'Tests for itemtype|item_type' => sub {
Link Here
|
1198 |
$schema->storage->txn_rollback; |
1198 |
$schema->storage->txn_rollback; |
1199 |
}; |
1199 |
}; |
1200 |
|
1200 |
|
|
|
1201 |
subtest 'get_transfer' => sub { |
1202 |
plan tests => 8; |
1203 |
$schema->storage->txn_begin; |
1204 |
|
1205 |
my $item = $builder->build_sample_item(); |
1206 |
|
1207 |
my $transfer = $item->get_transfer(); |
1208 |
is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' ); |
1209 |
|
1210 |
my $library_to = $builder->build( { source => 'Branch' } ); |
1211 |
|
1212 |
my $transfer_1 = $builder->build_object( |
1213 |
{ |
1214 |
class => 'Koha::Item::Transfers', |
1215 |
value => { |
1216 |
itemnumber => $item->itemnumber, |
1217 |
frombranch => $item->holdingbranch, |
1218 |
tobranch => $library_to->{branchcode}, |
1219 |
reason => 'Manual', |
1220 |
datesent => undef, |
1221 |
datearrived => undef, |
1222 |
datecancelled => undef, |
1223 |
daterequested => \'NOW()' |
1224 |
} |
1225 |
} |
1226 |
); |
1227 |
|
1228 |
$transfer = $item->get_transfer(); |
1229 |
is( |
1230 |
ref($transfer), 'Koha::Item::Transfer', |
1231 |
'Koha::Item->get_transfer should return a Koha::Item::Transfer object' |
1232 |
); |
1233 |
|
1234 |
my $transfer_2 = $builder->build_object( |
1235 |
{ |
1236 |
class => 'Koha::Item::Transfers', |
1237 |
value => { |
1238 |
itemnumber => $item->itemnumber, |
1239 |
frombranch => $item->holdingbranch, |
1240 |
tobranch => $library_to->{branchcode}, |
1241 |
reason => 'Manual', |
1242 |
datesent => undef, |
1243 |
datearrived => undef, |
1244 |
datecancelled => undef, |
1245 |
daterequested => \'NOW()' |
1246 |
} |
1247 |
} |
1248 |
); |
1249 |
|
1250 |
$transfer = $item->get_transfer(); |
1251 |
is( |
1252 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1253 |
'Koha::Item->get_transfer returns the oldest transfer request' |
1254 |
); |
1255 |
|
1256 |
$transfer_2->datesent( \'NOW()' )->store; |
1257 |
$transfer = $item->get_transfer(); |
1258 |
is( |
1259 |
$transfer->branchtransfer_id, $transfer_2->branchtransfer_id, |
1260 |
'Koha::Item->get_transfer returns the in_transit transfer' |
1261 |
); |
1262 |
|
1263 |
my $transfer_3 = $builder->build_object( |
1264 |
{ |
1265 |
class => 'Koha::Item::Transfers', |
1266 |
value => { |
1267 |
itemnumber => $item->itemnumber, |
1268 |
frombranch => $item->holdingbranch, |
1269 |
tobranch => $library_to->{branchcode}, |
1270 |
reason => 'Manual', |
1271 |
datesent => undef, |
1272 |
datearrived => undef, |
1273 |
datecancelled => undef, |
1274 |
daterequested => \'NOW()' |
1275 |
} |
1276 |
} |
1277 |
); |
1278 |
|
1279 |
$transfer_2->datearrived( \'NOW()' )->store; |
1280 |
$transfer = $item->get_transfer(); |
1281 |
is( |
1282 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1283 |
'Koha::Item->get_transfer returns the next queued transfer' |
1284 |
); |
1285 |
is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' ); |
1286 |
|
1287 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1288 |
$transfer = $item->get_transfer(); |
1289 |
is( |
1290 |
$transfer->branchtransfer_id, $transfer_3->branchtransfer_id, |
1291 |
'Koha::Item->get_transfer ignores cancelled transfers' |
1292 |
); |
1293 |
|
1294 |
subtest "Ensure prefetches don't affect which transfer if returned" => sub { |
1295 |
plan tests => 5; |
1296 |
|
1297 |
# Reset test data |
1298 |
$transfer_1->datecancelled(undef)->store; |
1299 |
$transfer_2->set( { datesent => undef, datearrived => undef } )->store; |
1300 |
|
1301 |
my $prefetched_item = Koha::Items->search( |
1302 |
{ 'me.itemnumber' => $item->itemnumber }, |
1303 |
{ prefetch => ['current_branchtransfers'] } |
1304 |
)->next; |
1305 |
|
1306 |
$transfer = $prefetched_item->get_transfer(); |
1307 |
is( |
1308 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1309 |
'Koha::Item->get_transfer returns the oldest transfer request' |
1310 |
); |
1311 |
|
1312 |
$transfer_2->datesent( \'NOW()' )->store; |
1313 |
$prefetched_item = Koha::Items->search( |
1314 |
{ 'me.itemnumber' => $item->itemnumber }, |
1315 |
{ prefetch => ['current_branchtransfers'] } |
1316 |
)->next; |
1317 |
|
1318 |
$transfer = $prefetched_item->get_transfer(); |
1319 |
is( |
1320 |
$transfer->branchtransfer_id, $transfer_2->branchtransfer_id, |
1321 |
'Koha::Item->get_transfer returns the in_transit transfer' |
1322 |
); |
1323 |
|
1324 |
$transfer_2->datearrived( \'NOW()' )->store; |
1325 |
$prefetched_item = Koha::Items->search( |
1326 |
{ 'me.itemnumber' => $item->itemnumber }, |
1327 |
{ prefetch => ['current_branchtransfers'] } |
1328 |
)->next; |
1329 |
$transfer = $prefetched_item->get_transfer(); |
1330 |
is( |
1331 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1332 |
'Koha::Item->get_transfer returns the next queued transfer' |
1333 |
); |
1334 |
is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' ); |
1335 |
|
1336 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1337 |
$prefetched_item = Koha::Items->search( |
1338 |
{ 'me.itemnumber' => $item->itemnumber }, |
1339 |
{ prefetch => ['current_branchtransfers'] } |
1340 |
)->next; |
1341 |
$transfer = $prefetched_item->get_transfer(); |
1342 |
is( |
1343 |
$transfer->branchtransfer_id, $transfer_3->branchtransfer_id, |
1344 |
'Koha::Item->get_transfer ignores cancelled transfers' |
1345 |
); |
1346 |
}; |
1347 |
$schema->storage->txn_rollback; |
1348 |
}; |
1349 |
|
1201 |
subtest 'get_transfers' => sub { |
1350 |
subtest 'get_transfers' => sub { |
1202 |
plan tests => 16; |
1351 |
plan tests => 17; |
1203 |
$schema->storage->txn_begin; |
1352 |
$schema->storage->txn_begin; |
1204 |
|
1353 |
|
1205 |
my $item = $builder->build_sample_item(); |
1354 |
my $item = $builder->build_sample_item(); |
Lines 1294-1299
subtest 'get_transfers' => sub {
Link Here
|
1294 |
$result_1 = $transfers->next; |
1443 |
$result_1 = $transfers->next; |
1295 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1444 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1296 |
|
1445 |
|
|
|
1446 |
subtest "Ensure prefetches don't affect the return order" => sub { |
1447 |
plan tests => 13; |
1448 |
|
1449 |
# Reset test data |
1450 |
$transfer_2->datesent(undef)->store; |
1451 |
$transfer_2->datearrived(undef)->store; |
1452 |
$transfer_1->datecancelled(undef)->store; |
1453 |
|
1454 |
my $prefetched_item = Koha::Items->search( |
1455 |
{ 'me.itemnumber' => $item->itemnumber }, |
1456 |
{ prefetch => ['current_branchtransfers'] } |
1457 |
)->next; |
1458 |
|
1459 |
$transfers = $prefetched_item->get_transfers(); |
1460 |
is( |
1461 |
$transfers->count, 3, |
1462 |
'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all' |
1463 |
); |
1464 |
$result_1 = $transfers->next; |
1465 |
$result_2 = $transfers->next; |
1466 |
$result_3 = $transfers->next; |
1467 |
is( |
1468 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1469 |
'Koha::Item->get_transfers returns the oldest transfer request first' |
1470 |
); |
1471 |
is( |
1472 |
$result_2->branchtransfer_id, $transfer_2->branchtransfer_id, |
1473 |
'Koha::Item->get_transfers returns the newer transfer request second' |
1474 |
); |
1475 |
is( |
1476 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1477 |
'Koha::Item->get_transfers returns the newest transfer request last' |
1478 |
); |
1479 |
|
1480 |
$transfer_2->datesent( \'NOW()' )->store; |
1481 |
$prefetched_item = Koha::Items->search( |
1482 |
{ 'me.itemnumber' => $item->itemnumber }, |
1483 |
{ prefetch => ['current_branchtransfers'] } |
1484 |
)->next; |
1485 |
$transfers = $prefetched_item->get_transfers(); |
1486 |
is( |
1487 |
$transfers->count, 3, |
1488 |
'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all' |
1489 |
); |
1490 |
$result_1 = $transfers->next; |
1491 |
$result_2 = $transfers->next; |
1492 |
$result_3 = $transfers->next; |
1493 |
is( |
1494 |
$result_1->branchtransfer_id, $transfer_2->branchtransfer_id, |
1495 |
'Koha::Item->get_transfers returns the active transfer request first' |
1496 |
); |
1497 |
is( |
1498 |
$result_2->branchtransfer_id, $transfer_1->branchtransfer_id, |
1499 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1500 |
); |
1501 |
is( |
1502 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1503 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1504 |
); |
1505 |
|
1506 |
$transfer_2->datearrived( \'NOW()' )->store; |
1507 |
$prefetched_item = Koha::Items->search( |
1508 |
{ 'me.itemnumber' => $item->itemnumber }, |
1509 |
{ prefetch => ['current_branchtransfers'] } |
1510 |
)->next; |
1511 |
$transfers = $prefetched_item->get_transfers(); |
1512 |
is( |
1513 |
$transfers->count, 2, |
1514 |
'Once a transfer is received, it no longer appears in the list from ->get_transfers()' |
1515 |
); |
1516 |
$result_1 = $transfers->next; |
1517 |
$result_2 = $transfers->next; |
1518 |
is( |
1519 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1520 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1521 |
); |
1522 |
is( |
1523 |
$result_2->branchtransfer_id, $transfer_3->branchtransfer_id, |
1524 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1525 |
); |
1526 |
|
1527 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1528 |
$prefetched_item = Koha::Items->search( |
1529 |
{ 'me.itemnumber' => $item->itemnumber }, |
1530 |
{ prefetch => ['current_branchtransfers'] } |
1531 |
)->next; |
1532 |
$transfers = $prefetched_item->get_transfers(); |
1533 |
is( |
1534 |
$transfers->count, 1, |
1535 |
'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()' |
1536 |
); |
1537 |
$result_1 = $transfers->next; |
1538 |
is( |
1539 |
$result_1->branchtransfer_id, $transfer_3->branchtransfer_id, |
1540 |
'Koha::Item->get_transfers returns the only transfer that remains' |
1541 |
); |
1542 |
}; |
1543 |
|
1297 |
$schema->storage->txn_rollback; |
1544 |
$schema->storage->txn_rollback; |
1298 |
}; |
1545 |
}; |
1299 |
|
1546 |
|
1300 |
- |
|
|