From e0e5011364d1496badfba9a1c9a0303524cd8a3f Mon Sep 17 00:00:00 2001
From: gnuget <gnuget@992990.no-reply.drupal.org>
Date: Mon, 6 Aug 2018 13:00:10 -0500
Subject: [PATCH] Issue #2959775 by gnuget, mr.baileys, heddn: SkipOnValue with
 multiple configured values and "not_equals" does not make sense

---
 src/Plugin/migrate/process/SkipOnValue.php | 22 +++++++++++-----
 tests/src/Unit/process/SkipOnValueTest.php | 30 ++++++++++++++++++++++
 2 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/src/Plugin/migrate/process/SkipOnValue.php b/src/Plugin/migrate/process/SkipOnValue.php
index f9c26be0..1a0c8f54 100644
--- a/src/Plugin/migrate/process/SkipOnValue.php
+++ b/src/Plugin/migrate/process/SkipOnValue.php
@@ -65,10 +65,15 @@ class SkipOnValue extends ProcessPluginBase {
     }
 
     if (is_array($this->configuration['value'])) {
+      $value_in_array = FALSE;
+      $not_equals = isset($this->configuration['not_equals']);
+
       foreach ($this->configuration['value'] as $skipValue) {
-        if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
-          throw new MigrateSkipRowException();
-        }
+        $value_in_array |= $this->compareValue($value, $skipValue);
+      }
+
+      if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
+        throw new MigrateSkipRowException();
       }
     }
     elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
@@ -87,10 +92,15 @@ class SkipOnValue extends ProcessPluginBase {
     }
 
     if (is_array($this->configuration['value'])) {
+      $value_in_array = FALSE;
+      $not_equals = isset($this->configuration['not_equals']);
+
       foreach ($this->configuration['value'] as $skipValue) {
-        if ($this->compareValue($value, $skipValue, !isset($this->configuration['not_equals']))) {
-          throw new MigrateSkipProcessException();
-        }
+        $value_in_array |= $this->compareValue($value, $skipValue);
+      }
+
+      if (($not_equals && !$value_in_array) || (!$not_equals && $value_in_array)) {
+        throw new MigrateSkipProcessException();
       }
     }
     elseif ($this->compareValue($value, $this->configuration['value'], !isset($this->configuration['not_equals']))) {
diff --git a/tests/src/Unit/process/SkipOnValueTest.php b/tests/src/Unit/process/SkipOnValueTest.php
index c1bdfac2..968e6f0f 100644
--- a/tests/src/Unit/process/SkipOnValueTest.php
+++ b/tests/src/Unit/process/SkipOnValueTest.php
@@ -65,6 +65,36 @@ class SkipOnValueTest extends MigrateProcessTestCase {
     $this->assertEquals($value, '4');
   }
 
+  /**
+   * @covers ::process
+   */
+  public function testProcessBypassesOnMultipleNonValue() {
+    $configuration['method'] = 'process';
+    $configuration['value'] = [1, 1, 2, 3, 5, 8];
+    $configuration['not_equals'] = TRUE;
+    $value = (new SkipOnValue($configuration, 'skip_on_value', []))
+      ->transform(5, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertEquals($value, '5');
+    $value = (new SkipOnValue($configuration, 'skip_on_value', []))
+      ->transform(1, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertEquals($value, '1');
+  }
+
+  /**
+   * @covers ::row
+   */
+  public function testRowBypassesOnMultipleNonValue() {
+    $configuration['method'] = 'row';
+    $configuration['value'] = [1, 1, 2, 3, 5, 8];
+    $configuration['not_equals'] = TRUE;
+    $value = (new SkipOnValue($configuration, 'skip_on_value', []))
+      ->transform(5, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertEquals($value, '5');
+    $value = (new SkipOnValue($configuration, 'skip_on_value', []))
+      ->transform(1, $this->migrateExecutable, $this->row, 'destinationproperty');
+    $this->assertEquals($value, '1');
+  }
+
   /**
    * @covers ::row
    */
-- 
GitLab