diff --git a/src/Plugin/migrate/process/SkipOnValue.php b/src/Plugin/migrate/process/SkipOnValue.php index f9c26be09d563e637fd42c9c41d897bfe48cfdda..1a0c8f545c5996f3c5708da619f918dd4ef60168 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 c1bdfac23883d618a2ff733bda7d7ce3fbd8a861..968e6f0fbc7a2be0ca86f53095dcb230747458e9 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 */