3 namespace Drupal\Tests\filter\Kernel\Plugin\migrate\process;
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;
12 * Unit tests of the filter_id plugin.
14 * @coversDefaultClass \Drupal\filter\Plugin\migrate\process\FilterID
17 class FilterIdTest extends KernelTestBase {
22 public static $modules = ['filter'];
25 * The mocked MigrateExecutable.
27 * @var \Drupal\migrate\MigrateExecutableInterface|\PHPUnit_Framework_MockObject_MockObject
29 protected $executable;
34 protected function setUp() {
36 $this->executable = $this->getMock(MigrateExecutableInterface::class);
40 * Tests the filter_id plugin.
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.
50 * @dataProvider testProvider
54 public function test($value, $expected_value, $invalid_id = NULL) {
58 'foo' => 'filter_html',
62 $plugin = FilterID::create($this->container, $configuration, 'filter_id', []);
64 if (isset($invalid_id)) {
66 ->expects($this->exactly(1))
67 ->method('saveMessage')
69 'Filter ' . $invalid_id . ' could not be mapped to an existing filter plugin; defaulting to filter_null.',
70 MigrationInterface::MESSAGE_WARNING
75 $output_value = $plugin->transform($value, $this->executable, $row, 'foo');
77 $this->assertSame($expected_value, $output_value);
81 * The test data provider.
85 public function testProvider() {
87 // The filter ID is mapped, and the plugin exists.
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.
98 // The filter ID is mapped, but the plugin does not exist.
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.