public function MediaMigrationFormatterWidgetTest::testWidgetsAndFormattersWithMediaLibrary in Media Migration 8
Tests media widgets' and formatters' migration with Media Library.
@dataProvider providerTestCases
File
- tests/
src/ Kernel/ Migrate/ MediaMigrationFormatterWidgetTest.php, line 111
Class
- MediaMigrationFormatterWidgetTest
- Tests widgets and formatters.
Namespace
Drupal\Tests\media_migration\Kernel\MigrateCode
public function testWidgetsAndFormattersWithMediaLibrary(bool $classic_node_migration) {
$this
->createStandardMediaTypes();
$this
->setClassicNodeMigration($classic_node_migration);
$installer = $this->container
->get('module_installer');
assert($installer instanceof ModuleInstallerInterface);
$installer
->install([
'media_library',
]);
// Execute the media migrations.
$this
->executeMediaMigrations($classic_node_migration);
$media_fields = [
'field_image' => [
'form' => 'media_library_widget',
'view' => 'entity_reference_entity_view',
],
'field_media' => [
'form' => 'media_library_widget',
'view' => 'entity_reference_entity_view',
],
];
$entity_type_manager = $this->container
->get('entity_type.manager');
assert($entity_type_manager instanceof EntityTypeManagerInterface);
// Check default widget configurations. Every field widget should use.
foreach ($media_fields as $field_name => $expected_config) {
$entity_form_display = $entity_type_manager
->getStorage('entity_form_display')
->load(implode('.', [
'node',
'article',
'default',
]));
$entity_form_display_array = $entity_form_display
->toArray();
$content = $entity_form_display_array['content'];
$this
->assertTrue(array_key_exists($field_name, $content));
$this
->assertEquals($expected_config['form'], $content[$field_name]['type']);
}
// Check default formatter configurations.
foreach ($media_fields as $field_name => $expected_config) {
$entity_form_display = $entity_type_manager
->getStorage('entity_view_display')
->load(implode('.', [
'node',
'article',
'default',
]));
$entity_form_display_array = $entity_form_display
->toArray();
$content = $entity_form_display_array['content'];
$this
->assertTrue(array_key_exists($field_name, $content));
$this
->assertEquals($expected_config['view'], $content[$field_name]['type']);
}
$this
->assertMediaTypeDisplayModes();
}