|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 42; |
21 |
use Test::More tests => 43; |
| 22 |
use Test::Exception; |
22 |
use Test::Exception; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
|
24 |
|
|
Lines 1381-1386
subtest 'link_marc_host' => sub {
Link Here
|
| 1381 |
$schema->storage->txn_rollback; |
1381 |
$schema->storage->txn_rollback; |
| 1382 |
}; |
1382 |
}; |
| 1383 |
|
1383 |
|
|
|
1384 |
subtest 'unlink_marc_host' => sub { |
| 1385 |
plan tests => 9; |
| 1386 |
$schema->storage->txn_begin; |
| 1387 |
my $host = $builder->build_sample_biblio(); |
| 1388 |
my $host_item = $builder->build_sample_item( { biblionumber => $host->biblionumber } ); |
| 1389 |
my $wronghost = $builder->build_sample_biblio(); |
| 1390 |
my $child = $builder->build_sample_biblio(); |
| 1391 |
my $child_record = $child->metadata->record; |
| 1392 |
|
| 1393 |
# Prepare the environment |
| 1394 |
t::lib::Mocks::mock_preference( 'EasyAnalyticalRecords', 1 ); |
| 1395 |
my $link_field = $host->generate_marc_host_field( { item => $host_item } ); |
| 1396 |
$child->link_marc_host( { field => $link_field } ); |
| 1397 |
$child->discard_changes; |
| 1398 |
$child_record = $child->metadata->record; |
| 1399 |
is( |
| 1400 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1401 |
'773 field is set before calling unlink_marc_host({ host => $biblionumber })' |
| 1402 |
); |
| 1403 |
|
| 1404 |
# Test |
| 1405 |
$child->unlink_marc_host( { host => $host->biblionumber } ); |
| 1406 |
$child->discard_changes; |
| 1407 |
$child_record = $child->metadata->record; |
| 1408 |
is( |
| 1409 |
$child_record->field('773'), undef, |
| 1410 |
'Can remove a link to a bundle using a biblionumber to identify the bundle' |
| 1411 |
); |
| 1412 |
|
| 1413 |
# Prepare the environment |
| 1414 |
$child->link_marc_host( { field => $link_field } ); |
| 1415 |
$child->discard_changes; |
| 1416 |
$child_record = $child->metadata->record; |
| 1417 |
is( |
| 1418 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1419 |
'773 field is set before calling unlink_marc_host({ host => $biblionumber })' |
| 1420 |
); |
| 1421 |
|
| 1422 |
# Test |
| 1423 |
$child->unlink_marc_host( { host => $host } ); |
| 1424 |
$child->discard_changes; |
| 1425 |
$child_record = $child->metadata->record; |
| 1426 |
is( |
| 1427 |
$child_record->field('773'), undef, |
| 1428 |
'Can remove a link to a bundle using a record to identify the bundle' |
| 1429 |
); |
| 1430 |
|
| 1431 |
# Prepare the environment |
| 1432 |
$child->link_marc_host( { field => $link_field } ); |
| 1433 |
$child->discard_changes; |
| 1434 |
$child_record = $child->metadata->record; |
| 1435 |
is( |
| 1436 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1437 |
'773 field is set before calling unlink_marc_host({ host => $biblionumber })' |
| 1438 |
); |
| 1439 |
|
| 1440 |
# Test |
| 1441 |
$child->unlink_marc_host( { host => $wronghost } ); |
| 1442 |
$child->discard_changes; |
| 1443 |
$child_record = $child->metadata->record; |
| 1444 |
is( |
| 1445 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1446 |
'Removing a link from another bundle does not remove the field' |
| 1447 |
); |
| 1448 |
|
| 1449 |
# Prepare the environment |
| 1450 |
$child->link_marc_host( { field => $link_field } ); |
| 1451 |
$child->discard_changes; |
| 1452 |
$child_record = $child->metadata->record; |
| 1453 |
is( |
| 1454 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1455 |
'773 field is set before calling unlink_marc_host({ host => $biblionumber })' |
| 1456 |
); |
| 1457 |
|
| 1458 |
# Test |
| 1459 |
$child->unlink_marc_host( { host => $wronghost } ); |
| 1460 |
$child->discard_changes; |
| 1461 |
$child_record = $child->metadata->record; |
| 1462 |
is( |
| 1463 |
ref( $child_record->field('773') ), 'MARC::Field', |
| 1464 |
'Removing a link from another bundle does not remove the field' |
| 1465 |
); |
| 1466 |
|
| 1467 |
# Prepare the environment |
| 1468 |
$child->link_marc_host( { field => $link_field } ); |
| 1469 |
$child->link_marc_host( { field => $link_field } ); |
| 1470 |
$child->discard_changes; |
| 1471 |
$child_record = $child->metadata->record; |
| 1472 |
my @fields = $child_record->field('773'); |
| 1473 |
my $fields_before = scalar @fields; |
| 1474 |
|
| 1475 |
# Test |
| 1476 |
$child->link_marc_host( { field => $link_field } ); |
| 1477 |
$child->unlink_marc_host( { host => $host } ); |
| 1478 |
$child->discard_changes; |
| 1479 |
$child_record = $child->metadata->record; |
| 1480 |
@fields = $child_record->field('773'); |
| 1481 |
my $fields_after = scalar @fields; |
| 1482 |
is( |
| 1483 |
$fields_after, $fields_before - 1, |
| 1484 |
'Removing a link only removes one link' |
| 1485 |
); |
| 1486 |
|
| 1487 |
$schema->storage->txn_rollback; |
| 1488 |
}; |
| 1489 |
|
| 1384 |
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub { |
1490 |
subtest '->orders, ->uncancelled_orders and ->acq_status tests' => sub { |
| 1385 |
|
1491 |
|
| 1386 |
plan tests => 9; |
1492 |
plan tests => 9; |
| 1387 |
- |
|
|