3 namespace Drupal\Tests\migrate_plus\Unit\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\MigrateSkipProcessException;
7 use Drupal\migrate\MigrateSkipRowException;
8 use Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue;
9 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
12 * Tests the skip on value process plugin.
15 * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue
17 class SkipOnValueTest extends MigrateProcessTestCase {
22 public function testProcessSkipsOnValue() {
23 $configuration['method'] = 'process';
24 $configuration['value'] = 86;
25 $this->setExpectedException(MigrateSkipProcessException::class);
26 (new SkipOnValue($configuration, 'skip_on_value', []))
27 ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
33 public function testProcessSkipsOnMultipleValue() {
34 $configuration['method'] = 'process';
35 $configuration['value'] = [1, 1, 2, 3, 5, 8];
36 $this->setExpectedException(MigrateSkipProcessException::class);
37 (new SkipOnValue($configuration, 'skip_on_value', []))
38 ->transform('5', $this->migrateExecutable, $this->row, 'destinationproperty');
44 public function testProcessBypassesOnNonValue() {
45 $configuration['method'] = 'process';
46 $configuration['value'] = 'sourcevalue';
47 $configuration['not_equals'] = TRUE;
48 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
49 ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
50 $this->assertEquals($value, 'sourcevalue');
51 $configuration['value'] = 86;
52 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
53 ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
54 $this->assertEquals($value, '86');
60 public function testProcessSkipsOnMultipleNonValue() {
61 $configuration['method'] = 'process';
62 $configuration['value'] = [1, 1, 2, 3, 5, 8];
63 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
64 ->transform(4, $this->migrateExecutable, $this->row, 'destinationproperty');
65 $this->assertEquals($value, '4');
71 public function testProcessBypassesOnMultipleNonValue() {
72 $configuration['method'] = 'process';
73 $configuration['value'] = [1, 1, 2, 3, 5, 8];
74 $configuration['not_equals'] = TRUE;
75 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
76 ->transform(5, $this->migrateExecutable, $this->row, 'destinationproperty');
77 $this->assertEquals($value, '5');
78 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
79 ->transform(1, $this->migrateExecutable, $this->row, 'destinationproperty');
80 $this->assertEquals($value, '1');
86 public function testRowBypassesOnMultipleNonValue() {
87 $configuration['method'] = 'row';
88 $configuration['value'] = [1, 1, 2, 3, 5, 8];
89 $configuration['not_equals'] = TRUE;
90 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
91 ->transform(5, $this->migrateExecutable, $this->row, 'destinationproperty');
92 $this->assertEquals($value, '5');
93 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
94 ->transform(1, $this->migrateExecutable, $this->row, 'destinationproperty');
95 $this->assertEquals($value, '1');
101 public function testRowSkipsOnValue() {
102 $configuration['method'] = 'row';
103 $configuration['value'] = 86;
104 $this->setExpectedException(MigrateSkipRowException::class);
105 (new SkipOnValue($configuration, 'skip_on_value', []))
106 ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
112 public function testRowBypassesOnNonValue() {
113 $configuration['method'] = 'row';
114 $configuration['value'] = 'sourcevalue';
115 $configuration['not_equals'] = TRUE;
116 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
117 ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
118 $this->assertEquals($value, 'sourcevalue');
119 $configuration['value'] = 86;
120 $value = (new SkipOnValue($configuration, 'skip_on_value', []))
121 ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
122 $this->assertEquals($value, 86);
128 public function testRequiredRowConfiguration() {
129 $configuration['method'] = 'row';
130 $this->setExpectedException(MigrateException::class);
131 (new SkipOnValue($configuration, 'skip_on_value', []))
132 ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
138 public function testRequiredProcessConfiguration() {
139 $configuration['method'] = 'process';
140 $this->setExpectedException(MigrateException::class);
141 (new SkipOnValue($configuration, 'skip_on_value', []))
142 ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');