9ea11c271b977201e95b6e3b8eaf8eca0f1ab0b8
[yaffs-website] / web / modules / contrib / migrate_plus / tests / src / Unit / process / SkipOnValueTest.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Tests\migrate_plus\Unit\process\SkipOnValueTest.
6  */
7
8 namespace Drupal\Tests\migrate_plus\Unit\process;
9
10 use Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue;
11 use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase;
12
13 /**
14  * Tests the skip on value process plugin.
15  *
16  * @group migrate
17  * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue
18  */
19 class SkipOnValueTest extends MigrateProcessTestCase {
20
21   /**
22    * @covers ::process
23    * @expectedException \Drupal\migrate\MigrateSkipProcessException
24    */
25   public function testProcessSkipsOnValue() {
26     $configuration['method'] = 'process';
27     $configuration['value'] = 86;
28     (new SkipOnValue($configuration, 'skip_on_value', []))
29       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
30   }
31
32   /**
33    * @covers ::process
34    * @expectedException \Drupal\migrate\MigrateSkipProcessException
35    */
36   public function testProcessSkipsOnMultipleValue() {
37     $configuration['method'] = 'process';
38     $configuration['value'] = [1, 1, 2, 3, 5, 8];
39     (new SkipOnValue($configuration, 'skip_on_value', []))
40       ->transform('5', $this->migrateExecutable, $this->row, 'destinationproperty');
41   }
42
43   /**
44    * @covers ::process
45    */
46   public function testProcessBypassesOnNonValue() {
47     $configuration['method'] = 'process';
48     $configuration['value'] = 'sourcevalue';
49     $configuration['not_equals'] = TRUE;
50     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
51       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
52     $this->assertEquals($value, 'sourcevalue');
53     $configuration['value'] = 86;
54     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
55       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
56     $this->assertEquals($value, '86');
57   }
58
59   /**
60    * @covers ::process
61    */
62   public function testProcessSkipsOnMultipleNonValue() {
63     $configuration['method'] = 'process';
64     $configuration['value'] = [1, 1, 2, 3, 5, 8];
65     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
66       ->transform(4, $this->migrateExecutable, $this->row, 'destinationproperty');
67     $this->assertEquals($value, '4');
68   }
69
70   /**
71    * @covers ::row
72    * @expectedException \Drupal\migrate\MigrateSkipRowException
73    */
74   public function testRowSkipsOnValue() {
75     $configuration['method'] = 'row';
76     $configuration['value'] = 86;
77     (new SkipOnValue($configuration, 'skip_on_value', []))
78       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
79   }
80
81   /**
82    * @covers ::row
83    */
84   public function testRowBypassesOnNonValue() {
85     $configuration['method'] = 'row';
86     $configuration['value'] = 'sourcevalue';
87     $configuration['not_equals'] = TRUE;
88     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
89       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
90     $this->assertEquals($value, 'sourcevalue');
91     $configuration['value'] = 86;
92     $value = (new SkipOnValue($configuration, 'skip_on_value', []))
93       ->transform('86', $this->migrateExecutable, $this->row, 'destinationproperty');
94     $this->assertEquals($value, 86);
95   }
96
97   /**
98    * @covers ::row
99    * @expectedException \Drupal\migrate\MigrateException
100    */
101   public function testRequiredRowConfiguration() {
102     $configuration['method'] = 'row';
103     (new SkipOnValue($configuration, 'skip_on_value', []))
104       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
105   }
106
107   /**
108    * @covers ::process
109    * @expectedException \Drupal\migrate\MigrateException
110    */
111   public function testRequiredProcessConfiguration() {
112     $configuration['method'] = 'process';
113     (new SkipOnValue($configuration, 'skip_on_value', []))
114       ->transform('sourcevalue', $this->migrateExecutable, $this->row, 'destinationproperty');
115   }
116
117 }