|
Lines 17-28
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 26; |
20 |
use Test::More tests => 27; |
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
use List::MoreUtils qw( uniq ); |
24 |
use List::MoreUtils qw( uniq ); |
| 25 |
use MARC::Record; |
25 |
use MARC::Record; |
|
|
26 |
use POSIX qw( strftime ); |
| 26 |
|
27 |
|
| 27 |
use t::lib::Mocks; |
28 |
use t::lib::Mocks; |
| 28 |
use t::lib::TestBuilder; |
29 |
use t::lib::TestBuilder; |
|
Lines 1376-1381
subtest 'AddBiblio/ModBiblio calling ModBiblioMarc for field 005' => sub {
Link Here
|
| 1376 |
ok( $field && $field->data, 'Record contains field 005 after ModBiblio' ); |
1377 |
ok( $field && $field->data, 'Record contains field 005 after ModBiblio' ); |
| 1377 |
}; |
1378 |
}; |
| 1378 |
|
1379 |
|
|
|
1380 |
subtest 'record status after ModBiblio' => sub { |
| 1381 |
plan tests => 5; |
| 1382 |
|
| 1383 |
t::lib::Mocks::mock_preference( "marcflavour", 'MARC21' ); |
| 1384 |
t::lib::Mocks::mock_preference( "AutoUpdateRecordStatus", 1 ); |
| 1385 |
t::lib::Mocks::mock_preference( "CataloguingLog", 0 ); |
| 1386 |
my $c4_context = Test::MockModule->new('C4::Context'); |
| 1387 |
$c4_context->mock( 'userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe' }; } ); |
| 1388 |
|
| 1389 |
my $marc_record_init = MARC::Record->new; |
| 1390 |
my $leader = $marc_record_init->leader; |
| 1391 |
substr( $leader, 5, 1, 'n' ); |
| 1392 |
$marc_record_init->leader($leader); |
| 1393 |
$marc_record_init->insert_fields_ordered( |
| 1394 |
MARC::Field->new( '008', POSIX::strftime( "%y%m%d", localtime ) . ( ' ' x 34 ) ) ); |
| 1395 |
$marc_record_init->insert_fields_ordered( |
| 1396 |
MARC::Field->new( |
| 1397 |
'040', ' ', ' ', |
| 1398 |
a => 'ABC', |
| 1399 |
c => 'ABC' |
| 1400 |
) |
| 1401 |
); |
| 1402 |
|
| 1403 |
my ($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); |
| 1404 |
my $marc_record = $marc_record_init->clone; |
| 1405 |
|
| 1406 |
# CataloguingLog == 0 --> LDR/5 should be set to 'c' |
| 1407 |
C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); |
| 1408 |
|
| 1409 |
my $biblio = Koha::Biblios->find($biblionumber); |
| 1410 |
$marc_record = $biblio->metadata->record; |
| 1411 |
$leader = $marc_record->leader; |
| 1412 |
is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); |
| 1413 |
|
| 1414 |
# CataloguingLog == 1 --> LDR/5 should not be changed |
| 1415 |
t::lib::Mocks::mock_preference( "CataloguingLog", 1 ); |
| 1416 |
($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); |
| 1417 |
$marc_record = $marc_record_init->clone; |
| 1418 |
|
| 1419 |
C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); |
| 1420 |
|
| 1421 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1422 |
$marc_record = $biblio->metadata->record; |
| 1423 |
$leader = $marc_record->leader; |
| 1424 |
is( substr( $leader, 5, 1 ), 'n', 'Record status unchanged' ); |
| 1425 |
|
| 1426 |
# 040 $d present --> LDR/5 should be set to 'c' |
| 1427 |
$marc_record->field('040')->add_subfields( d => 'ABC' ); |
| 1428 |
C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); |
| 1429 |
|
| 1430 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1431 |
$marc_record = $biblio->metadata->record; |
| 1432 |
$leader = $marc_record->leader; |
| 1433 |
is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); |
| 1434 |
|
| 1435 |
# date entered on file != today --> LDR/5 should be set to 'c' |
| 1436 |
($biblionumber) = C4::Biblio::AddBiblio( $marc_record_init, '' ); |
| 1437 |
$marc_record = $marc_record_init->clone; |
| 1438 |
$marc_record->field('008')->update( '010101' . ( ' ' x 34 ) ); |
| 1439 |
C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); |
| 1440 |
|
| 1441 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1442 |
$marc_record = $biblio->metadata->record; |
| 1443 |
$leader = $marc_record->leader; |
| 1444 |
is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' ); |
| 1445 |
|
| 1446 |
# LDR/5 explicitly changed in $marc_record before ModBiblio, added 040 $d --> no auto update |
| 1447 |
substr( $leader, 5, 1, 'p' ); |
| 1448 |
$marc_record->leader($leader); |
| 1449 |
$marc_record->field('040')->add_subfields( d => 'ABC' ); |
| 1450 |
C4::Biblio::ModBiblio( $marc_record, $biblionumber, '' ); |
| 1451 |
|
| 1452 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1453 |
$marc_record = $biblio->metadata->record; |
| 1454 |
$leader = $marc_record->leader; |
| 1455 |
is( substr( $leader, 5, 1 ), 'p', 'Record status still "p"' ); |
| 1456 |
}; |
| 1457 |
|
| 1379 |
# Cleanup |
1458 |
# Cleanup |
| 1380 |
Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-"); |
1459 |
Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-"); |
| 1381 |
$schema->storage->txn_rollback; |
1460 |
$schema->storage->txn_rollback; |
| 1382 |
- |
|
|