Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / filter / tests / src / Kernel / Plugin / migrate / process / FilterIdTest.php
1 <?php
2
3 namespace Drupal\Tests\filter\Kernel\Plugin\migrate\process;
4
5 use Drupal\filter\Plugin\migrate\process\FilterID;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\migrate\MigrateExecutableInterface;
8 use Drupal\migrate\Plugin\MigrationInterface;
9 use Drupal\migrate\Row;
10
11 /**
12  * Unit tests of the filter_id plugin.
13  *
14  * @coversDefaultClass \Drupal\filter\Plugin\migrate\process\FilterID
15  * @group filter
16  */
17 class FilterIdTest extends KernelTestBase {
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = ['filter'];
23
24   /**
25    * The mocked MigrateExecutable.
26    *
27    * @var \Drupal\migrate\MigrateExecutableInterface|\PHPUnit_Framework_MockObject_MockObject
28    */
29   protected $executable;
30
31   /**
32    * {@inheritdoc}
33    */
34   protected function setUp() {
35     parent::setUp();
36     $this->executable = $this->getMock(MigrateExecutableInterface::class);
37   }
38
39   /**
40    * Tests the filter_id plugin.
41    *
42    * @param mixed $value
43    *   The input value to the plugin.
44    * @param string $expected_value
45    *   The output value expected from the plugin.
46    * @param string $invalid_id
47    *   (optional) The invalid plugin ID which is expected to be logged by the
48    *   MigrateExecutable object.
49    *
50    * @dataProvider testProvider
51    *
52    * @covers ::transform
53    */
54   public function test($value, $expected_value, $invalid_id = NULL) {
55     $configuration = [
56       'bypass' => TRUE,
57       'map' => [
58         'foo' => 'filter_html',
59         'baz' => 'php_code',
60       ],
61     ];
62     $plugin = FilterID::create($this->container, $configuration, 'filter_id', []);
63
64     if (isset($invalid_id)) {
65       $this->executable
66         ->expects($this->exactly(1))
67         ->method('saveMessage')
68         ->with(
69           'Filter ' . $invalid_id . ' could not be mapped to an existing filter plugin; defaulting to filter_null.',
70           MigrationInterface::MESSAGE_WARNING
71         );
72     }
73
74     $row = new Row();
75     $output_value = $plugin->transform($value, $this->executable, $row, 'foo');
76
77     $this->assertSame($expected_value, $output_value);
78   }
79
80   /**
81    * The test data provider.
82    *
83    * @return array
84    */
85   public function testProvider() {
86     return [
87       // The filter ID is mapped, and the plugin exists.
88       [
89         'foo',
90         'filter_html',
91       ],
92       // The filter ID isn't mapped, but it's unchanged from the source (i.e.,
93       // it bypasses the static map) and the plugin exists.
94       [
95         'filter_html',
96         'filter_html',
97       ],
98       // The filter ID is mapped, but the plugin does not exist.
99       [
100         'baz',
101         'filter_null',
102         'php_code',
103       ],
104       // The filter ID isn't mapped, but it's unchanged from the source (i.e.,
105       // it bypasses the static map) but the plugin does not exist.
106       [
107         'php_code',
108         'filter_null',
109         'php_code',
110       ],
111       [
112         ['filter', 1],
113         'filter_null',
114         'filter:1',
115       ],
116     ];
117   }
118
119 }