class MigrateFieldPluginManagerTest in Drupal 10
Same name in this branch
- 10 core/modules/migrate_drupal/tests/src/Unit/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Unit\MigrateFieldPluginManagerTest
- 10 core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
Same name and namespace in other branches
- 8 core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
- 9 core/modules/migrate_drupal/tests/src/Kernel/MigrateFieldPluginManagerTest.php \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
Tests the field plugin manager.
@group migrate_drupal @coversDefaultClass \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManager
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, AssertContentTrait, ConfigTestTrait, ExtensionListTestTrait, RandomGeneratorTrait, TestRequirementsTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase implements MigrateMessageInterface
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateFieldPluginManagerTest
- class \Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase
- class \Drupal\Tests\migrate\Kernel\MigrateTestBase implements MigrateMessageInterface
Expanded class hierarchy of MigrateFieldPluginManagerTest
File
- core/
modules/ migrate_drupal/ tests/ src/ Kernel/ MigrateFieldPluginManagerTest.php, line 13
Namespace
Drupal\Tests\migrate_drupal\KernelView source
class MigrateFieldPluginManagerTest extends MigrateDrupalTestBase {
/**
* The field plugin manager.
*
* @var \Drupal\migrate_drupal\Plugin\MigrateFieldPluginManagerInterface
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
protected static $modules = [
'datetime',
'system',
'user',
'field',
'migrate_drupal',
'options',
'file',
'image',
'text',
'link',
'migrate_field_plugin_manager_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->pluginManager = $this->container
->get('plugin.manager.migrate.field');
}
/**
* Tests that the correct MigrateField plugins are used.
*
* @covers ::getPluginIdFromFieldType
*/
public function testPluginSelection() {
$this
->assertSame('link', $this->pluginManager
->getPluginIdFromFieldType('link', [
'core' => 6,
]));
$this
->assertSame('link_field', $this->pluginManager
->getPluginIdFromFieldType('link_field', [
'core' => 7,
]));
$this
->assertSame('image', $this->pluginManager
->getPluginIdFromFieldType('image', [
'core' => 7,
]));
$this
->assertSame('file', $this->pluginManager
->getPluginIdFromFieldType('file', [
'core' => 7,
]));
$this
->assertSame('d6_file', $this->pluginManager
->getPluginIdFromFieldType('file', [
'core' => 6,
]));
$this
->assertSame('d6_text', $this->pluginManager
->getPluginIdFromFieldType('text', [
'core' => 6,
]));
$this
->assertSame('d7_text', $this->pluginManager
->getPluginIdFromFieldType('text', [
'core' => 7,
]));
// Test that the deprecated d6 'date' plugin is not returned.
$this
->assertSame('datetime', $this->pluginManager
->getPluginIdFromFieldType('date', [
'core' => 6,
]));
// Test fallback when no core version is specified.
$this
->assertSame('d6_no_core_version_specified', $this->pluginManager
->getPluginIdFromFieldType('d6_no_core_version_specified', [
'core' => 6,
]));
}
/**
* Tests that a PluginNotFoundException is thrown when a plugin isn't found.
*
* @covers ::getPluginIdFromFieldType
* @dataProvider nonExistentPluginExceptionsData
*/
public function testNonExistentPluginExceptions($core, $field_type) {
$this
->expectException(PluginNotFoundException::class);
$this
->expectExceptionMessage(sprintf("Plugin ID '%s' was not found.", $field_type));
$this->pluginManager
->getPluginIdFromFieldType($field_type, [
'core' => $core,
]);
}
/**
* Provides data for testNonExistentPluginExceptions.
*
* @return array
* The data.
*/
public function nonExistentPluginExceptionsData() {
return [
'D7 Filefield' => [
'core' => 7,
'field_type' => 'filefield',
],
'D6 linkfield' => [
'core' => 6,
'field_type' => 'link_field',
],
'D7 link' => [
'core' => 7,
'field_type' => 'link',
],
'D7 no core version' => [
'core' => 7,
'field_type' => 'd6_no_core_version_specified',
],
];
}
/**
* Tests that plugins with no explicit weight are given a weight of 0.
*/
public function testDefaultWeight() {
$definitions = $this->pluginManager
->getDefinitions();
$deprecated_plugins = [
'date',
];
foreach ($definitions as $id => $definition) {
$this
->assertArrayHasKey('weight', $definition);
if (in_array($id, $deprecated_plugins, TRUE)) {
$this
->assertSame(9999999, $definition['weight']);
}
else {
$this
->assertSame(0, $definition['weight']);
}
}
}
}