c1bdfac23883d618a2ff733bda7d7ce3fbd8a861
[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 ::row
70    */
71   public function testRowSkipsOnValue() {
72     $configuration['method'] = 'row';
73     $configuration['value'] = 86;
74     $this->setExpectedException(MigrateSkipRowException::class);
75     (new SkipOnValue($configuration, 'skip_on_value', []))
76       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
77   }
78
79   /**
80    * @covers ::row
81    */
82   public function testRowBypassesOnNonValue() {
83     $configuration['method'] = 'row';
84     $configuration['value'] = 'sourcevalue';
85     $configuration['not_equals'] = TRUE;
86     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
87       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
88     $this->assertEquals($value, 'sourcevalue');
89     $configuration['value'] = 86;
90     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
91       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
92     $this->assertEquals($value, 86);
93   }
94
95   /**
96    * @covers ::row
97    */
98   public function testRequiredRowConfiguration() {
99     $configuration['method'] = 'row';
100     $this->setExpectedException(MigrateException::class);
101     (new SkipOnValue($configuration, 'skip_on_value', []))
102       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
103   }
104
105   /**
106    * @covers ::process
107    */
108   public function testRequiredProcessConfiguration() {
109     $configuration['method'] = 'process';
110     $this->setExpectedException(MigrateException::class);
111     (new SkipOnValue($configuration, 'skip_on_value', []))
112       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
113   }
114
115 }