class ProcessFieldTest in Drupal 9
Same name and namespace in other branches
- 8 core/modules/field/tests/src/Unit/Plugin/migrate/process/ProcessFieldTest.php \Drupal\Tests\field\Unit\Plugin\migrate\process\ProcessFieldTest
Tests the ProcessField migrate process plugin.
@coversDefaultClass \Drupal\field\Plugin\migrate\process\ProcessField @group field
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\field\Unit\Plugin\migrate\process\ProcessFieldTest
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of ProcessFieldTest
File
- core/
modules/ field/ tests/ src/ Unit/ Plugin/ migrate/ process/ ProcessFieldTest.php, line 21
Namespace
Drupal\Tests\field\Unit\Plugin\migrate\processView source
class ProcessFieldTest extends MigrateTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->fieldManager = $this
->prophesize(MigrateFieldPluginManagerInterface::class);
$this->fieldPlugin = $this
->prophesize(MigrateFieldInterface::class);
$this->migrateExecutable = $this
->prophesize(MigrateExecutable::class);
$this->migration = $this
->prophesize(MigrationInterface::class);
$this->row = $this
->prophesize(Row::class);
$this->fieldManager
->getPluginIdFromFieldType('foo', [], $this->migration
->reveal())
->willReturn('foo');
$this->fieldManager
->createInstance('foo', [], $this->migration
->reveal())
->willReturn($this->fieldPlugin);
parent::setUp();
}
/**
* Tests the transform method.
*
* @param string $method
* The method to call.
* @param string $value
* The value to process.
* @param mixed $expected_value
* The expected transformed value.
* @param string $migrate_exception
* The MigrateException message to expect.
* @param bool $plugin_not_found
* Whether the field plugin is not found.
*
* @covers ::transform
* @dataProvider providerTestTransform
*/
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->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->fieldManager
->getPluginIdFromFieldType()
->willThrow($exception);
}
$transformed_value = $this->plugin
->transform($value, $this->migrateExecutable
->reveal(), $this->row
->reveal(), 'foo');
$this
->assertSame($transformed_value, $expected_value);
}
/**
* Provides data for the transform method test.
*
* @return array
* - The method to call.
* - The value to process.
* - The expected transformed value.
* - The MigrateException message to expect.
* - Whether the field plugin is not found.
*/
public function providerTestTransform() {
return [
// Tests the getFieldType() method.
[
'method' => 'getFieldType',
'value' => 'foo',
'expected_value' => 'bar',
],
// Tests the getFieldFormatterMap() method.
[
'method' => 'getFieldFormatterMap',
'value' => 'foo',
'expected_value' => [
'foo' => 'bar',
],
],
// Tests the getFieldWidgetMap() method.
[
'method' => 'getFieldWidgetMap',
'value' => 'foo',
'expected_value' => [
'foo' => 'bar',
],
],
// Tests that an exception is thrown if the value is not a string.
[
'method' => 'getFieldType',
'value' => [
'foo',
],
'expected_value' => '',
'migrate_exception' => 'The input value must be a string.',
],
// Tests that an exception is thrown if no method name is provided.
[
'method' => '',
'value' => '',
'expected_value' => '',
'migrate_exception' => 'You need to specify the name of a method to be called on the Field plugin.',
],
// Tests that NULL is returned if no field plugin is found.
[
'method' => 'getFieldType',
'value' => 'foo',
'expected_value' => NULL,
'migrate_exception' => '',
'plugin_not_found' => TRUE,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateTestCase:: |
protected | property | The migration ID map. | |
MigrateTestCase:: |
protected | property | An array of migration configuration values. | 7 |
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Gets an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieves a mocked migration. | |
MigrateTestCase:: |
protected | function | Gets the value on a row for a given key. | |
MigrateTestCase:: |
public | function | Tests a query. | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
ProcessFieldTest:: |
public | function | Provides data for the transform method test. | |
ProcessFieldTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ProcessFieldTest:: |
public | function | Tests the transform method. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |