Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 17; |
22 |
use Test::More tests => 20; |
23 |
|
23 |
|
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Exception; |
25 |
use Test::Exception; |
Lines 1382-1392
subtest 'store' => sub {
Link Here
|
1382 |
}; |
1382 |
}; |
1383 |
}; |
1383 |
}; |
1384 |
|
1384 |
|
1385 |
subtest 'get_transfer' => sub { |
1385 |
subtest 'serial_item' => sub { |
1386 |
plan tests => 7; |
1386 |
|
|
|
1387 |
plan tests => 3; |
1388 |
|
1389 |
$schema->storage->txn_begin; |
1390 |
|
1391 |
my $item = $builder->build_sample_item; |
1392 |
my $serial_item = |
1393 |
$builder->build_object( { class => 'Koha::Serial::Items', value => { itemnumber => $item->itemnumber } } ); |
1394 |
is( ref( $item->serial_item ), 'Koha::Serial::Item' ); |
1395 |
is( $item->serial_item->itemnumber, $item->itemnumber ); |
1396 |
|
1397 |
is( ref( $item->serial_item->serial ), 'Koha::Serial', 'Koha::Serial::Item->serial returns a Koha::Serial object' ); |
1398 |
|
1399 |
$schema->storage->txn_rollback; |
1400 |
|
1401 |
}; |
1402 |
|
1403 |
subtest 'item_group_item' => sub { |
1404 |
|
1405 |
plan tests => 2; |
1406 |
|
1407 |
$schema->storage->txn_begin; |
1408 |
|
1409 |
my $biblio = $builder->build_sample_biblio(); |
1410 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
1411 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
1412 |
|
1413 |
my $item_group = Koha::Biblio::ItemGroup->new( { biblio_id => $biblio->id } )->store(); |
1414 |
$item_group->add_item( { item_id => $item_1->itemnumber } ); |
1415 |
|
1416 |
is( |
1417 |
ref( $item_1->item_group_item ), 'Koha::Biblio::ItemGroup::Item', |
1418 |
'->item_group_item should return a Koha::Biblio::ItemGroup::Item object' |
1419 |
); |
1420 |
is( $item_1->item_group_item->item_id, $item_1->itemnumber, '->item_group_item should return the correct item' ); |
1421 |
|
1422 |
$schema->storage->txn_rollback; |
1423 |
|
1424 |
}; |
1425 |
|
1426 |
subtest 'course_item' => sub { |
1427 |
|
1428 |
plan tests => 2; |
1429 |
|
1430 |
$schema->storage->txn_begin; |
1431 |
|
1432 |
my $item = $builder->build_sample_item; |
1433 |
my $course_item = |
1434 |
$builder->build_object( { class => 'Koha::Course::Items', value => { itemnumber => $item->itemnumber } } ); |
1435 |
is( ref( $item->course_item ), 'Koha::Course::Item', '->course_item should return a Koha::Course::Item object' ); |
1436 |
is( $item->course_item->ci_id, $course_item->ci_id, '->course_item should return the correct object' ); |
1437 |
|
1438 |
$schema->storage->txn_rollback; |
1439 |
|
1440 |
}; |
1441 |
|
1442 |
subtest 'get_transfer|transfer' => sub { |
1443 |
plan tests => 9; |
1387 |
|
1444 |
|
1388 |
my $transfer = $new_item_1->get_transfer(); |
1445 |
my $transfer = $new_item_1->get_transfer(); |
1389 |
is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' ); |
1446 |
is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' ); |
|
|
1447 |
is( $new_item_1->transfer, undef ); |
1390 |
|
1448 |
|
1391 |
my $library_to = $builder->build( { source => 'Branch' } ); |
1449 |
my $library_to = $builder->build( { source => 'Branch' } ); |
1392 |
|
1450 |
|
Lines 1408-1413
subtest 'get_transfer' => sub {
Link Here
|
1408 |
|
1466 |
|
1409 |
$transfer = $new_item_1->get_transfer(); |
1467 |
$transfer = $new_item_1->get_transfer(); |
1410 |
is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfer object' ); |
1468 |
is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfer object' ); |
|
|
1469 |
is( ref($new_item_1->transfer), 'Koha::Item::Transfer' ); |
1411 |
|
1470 |
|
1412 |
my $transfer_2 = $builder->build_object( |
1471 |
my $transfer_2 = $builder->build_object( |
1413 |
{ |
1472 |
{ |
Lines 1459-1479
subtest 'get_transfer' => sub {
Link Here
|
1459 |
}; |
1518 |
}; |
1460 |
|
1519 |
|
1461 |
subtest 'holds' => sub { |
1520 |
subtest 'holds' => sub { |
1462 |
plan tests => 5; |
1521 |
plan tests => 7; |
1463 |
|
1522 |
|
1464 |
my $biblio = $builder->build_sample_biblio(); |
1523 |
my $biblio = $builder->build_sample_biblio(); |
1465 |
my $item = $builder->build_sample_item({ |
1524 |
my $item = $builder->build_sample_item( |
1466 |
biblionumber => $biblio->biblionumber, |
1525 |
{ |
1467 |
}); |
1526 |
biblionumber => $biblio->biblionumber, |
1468 |
is($item->holds->count, 0, "Nothing returned if no holds"); |
1527 |
} |
1469 |
my $hold1 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'T' }}); |
1528 |
); |
1470 |
my $hold2 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
1529 |
is( $item->holds->count, 0, "Nothing returned if no holds" ); |
1471 |
my $hold3 = $builder->build({ source => 'Reserve', value => { itemnumber=>$item->itemnumber, found => 'W' }}); |
1530 |
is( $item->first_hold, undef, 'No hold yet' ); |
1472 |
|
1531 |
my $yesterday = dt_from_string->subtract( days => 1 )->ymd; |
1473 |
is($item->holds()->count,3,"Three holds found"); |
1532 |
my $hold1 = $builder->build( |
1474 |
is($item->holds({found => 'W'})->count,2,"Two waiting holds found"); |
1533 |
{ |
1475 |
is_deeply($item->holds({found => 'T'})->next->unblessed,$hold1,"Found transit holds matches the hold"); |
1534 |
source => 'Reserve', |
1476 |
is($item->holds({found => undef})->count, 0,"Nothing returned if no matching holds"); |
1535 |
value => { |
|
|
1536 |
itemnumber => $item->itemnumber, found => 'T', reservedate => $yesterday, suspend => 0, priority => 2 |
1537 |
} |
1538 |
} |
1539 |
); |
1540 |
my $hold2 = $builder->build( |
1541 |
{ |
1542 |
source => 'Reserve', |
1543 |
value => { |
1544 |
itemnumber => $item->itemnumber, found => 'W', reservedate => $yesterday, suspend => 0, priority => 1 |
1545 |
} |
1546 |
} |
1547 |
); |
1548 |
my $hold3 = $builder->build( |
1549 |
{ |
1550 |
source => 'Reserve', |
1551 |
value => { |
1552 |
itemnumber => $item->itemnumber, found => 'W', reservedate => $yesterday, suspend => 0, priority => 3 |
1553 |
} |
1554 |
} |
1555 |
); |
1556 |
|
1557 |
is( $item->holds()->count, 3, "Three holds found" ); |
1558 |
is( $item->holds( { found => 'W' } )->count, 2, "Two waiting holds found" ); |
1559 |
is_deeply( $item->holds( { found => 'T' } )->next->unblessed, $hold1, "Found transit holds matches the hold" ); |
1560 |
is( $item->holds( { found => undef } )->count, 0, "Nothing returned if no matching holds" ); |
1561 |
is( $item->first_hold->reserve_id, $hold2->{reserve_id}, '->first_hold returns the correct hold' ); |
1477 |
}; |
1562 |
}; |
1478 |
|
1563 |
|
1479 |
subtest 'biblio' => sub { |
1564 |
subtest 'biblio' => sub { |