Bug 18458: Add a subtest in Merge.t
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 8 Dec 2017 12:45:55 +0000 (13:45 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 22 Dec 2017 16:15:36 +0000 (13:15 -0300)
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 <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Authority/Merge.t

index 7bf7fb5..d987b83 100755 (executable)
@@ -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.