08fbef238e4c35cf1df02420a1ef8f9ff4f1ac7d
[yaffs-website] / web / core / modules / migrate / tests / src / Unit / process / SkipOnEmptyTest.php
1 <?php
2
3 namespace Drupal\Tests\migrate\Unit\process;
4
5 use Drupal\migrate\MigrateSkipProcessException;
6 use Drupal\migrate\MigrateSkipRowException;
7 use Drupal\migrate\Plugin\migrate\process\SkipOnEmpty;
8
9 /**
10  * Tests the skip on empty process plugin.
11  *
12  * @group migrate
13  * @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\SkipOnEmpty
14  */
15 class SkipOnEmptyTest extends MigrateProcessTestCase {
16
17   /**
18    * @covers ::process
19    */
20   public function testProcessSkipsOnEmpty() {
21     $configuration['method'] = 'process';
22     $this->setExpectedException(MigrateSkipProcessException::class);
23     (new SkipOnEmpty($configuration, 'skip_on_empty', []))
24       ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
25   }
26
27   /**
28    * @covers ::process
29    */
30   public function testProcessBypassesOnNonEmpty() {
31     $configuration['method'] = 'process';
32     $value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
33       ->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
34     $this->assertSame($value, ' ');
35   }
36
37   /**
38    * @covers ::row
39    */
40   public function testRowSkipsOnEmpty() {
41     $configuration['method'] = 'row';
42     $this->setExpectedException(MigrateSkipRowException::class);
43     (new SkipOnEmpty($configuration, 'skip_on_empty', []))
44       ->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
45   }
46
47   /**
48    * @covers ::row
49    */
50   public function testRowBypassesOnNonEmpty() {
51     $configuration['method'] = 'row';
52     $value = (new SkipOnEmpty($configuration, 'skip_on_empty', []))
53       ->transform(' ', $this->migrateExecutable, $this->row, 'destinationproperty');
54     $this->assertSame($value, ' ');
55   }
56
57   /**
58    * Tests that a skip row exception without a message is raised.
59    *
60    * @covers ::row
61    */
62   public function testRowSkipWithoutMessage() {
63     $configuration = [
64       'method' => 'row',
65     ];
66     $process = new SkipOnEmpty($configuration, 'skip_on_empty', []);
67     $this->setExpectedException(MigrateSkipRowException::class);
68     $process->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
69   }
70
71   /**
72    * Tests that a skip row exception with a message is raised.
73    *
74    * @covers ::row
75    */
76   public function testRowSkipWithMessage() {
77     $configuration = [
78       'method' => 'row',
79       'message' => 'The value is empty',
80     ];
81     $process = new SkipOnEmpty($configuration, 'skip_on_empty', []);
82     $this->setExpectedException(MigrateSkipRowException::class, 'The value is empty');
83     $process->transform('', $this->migrateExecutable, $this->row, 'destinationproperty');
84   }
85
86 }