View source
<?php
namespace Drupal\Tests\media_migration\Functional;
class MigrateEmbedMediaTokenToMediaEmbedTest extends MigrateEmbedMediaTokenTestBase {
protected $embedTokenDestinationFilterPlugin = 'media_embed';
protected $embedMediaCssSelector = '.field--name-body.field--type-text-with-summary .media.media--type-image .field--name-field-media-image';
public function testMediaTokenToMediaEmbedTransform(string $reference_method, array $extra_modules, bool $preexisting_media_types) {
$media_types = $this->container
->get('entity_type.manager')
->getStorage('media_type')
->loadMultiple();
foreach ($media_types as $media_type) {
$media_type
->delete();
}
if ($preexisting_media_types) {
$this
->createStandardMediaTypes(TRUE);
}
$this
->setEmbedMediaReferenceMethod($reference_method);
if (!empty($extra_modules)) {
$this->container
->get('module_installer')
->install($extra_modules);
}
$this
->assertMigrateUpgradeViaUi();
$this
->assertMediaMigrationResults();
$expected_node1_embed_attributes = [
0 => [
'data-view-mode' => 'wysiwyg',
'data-entity-type' => 'media',
'data-entity-uuid' => TRUE,
'alt' => 'Different alternative text about blue.png in the test article',
'title' => 'Different title copy for blue.png in the test article',
'data-align' => 'center',
],
1 => [
'data-entity-type' => 'media',
'data-entity-uuid' => TRUE,
'data-view-mode' => 'default',
'alt' => 'A yellow image',
'title' => 'This is a yellow image',
],
];
$this
->assertMediaTokenTransform($expected_node1_embed_attributes);
$this
->assertNode1FieldValues($expected_node1_embed_attributes);
}
public function providerMediaEmbedTransform() {
$test_cases = [
'ID reference method, no additional modules, preexisting media types' => [
'reference method' => 'id',
'additional modules' => [],
'Preexisting media types' => TRUE,
],
'ID reference method, Entity Embed installed, preexisting media types' => [
'reference method' => 'id',
'additional modules' => [
'entity_embed',
],
'Preexisting media types' => TRUE,
],
'UUID reference method, no additional modules, preexisting media types' => [
'reference method' => 'uuid',
'additional modules' => [],
'Preexisting media types' => TRUE,
],
'UUID reference method, Entity Embed installed, preexisting media types' => [
'reference method' => 'uuid',
'additional modules' => [
'entity_embed',
],
'Preexisting media types' => TRUE,
],
];
$test_cases_without_media_types = [];
foreach ($test_cases as $test_case_label => $test_case) {
$without_media_label = preg_replace('/preexisting media types$/', 'no media types', $test_case_label);
$test_case['Preexisting media types'] = FALSE;
$test_cases_without_media_types[$without_media_label] = $test_case;
}
$test_cases += $test_cases_without_media_types;
return $test_cases;
}
}