You are here

public function FilterIdTest::testTransform in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterIdTest.php \Drupal\Tests\filter\Kernel\Plugin\migrate\process\FilterIdTest::testTransform()
  2. 9 core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterIdTest.php \Drupal\Tests\filter\Kernel\Plugin\migrate\process\FilterIdTest::testTransform()

Tests transformation of filter_id plugin.

@dataProvider provideFilters

@covers ::transform

Parameters

mixed $value: The input value to the plugin.

string $expected_value: The output value expected from the plugin.

string $invalid_id: (optional) The invalid plugin ID which is expected to be logged by the MigrateExecutable object.

bool $skip_exception: (optional) Set to TRUE if we expect the filter to be skipped because it is a transformation-only filter.

File

core/modules/filter/tests/src/Kernel/Plugin/migrate/process/FilterIdTest.php, line 58

Class

FilterIdTest
Unit tests of the filter_id plugin.

Namespace

Drupal\Tests\filter\Kernel\Plugin\migrate\process

Code

public function testTransform($value, $expected_value, $invalid_id = NULL, $skip_exception = FALSE) {
  $configuration = [
    'bypass' => TRUE,
    'map' => [
      'foo' => 'filter_html',
      'baz' => 'php_code',
    ],
  ];
  $plugin = FilterID::create($this->container, $configuration, 'filter_id', []);
  if ($skip_exception) {
    $this->executable
      ->expects($this
      ->exactly(1))
      ->method('saveMessage')
      ->with(sprintf('Filter %s could not be mapped to an existing filter plugin; omitted since it is a transformation-only filter. Install and configure a successor after the migration.', $value), MigrationInterface::MESSAGE_INFORMATIONAL);
    $this
      ->expectException(MigrateSkipProcessException::class);
    $this
      ->expectExceptionMessage(sprintf("The transformation-only filter %s was skipped.", $value));
  }
  if (isset($invalid_id)) {
    $this->executable
      ->expects($this
      ->exactly(1))
      ->method('saveMessage')
      ->with(sprintf('Filter %s could not be mapped to an existing filter plugin; defaulting to %s and dropping all settings. Either redo the migration with the module installed that provides an equivalent filter, or modify the text format after the migration to remove this filter if it is no longer necessary.', $invalid_id, $expected_value), MigrationInterface::MESSAGE_WARNING);
  }
  $row = new Row();
  $output_value = $plugin
    ->transform($value, $this->executable, $row, 'foo');
  $this
    ->assertSame($expected_value, $output_value);
}