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 transformation of 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 provideFilters
54 public function testTransform($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 * Provides filter ids for testing transformations.
84 * Formatted as $source_id, $tranformed_id, $invalid_id.
85 * When $invalid_id is provided the transformation should fail with the
88 public function provideFilters() {
90 'filter ID mapped to plugin that exists' => [
94 'filter ID not mapped but unchanged from the source and the plugin exists' => [
98 'filter ID mapped to plugin that does not exist' => [
103 'filter ID not mapped but unchanged from the source and the plugin does not exist' => [
108 'filter ID set and the plugin does not exist' => [