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 => 36; |
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 1309-1316
subtest 'Tests for itemtype|item_type' => sub {
Link Here
|
1309 |
$schema->storage->txn_rollback; |
1309 |
$schema->storage->txn_rollback; |
1310 |
}; |
1310 |
}; |
1311 |
|
1311 |
|
|
|
1312 |
subtest 'get_transfer' => sub { |
1313 |
plan tests => 8; |
1314 |
$schema->storage->txn_begin; |
1315 |
|
1316 |
my $item = $builder->build_sample_item(); |
1317 |
|
1318 |
my $transfer = $item->get_transfer(); |
1319 |
is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item has no queued transfers' ); |
1320 |
|
1321 |
my $library_to = $builder->build( { source => 'Branch' } ); |
1322 |
|
1323 |
my $transfer_1 = $builder->build_object( |
1324 |
{ |
1325 |
class => 'Koha::Item::Transfers', |
1326 |
value => { |
1327 |
itemnumber => $item->itemnumber, |
1328 |
frombranch => $item->holdingbranch, |
1329 |
tobranch => $library_to->{branchcode}, |
1330 |
reason => 'Manual', |
1331 |
datesent => undef, |
1332 |
datearrived => undef, |
1333 |
datecancelled => undef, |
1334 |
daterequested => \'NOW()' |
1335 |
} |
1336 |
} |
1337 |
); |
1338 |
|
1339 |
$transfer = $item->get_transfer(); |
1340 |
is( |
1341 |
ref($transfer), 'Koha::Item::Transfer', |
1342 |
'Koha::Item->get_transfer should return a Koha::Item::Transfer object' |
1343 |
); |
1344 |
|
1345 |
my $transfer_2 = $builder->build_object( |
1346 |
{ |
1347 |
class => 'Koha::Item::Transfers', |
1348 |
value => { |
1349 |
itemnumber => $item->itemnumber, |
1350 |
frombranch => $item->holdingbranch, |
1351 |
tobranch => $library_to->{branchcode}, |
1352 |
reason => 'Manual', |
1353 |
datesent => undef, |
1354 |
datearrived => undef, |
1355 |
datecancelled => undef, |
1356 |
daterequested => \'NOW()' |
1357 |
} |
1358 |
} |
1359 |
); |
1360 |
|
1361 |
$transfer = $item->get_transfer(); |
1362 |
is( |
1363 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1364 |
'Koha::Item->get_transfer returns the oldest transfer request' |
1365 |
); |
1366 |
|
1367 |
$transfer_2->datesent( \'NOW()' )->store; |
1368 |
$transfer = $item->get_transfer(); |
1369 |
is( |
1370 |
$transfer->branchtransfer_id, $transfer_2->branchtransfer_id, |
1371 |
'Koha::Item->get_transfer returns the in_transit transfer' |
1372 |
); |
1373 |
|
1374 |
my $transfer_3 = $builder->build_object( |
1375 |
{ |
1376 |
class => 'Koha::Item::Transfers', |
1377 |
value => { |
1378 |
itemnumber => $item->itemnumber, |
1379 |
frombranch => $item->holdingbranch, |
1380 |
tobranch => $library_to->{branchcode}, |
1381 |
reason => 'Manual', |
1382 |
datesent => undef, |
1383 |
datearrived => undef, |
1384 |
datecancelled => undef, |
1385 |
daterequested => \'NOW()' |
1386 |
} |
1387 |
} |
1388 |
); |
1389 |
|
1390 |
$transfer_2->datearrived( \'NOW()' )->store; |
1391 |
$transfer = $item->get_transfer(); |
1392 |
is( |
1393 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1394 |
'Koha::Item->get_transfer returns the next queued transfer' |
1395 |
); |
1396 |
is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' ); |
1397 |
|
1398 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1399 |
$transfer = $item->get_transfer(); |
1400 |
is( |
1401 |
$transfer->branchtransfer_id, $transfer_3->branchtransfer_id, |
1402 |
'Koha::Item->get_transfer ignores cancelled transfers' |
1403 |
); |
1404 |
|
1405 |
subtest "Ensure prefetches don't affect which transfer if returned" => sub { |
1406 |
plan tests => 5; |
1407 |
|
1408 |
# Reset test data |
1409 |
$transfer_1->datecancelled(undef)->store; |
1410 |
$transfer_2->set( { datesent => undef, datearrived => undef } )->store; |
1411 |
|
1412 |
my $prefetched_item = Koha::Items->search( |
1413 |
{ 'me.itemnumber' => $item->itemnumber }, |
1414 |
{ prefetch => ['current_branchtransfers'] } |
1415 |
)->next; |
1416 |
|
1417 |
$transfer = $prefetched_item->get_transfer(); |
1418 |
is( |
1419 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1420 |
'Koha::Item->get_transfer returns the oldest transfer request' |
1421 |
); |
1422 |
|
1423 |
$transfer_2->datesent( \'NOW()' )->store; |
1424 |
$prefetched_item = Koha::Items->search( |
1425 |
{ 'me.itemnumber' => $item->itemnumber }, |
1426 |
{ prefetch => ['current_branchtransfers'] } |
1427 |
)->next; |
1428 |
|
1429 |
$transfer = $prefetched_item->get_transfer(); |
1430 |
is( |
1431 |
$transfer->branchtransfer_id, $transfer_2->branchtransfer_id, |
1432 |
'Koha::Item->get_transfer returns the in_transit transfer' |
1433 |
); |
1434 |
|
1435 |
$transfer_2->datearrived( \'NOW()' )->store; |
1436 |
$prefetched_item = Koha::Items->search( |
1437 |
{ 'me.itemnumber' => $item->itemnumber }, |
1438 |
{ prefetch => ['current_branchtransfers'] } |
1439 |
)->next; |
1440 |
$transfer = $prefetched_item->get_transfer(); |
1441 |
is( |
1442 |
$transfer->branchtransfer_id, $transfer_1->branchtransfer_id, |
1443 |
'Koha::Item->get_transfer returns the next queued transfer' |
1444 |
); |
1445 |
is( $transfer->itemnumber, $item->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' ); |
1446 |
|
1447 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1448 |
$prefetched_item = Koha::Items->search( |
1449 |
{ 'me.itemnumber' => $item->itemnumber }, |
1450 |
{ prefetch => ['current_branchtransfers'] } |
1451 |
)->next; |
1452 |
$transfer = $prefetched_item->get_transfer(); |
1453 |
is( |
1454 |
$transfer->branchtransfer_id, $transfer_3->branchtransfer_id, |
1455 |
'Koha::Item->get_transfer ignores cancelled transfers' |
1456 |
); |
1457 |
}; |
1458 |
$schema->storage->txn_rollback; |
1459 |
}; |
1460 |
|
1312 |
subtest 'get_transfers' => sub { |
1461 |
subtest 'get_transfers' => sub { |
1313 |
plan tests => 16; |
1462 |
plan tests => 17; |
1314 |
$schema->storage->txn_begin; |
1463 |
$schema->storage->txn_begin; |
1315 |
|
1464 |
|
1316 |
my $item = $builder->build_sample_item(); |
1465 |
my $item = $builder->build_sample_item(); |
Lines 1405-1410
subtest 'get_transfers' => sub {
Link Here
|
1405 |
$result_1 = $transfers->next; |
1554 |
$result_1 = $transfers->next; |
1406 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1555 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
1407 |
|
1556 |
|
|
|
1557 |
subtest "Ensure prefetches don't affect the return order" => sub { |
1558 |
plan tests => 13; |
1559 |
|
1560 |
# Reset test data |
1561 |
$transfer_2->datesent(undef)->store; |
1562 |
$transfer_2->datearrived(undef)->store; |
1563 |
$transfer_1->datecancelled(undef)->store; |
1564 |
|
1565 |
my $prefetched_item = Koha::Items->search( |
1566 |
{ 'me.itemnumber' => $item->itemnumber }, |
1567 |
{ prefetch => ['current_branchtransfers'] } |
1568 |
)->next; |
1569 |
|
1570 |
$transfers = $prefetched_item->get_transfers(); |
1571 |
is( |
1572 |
$transfers->count, 3, |
1573 |
'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all' |
1574 |
); |
1575 |
$result_1 = $transfers->next; |
1576 |
$result_2 = $transfers->next; |
1577 |
$result_3 = $transfers->next; |
1578 |
is( |
1579 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1580 |
'Koha::Item->get_transfers returns the oldest transfer request first' |
1581 |
); |
1582 |
is( |
1583 |
$result_2->branchtransfer_id, $transfer_2->branchtransfer_id, |
1584 |
'Koha::Item->get_transfers returns the newer transfer request second' |
1585 |
); |
1586 |
is( |
1587 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1588 |
'Koha::Item->get_transfers returns the newest transfer request last' |
1589 |
); |
1590 |
|
1591 |
$transfer_2->datesent( \'NOW()' )->store; |
1592 |
$prefetched_item = Koha::Items->search( |
1593 |
{ 'me.itemnumber' => $item->itemnumber }, |
1594 |
{ prefetch => ['current_branchtransfers'] } |
1595 |
)->next; |
1596 |
$transfers = $prefetched_item->get_transfers(); |
1597 |
is( |
1598 |
$transfers->count, 3, |
1599 |
'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all' |
1600 |
); |
1601 |
$result_1 = $transfers->next; |
1602 |
$result_2 = $transfers->next; |
1603 |
$result_3 = $transfers->next; |
1604 |
is( |
1605 |
$result_1->branchtransfer_id, $transfer_2->branchtransfer_id, |
1606 |
'Koha::Item->get_transfers returns the active transfer request first' |
1607 |
); |
1608 |
is( |
1609 |
$result_2->branchtransfer_id, $transfer_1->branchtransfer_id, |
1610 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1611 |
); |
1612 |
is( |
1613 |
$result_3->branchtransfer_id, $transfer_3->branchtransfer_id, |
1614 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1615 |
); |
1616 |
|
1617 |
$transfer_2->datearrived( \'NOW()' )->store; |
1618 |
$prefetched_item = Koha::Items->search( |
1619 |
{ 'me.itemnumber' => $item->itemnumber }, |
1620 |
{ prefetch => ['current_branchtransfers'] } |
1621 |
)->next; |
1622 |
$transfers = $prefetched_item->get_transfers(); |
1623 |
is( |
1624 |
$transfers->count, 2, |
1625 |
'Once a transfer is received, it no longer appears in the list from ->get_transfers()' |
1626 |
); |
1627 |
$result_1 = $transfers->next; |
1628 |
$result_2 = $transfers->next; |
1629 |
is( |
1630 |
$result_1->branchtransfer_id, $transfer_1->branchtransfer_id, |
1631 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1632 |
); |
1633 |
is( |
1634 |
$result_2->branchtransfer_id, $transfer_3->branchtransfer_id, |
1635 |
'Koha::Item->get_transfers returns the other transfers oldest to newest' |
1636 |
); |
1637 |
|
1638 |
$transfer_1->datecancelled( \'NOW()' )->store; |
1639 |
$prefetched_item = Koha::Items->search( |
1640 |
{ 'me.itemnumber' => $item->itemnumber }, |
1641 |
{ prefetch => ['current_branchtransfers'] } |
1642 |
)->next; |
1643 |
$transfers = $prefetched_item->get_transfers(); |
1644 |
is( |
1645 |
$transfers->count, 1, |
1646 |
'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()' |
1647 |
); |
1648 |
$result_1 = $transfers->next; |
1649 |
is( |
1650 |
$result_1->branchtransfer_id, $transfer_3->branchtransfer_id, |
1651 |
'Koha::Item->get_transfers returns the only transfer that remains' |
1652 |
); |
1653 |
}; |
1654 |
|
1408 |
$schema->storage->txn_rollback; |
1655 |
$schema->storage->txn_rollback; |
1409 |
}; |
1656 |
}; |
1410 |
|
1657 |
|
1411 |
- |
|
|