Bug 25008: Regression tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 27 Mar 2020 20:53:32 +0000 (17:53 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 07:31:02 +0000 (08:31 +0100)
This patch highlights a behaviour of Koha::RecordProcessor that is
unexpected: if you change the original options using ->options, the
loaded filters don't pick the change. That's because the filter objects
are loaded on ->new, and they are never updated.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/RecordProcessor.t
=> FAIL: Test prove ->options doesn't update the filters!

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/RecordProcessor.t

index 63683c1..aab2b3c 100755 (executable)
@@ -149,4 +149,55 @@ subtest 'new() tests' => sub {
     is_deeply( $filter_params, $parameters, 'Initialization parameters' );
 };
 
+subtest 'options() tests' => sub {
+
+    plan tests => 4;
+
+    # Create a processor with some options
+    my $record_processor = Koha::RecordProcessor->new(
+        {
+            filters => ['EmbedSeeFromHeadings','Null'],
+            options => {
+                dummy => 'something'
+            }
+        }
+    );
+
+    my $filter = $record_processor->filters->[0];
+
+    is(
+        ref( $filter ),
+        'Koha::Filter::MARC::EmbedSeeFromHeadings',
+        'Correct second filter initialized'
+    );
+
+    is_deeply(
+        $filter->params->{options},
+        { dummy => 'something' },
+        'Options are set correctly'
+    );
+
+    # Update the chosen options
+    $record_processor->options(
+        {
+            dummy => 'something else'
+        }
+    );
+
+    # Re-fetch the filter
+    $filter = $record_processor->filters->[0];
+
+    is(
+        ref( $filter ),
+        'Koha::Filter::MARC::EmbedSeeFromHeadings',
+        'Correct second filter initialized'
+    );
+
+    is_deeply(
+        $filter->params->{options},
+        { dummy => 'something else' },
+        'Options are updated correctly'
+    );
+};
+
 done_testing();