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

(-)a/t/db_dependent/Authority/Merge.t (-3 / +88 lines)
Lines 4-10 Link Here
4
4
5
use Modern::Perl;
5
use Modern::Perl;
6
6
7
use Test::More tests => 12;
7
use Test::More tests => 13;
8
8
9
use Getopt::Long;
9
use Getopt::Long;
10
use MARC::Record;
10
use MARC::Record;
Lines 147-153 subtest 'Test merge A1 to modified A1, test strict mode' => sub { Link Here
147
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'b' => 'Should be cleared too', '9' => $authid1 ));
147
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'b' => 'Should be cleared too', '9' => $authid1 ));
148
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'c' => 'This is a duplicate to be removed in strict mode', '9' => $authid1 ));
148
    $MARC1->append_fields( MARC::Field->new( '609', '', '', 'a' => 'Bruce Lee', 'c' => 'This is a duplicate to be removed in strict mode', '9' => $authid1 ));
149
    my $MARC2 = MARC::Record->new;
149
    my $MARC2 = MARC::Record->new;
150
    $MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'Batman', '9' => $authid1 ));
150
    $MARC2->append_fields( MARC::Field->new( '109', '', '', 'a' => 'BATMAN', '9' => $authid1 ));
151
    $MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' ));
151
    $MARC2->append_fields( MARC::Field->new( '245', '', '', 'a' => 'All the way to heaven' ));
152
    my ( $biblionumber1 ) = AddBiblio( $MARC1, '');
152
    my ( $biblionumber1 ) = AddBiblio( $MARC1, '');
153
    my ( $biblionumber2 ) = AddBiblio( $MARC2, '');
153
    my ( $biblionumber2 ) = AddBiblio( $MARC2, '');
Lines 572-577 subtest "Test bibs not auto linked when merging" => sub { Link Here
572
572
573
};
573
};
574
574
575
576
subtest 'ModBiblio calls from merge' => sub {
577
578
    plan tests => 4;
579
580
    $schema->storage->txn_begin;
581
582
    t::lib::Mocks::mock_preference( 'marcflavour',                   'MARC21' );
583
    t::lib::Mocks::mock_preference( 'AuthorityControlledIndicators', '' );
584
    t::lib::Mocks::mock_preference( 'IncludeSeeFromInSearches',      '1' );
585
586
    my $auth_record = MARC::Record->new();
587
    $auth_record->insert_fields_ordered( MARC::Field->new( '109', '1', ' ', a => 'Brown,', 'c' => 'Father' ) );
588
    my $authid = AddAuthority( $auth_record, undef, $authtype1, { skip_record_index => 1 } );
589
590
    my $auth_record_modified = $auth_record->clone;
591
    $auth_record_modified->field('109')->update( c => 'Father (Fictitious character)' );
592
593
    my $biblio_record = MARC::Record->new();
594
    $biblio_record->insert_fields_ordered(
595
        MARC::Field->new( '609', '1', '1', a => 'Brown,', 'c' => 'Father', 9 => $authid ) );
596
    my $biblionumber = AddBiblio( $biblio_record, '', { skip_record_index => 1 } );
597
598
    my $biblio_module = Test::MockModule->new('C4::AuthoritiesMarc');
599
    $biblio_module->mock(
600
        'ModBiblio',
601
        sub { warn 'ModBiblio called'; }
602
    );
603
604
    warnings_are {
605
        merge(
606
            {
607
                mergefrom     => $authid, MARCfrom => $auth_record, mergeto => $authid, MARCto => $auth_record_modified,
608
                biblionumbers => [$biblionumber],
609
            }
610
        );
611
    }
612
    ["ModBiblio called"], "real modification of bibliographic record, ModBiblio called";
613
614
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
615
    my $mock_index = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Indexer');
616
    $mock_index->mock( 'index_records', sub { warn 'index_records called'; } );
617
618
    warnings_are {
619
        merge(
620
            {
621
                mergefrom     => $authid, MARCfrom => $auth_record, mergeto => $authid, MARCto => $auth_record,
622
                biblionumbers => [$biblionumber],
623
            }
624
        );
625
    }
626
    ["index_records called"], "no real modification of bibliographic record, index_records called";
627
628
    t::lib::Mocks::mock_preference( 'IncludeSeeFromInSearches',     '0' );
629
    t::lib::Mocks::mock_preference( 'IncludeSeeAlsoFromInSearches', '0' );
630
    warnings_are {
631
        merge(
632
            {
633
                mergefrom     => $authid, MARCfrom => $auth_record, mergeto => $authid, MARCto => $auth_record,
634
                biblionumbers => [$biblionumber],
635
            }
636
        );
637
    }
638
    [], "no real modification of bibliographic record, index_records not called";
639
640
    my $auth_record2 = MARC::Record->new();
641
    $auth_record2->insert_fields_ordered( MARC::Field->new( '109', '1', ' ', a => 'Chesterton, G.K.' ) );
642
    my $authid2 = AddAuthority( $auth_record2, undef, $authtype1, { skip_record_index => 1 } );
643
644
    my $biblio_record2 = MARC::Record->new();
645
    $biblio_record2->insert_fields_ordered(
646
        MARC::Field->new( '109', '1', ' ', a => 'Chesterton, G.K.', 9 => $authid2 ) );
647
    my $biblionumber2 = AddBiblio( $biblio_record2, '', { skip_record_index => 1 } );
648
649
    my $num_biblio_edited = merge(
650
        {
651
            mergefrom     => $authid, MARCfrom => $auth_record, mergeto => $authid2, MARCto => $auth_record2,
652
            biblionumbers => [ $biblionumber, $biblionumber2 ],
653
        }
654
    );
655
    is( $num_biblio_edited, 1, 'Only one bibliographic record updated while merging two authorities' );
656
657
    $schema->storage->txn_rollback;
658
659
};
660
575
sub set_mocks {
661
sub set_mocks {
576
    # After we removed the Zebra code from merge, we only need to mock
662
    # After we removed the Zebra code from merge, we only need to mock
577
    # get_usage_count and linked_biblionumbers here.
663
    # get_usage_count and linked_biblionumbers here.
578
- 

Return to bug 34739