From 6020fe50e13c4c9d6ed8bca133c5168f5394d804 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 8 Dec 2017 13:45:55 +0100 Subject: [PATCH] Bug 18458: Add a subtest in Merge.t This test illustrates the problem we have if you run it without the second patch. And it serves to demonstrate that we resolved the situation if you run it after the second patch. Test plan: [1] Without the second patch: The last subtest should fail. Signed-off-by: Marcel de Rooy Signed-off-by: Josef Moravec --- t/db_dependent/Authority/Merge.t | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Authority/Merge.t b/t/db_dependent/Authority/Merge.t index 7bf7fb5..d987b83 100755 --- a/t/db_dependent/Authority/Merge.t +++ b/t/db_dependent/Authority/Merge.t @@ -4,7 +4,7 @@ use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 9; use Getopt::Long; use MARC::Record; @@ -360,6 +360,31 @@ subtest "Graceful resolution of missing reporting tag" => sub { $fw2->auth_tag_to_report('112')->store; }; +subtest 'merge should not reorder too much' => sub { + plan tests => 2; + + # Back to loose mode + t::lib::Mocks::mock_preference('AuthorityMergeMode', 'loose'); + + 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', '', '', 9 => $id, i => 'in front', a => 'aa', c => 'after controlled block' ), # this field shows the old situation when $9 is the first subfield + MARC::Field->new( '609', '', '', i => 'in front', a => 'aa', c => 'after controlled block', 9 => $id ), # here $9 is already the last one + ); + my ( $biblionumber ) = C4::Biblio::AddBiblio( $biblio, '' ); + + # Merge 109 and 609 and check order of subfields + merge({ mergefrom => $id, MARCfrom => $authmarc, mergeto => $id, MARCto => $authmarc, biblionumbers => [ $biblionumber ] }); + my $biblio2 = C4::Biblio::GetMarcBiblio({ biblionumber => $biblionumber }); + my $subfields = [ map { $_->[0] } $biblio2->field('109')->subfields ]; + is_deeply( $subfields, [ 'i', 'a', 'b', 'c', '9' ], 'Merge only moved $9' ); + $subfields = [ map { $_->[0] } $biblio2->field('609')->subfields ]; + is_deeply( $subfields, [ 'i', 'a', 'b', 'c', '9' ], 'Order kept' ); +}; + 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