From d4f82cb63abe575d2ac4ec7d23cc9c405365539d 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 fail. Signed-off-by: Marcel de Rooy Signed-off-by: Marc VĂ©ron Signed-off-by: Jacek Ablewicz --- t/db_dependent/Authorities/Merge.t | 45 +++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Authorities/Merge.t b/t/db_dependent/Authorities/Merge.t index d4c9cfe..0ae6124 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,49 @@ 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 => 4; + + my $authmarc = MARC::Record->new; + $authmarc->append_fields( MARC::Field->new( '109', '', '', 'a' => 'aa', b => 'bb' )); + my $oldauthmarc = MARC::Record->new; + $oldauthmarc->append_fields( MARC::Field->new( '112', '', '', c => 'cc' )); + 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', c => 'cc', 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 + # Additionally, we test clearing subfield + merge({ mergefrom => $id + 1, MARCfrom => $oldauthmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); + $biblio = C4::Biblio::GetMarcBiblio( $biblionumber ); + is( $biblio->subfield('609', '9'), $id, '612 moved to 609' ); + is( $biblio->subfield('609', 'c'), undef, '609c cleared correctly' ); + + # 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. -- 1.7.10.4