Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / migrate_plus / tests / src / Unit / process / SkipOnValueTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate_plus\Unit\process;
4
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;
10
11 /**
12  * Tests the skip on value process plugin.
13  *
14  * @group migrate
15  * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue
16  */
17 class SkipOnValueTest extends MigrateProcessTestCase {
18
19   /**
20    * @covers ::process
21    */
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');
28   }
29
30   /**
31    * @covers ::process
32    */
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');
39   }
40
41   /**
42    * @covers ::process
43    */
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');
55   }
56
57   /**
58    * @covers ::process
59    */
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');
66   }
67
68   /**
69    * @covers ::process
70    */
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');
81   }
82
83   /**
84    * @covers ::row
85    */
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');
96   }
97
98   /**
99    * @covers ::row
100    */
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');
107   }
108
109   /**
110    * @covers ::row
111    */
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);
123   }
124
125   /**
126    * @covers ::row
127    */
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');
133   }
134
135   /**
136    * @covers ::process
137    */
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');
143   }
144
145 }