View | Details | Raw Unified | Return to bug 42044
Collapse All | Expand All

(-)a/t/db_dependent/AuthoritiesMarc.t (-1 / +94 lines)
Lines 6-16 Link Here
6
use Modern::Perl;
6
use Modern::Perl;
7
7
8
use Test::NoWarnings;
8
use Test::NoWarnings;
9
use Test::More tests => 14;
9
use Test::More tests => 15;
10
use Test::MockModule;
10
use Test::MockModule;
11
use Test::Warn;
11
use Test::Warn;
12
use MARC::Field;
12
use MARC::Field;
13
use MARC::Record;
13
use MARC::Record;
14
use POSIX qw( strftime );
14
15
15
use t::lib::Mocks;
16
use t::lib::Mocks;
16
use t::lib::TestBuilder;
17
use t::lib::TestBuilder;
Lines 398-400 subtest 'DelAuthority() tests' => sub { Link Here
398
399
399
    $schema->storage->txn_rollback;
400
    $schema->storage->txn_rollback;
400
};
401
};
402
403
subtest 'record status after ModAuthority' => sub {
404
    plan tests => 5;
405
406
    $schema->storage->txn_begin;
407
408
    t::lib::Mocks::mock_preference( "marcflavour",            'MARC21' );
409
    t::lib::Mocks::mock_preference( "AutoUpdateRecordStatus", 1 );
410
    t::lib::Mocks::mock_preference( "AuthoritiesLog",         0 );
411
    my $c4_context = Test::MockModule->new('C4::Context');
412
    $c4_context->mock( 'userenv', sub { return { number => 123, firstname => 'John', surname => 'Doe' }; } );
413
    my $mocked_authorities_marc = Test::MockModule->new('C4::AuthoritiesMarc');
414
    $mocked_authorities_marc->unmock('merge');
415
416
    my $authtypecode = 'GEOGR_NAME';
417
418
    my $marc_record_init = MARC::Record->new;
419
    my $leader           = $marc_record_init->leader;
420
    substr( $leader, 5, 1, 'n' );
421
    $marc_record_init->leader($leader);
422
    $marc_record_init->insert_fields_ordered(
423
        MARC::Field->new( '008', POSIX::strftime( "%y%m%d", localtime ) . ( ' ' x 34 ) ) );
424
    $marc_record_init->insert_fields_ordered(
425
        MARC::Field->new(
426
            '040', ' ', ' ',
427
            a => 'ABC',
428
            c => 'ABC'
429
        )
430
    );
431
    $marc_record_init->insert_fields_ordered(
432
        MARC::Field->new(
433
            '151', ' ', ' ',
434
            a => 'Cape Horn'
435
        )
436
    );
437
438
    my $authid      = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode );
439
    my $marc_record = $marc_record_init->clone;
440
441
    # AuthoritiesLog == 0 --> LDR/5 should be set to 'c'
442
    C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode );
443
444
    my $auth = Koha::Authorities->find($authid);
445
    $marc_record = $auth->record;
446
    $leader      = $marc_record->leader;
447
    is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' );
448
449
    # AuthoritiesLog == 1 --> LDR/5 should not be changed
450
    t::lib::Mocks::mock_preference( "AuthoritiesLog", 1 );
451
    $authid      = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode );
452
    $marc_record = $marc_record_init->clone;
453
454
    C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode );
455
456
    $auth        = Koha::Authorities->find($authid);
457
    $marc_record = $auth->record;
458
    $leader      = $marc_record->leader;
459
    is( substr( $leader, 5, 1 ), 'n', 'Record status unchanged' );
460
461
    # 040 $d present --> LDR/5 should be set to 'c'
462
    $marc_record->field('040')->add_subfields( d => 'ABC' );
463
    C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode );
464
465
    $auth        = Koha::Authorities->find($authid);
466
    $marc_record = $auth->record;
467
    $leader      = $marc_record->leader;
468
    is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' );
469
470
    # date entered on file != today --> LDR/5 should be set to 'c'
471
    $authid      = C4::AuthoritiesMarc::AddAuthority( $marc_record_init, undef, $authtypecode );
472
    $marc_record = $marc_record_init->clone;
473
    $marc_record->field('008')->update( '010101' . ( ' ' x 34 ) );
474
    C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode );
475
476
    $auth        = Koha::Authorities->find($authid);
477
    $marc_record = $auth->record;
478
    $leader      = $marc_record->leader;
479
    is( substr( $leader, 5, 1 ), 'c', 'Record status changed to "c"' );
480
481
    # LDR/5 changed in $marc_record before ModAuthority --> no auto update
482
    substr( $leader, 5, 1, 'p' );
483
    $marc_record->leader($leader);
484
    $marc_record->field('040')->add_subfields( d => 'ABC' );
485
    C4::AuthoritiesMarc::ModAuthority( $authid, $marc_record, $authtypecode );
486
487
    $auth        = Koha::Authorities->find($authid);
488
    $marc_record = $auth->record;
489
    $leader      = $marc_record->leader;
490
    is( substr( $leader, 5, 1 ), 'p', 'Record status still "p"' );
491
492
    $schema->storage->txn_rollback;
493
};
(-)a/t/db_dependent/Biblio.t (-2 / +80 lines)
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
- 

Return to bug 42044