From f6befafaebb8e75a5809b361a6de5cea7a919aa8 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 23 Feb 2017 12:46:52 +0100 Subject: [PATCH] Bug 9988: Add a subtest for specific postponed merge issues Content-Type: text/plain; charset=utf-8 This subtest shows that we need a few little tweaks to make merge work in some specific postponed merge situations. Test plan: [1] Run t/db_dependent/Authorities/Merge.t. The last subtest should show three fails to be fixed in the next patch. Signed-off-by: Marcel de Rooy --- t/db_dependent/Authorities/Merge.t | 41 +++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Authorities/Merge.t b/t/db_dependent/Authorities/Merge.t index d4c9cfe..5e1f834 100755 --- a/t/db_dependent/Authorities/Merge.t +++ b/t/db_dependent/Authorities/Merge.t @@ -4,7 +4,7 @@ use Modern::Perl; -use Test::More tests => 6; +use Test::More tests => 7; use Getopt::Long; use MARC::Record; @@ -286,6 +286,45 @@ subtest 'Merging authorities should handle deletes (BZ 18070)' => sub { is( $marc1->field('609'), undef, 'Merge removed the 609 again even after deleting the authority record' ); }; +subtest "Test some specific postponed merge issues" => sub { + plan tests => 3; + + my $authmarc = MARC::Record->new; + $authmarc->append_fields( MARC::Field->new( '109', '', '', 'a' => 'aa', b => 'bb' )); + my $id = AddAuthority( $authmarc, undef, $authtype1 ); + my $biblio = MARC::Record->new; + $biblio->append_fields( + MARC::Field->new( '109', '', '', a => 'a1', 9 => $id ), + MARC::Field->new( '612', '', '', a => 'a2', 9 => $id+1 ), + MARC::Field->new( '612', '', '', a => 'a3', 9 => $id+2 ), + ); + my ( $biblionumber ) = C4::Biblio::AddBiblio( $biblio, '' ); + + # Merge A to B postponed, A is deleted (simulated by id+1) + # This proves the !authtypefrom condition in sub merge + merge({ mergefrom => $id + 1, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); + $biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); + is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); + + # Merge A to B postponed, delete B immediately (hits B < hits A) + # This proves the !@record_to test in sub merge + merge({ mergefrom => $id + 2, mergeto => $id + 1, MARCto => undef, biblionumbers => [ $biblionumber ] }); + $biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); + is( $biblio->field('612'), undef, 'Last 612 must be gone' ); + + # Show that we 'need' skip_merge; this example is far-fetched. + # We *prove* by contradiction. + # Suppose: Merge A to B postponed, and delete A would merge rightaway. + # (You would need some special race condition with merge.pl to do so.) + # The modify merge would be useless after that. + @linkedrecords = ( $biblionumber ); + my $restored_mocks = set_mocks(); + DelAuthority({ authid => $id }); # delete A + $restored_mocks->{auth_mod}->unmock_all; + $biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); + is( $biblio->subfield('109', '9'), $id, 'If the 109 is no longer present, another modify merge would not bring it back' ); +}; + sub set_mocks { # After we removed the Zebra code from merge, we only need to mock # get_usage_count and linked_biblionumbers here. -- 2.1.4