You are here

public function ProcessFieldTest::testTransform in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php \Drupal\Tests\field\Unit\Plugin\migrate\process\ProcessFieldTest::testTransform()

Tests the transform method.

@covers ::transform @dataProvider providerTestTransform

Parameters

string $method: The method to call.

string $value: The value to process.

mixed $expected_value: The expected transformed value.

string $migrate_exception: The MigrateException message to expect.

bool $plugin_not_found: Whether the field plugin is not found.

File

core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php, line 59

Class

ProcessFieldTest
Tests the ProcessField migrate process plugin.

Namespace

Drupal\Tests\field\Unit\Plugin\migrate\process

Code

public function testTransform($method, $value, $expected_value, $migrate_exception = '', $plugin_not_found = FALSE) {
  if ($method) {
    $this->fieldPlugin
      ->{$method}($this->row
      ->reveal())
      ->willReturn($expected_value);
  }
  $this->plugin = new ProcessField([
    'method' => $method,
  ], $value, [], $this->cckFieldManager
    ->reveal(), $this->fieldManager
    ->reveal(), $this->migration
    ->reveal());
  if ($migrate_exception) {
    $this
      ->expectException(MigrateException::class);
    $this
      ->expectExceptionMessage($migrate_exception);
  }
  if ($plugin_not_found) {
    $exception = new PluginNotFoundException('foo');
    $this->cckFieldManager
      ->getPluginIdFromFieldType()
      ->willThrow($exception);
    $this->fieldManager
      ->getPluginIdFromFieldType()
      ->willThrow($exception);
  }
  $transformed_value = $this->plugin
    ->transform($value, $this->migrateExecutable
    ->reveal(), $this->row
    ->reveal(), 'foo');
  $this
    ->assertSame($transformed_value, $expected_value);
}