View source
<?php
namespace Drupal\Tests\media_migration\Functional;
use Drupal\Tests\media_migration\Traits\MediaMigrationAssertionsForNonMediaSourceTrait;
class MigrateMediaFromNonMediaSourceTest extends MigrateMediaTestBase {
use MediaMigrationAssertionsForNonMediaSourceTrait;
public static $modules = [
'linkit',
];
protected function getFixtureFilePath() {
return drupal_get_path('module', 'media_migration') . '/tests/fixtures/drupal7_nomedia.php';
}
protected function getExpectedEntities() {
return [];
}
public function testPlainFileToMediaMigration(bool $classic_node_migration, bool $preexisting_media_types) {
$this
->setClassicNodeMigration($classic_node_migration);
$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
->assertMigrateUpgradeViaUi(FALSE);
$this
->assertMediaMigrationResults();
$this
->assertMediaFieldsAllowedTypes('node', 'article', 'field_image', [
'image',
]);
$this
->assertMediaFieldsAllowedTypes('node', 'article', 'field_image_multi', [
'image',
]);
$media_type_ids = array_keys($this->container
->get('entity_type.manager')
->getStorage('media_type')
->loadMultiple());
$this
->assertMediaFieldsAllowedTypes('node', 'article', 'field_file', $media_type_ids);
$this
->assertMediaFieldsAllowedTypes('node', 'article', 'field_file_multi', $media_type_ids);
$this
->assertNonMediaToMediaImageMediaBundleSourceFieldProperties();
$this
->assertNonMediaToMediaDocumentMediaBundleSourceFieldProperties();
$this
->assertNonMediaToMediaAudioMediaBundleSourceFieldProperties();
$this
->assertNonMediaToMediaVideoMediaBundleSourceFieldProperties();
$this
->assertNonMediaToMedia1FieldValues();
$this
->assertNonMediaToMedia2FieldValues();
$this
->assertNonMediaToMedia3FieldValues();
$this
->assertNonMediaToMedia6FieldValues();
$this
->assertNonMediaToMedia7FieldValues();
$this
->assertNonMediaToMedia8FieldValues();
$this
->assertNonMediaToMedia9FieldValues();
$this
->assertNonMediaToMedia10FieldValues();
$this
->assertNonMediaToMedia11FieldValues();
$this
->assertNonMediaToMedia12FieldValues();
$this
->assertNonMediaToMediaNode1FieldValues();
$this
->assertNonMediaToMediaNode2FieldValues();
}
public function providerTestPlainFileToMediaMigration() {
$test_cases = [
'Classic node migration, no initial media types' => [
'Classic node migration' => TRUE,
'Preexisting media types' => FALSE,
],
'Complete node migration, no initial media types' => [
'Classic node migration' => FALSE,
'Preexisting media types' => FALSE,
],
'Classic node migration, preexisting media types' => [
'Classic node migration' => TRUE,
'Preexisting media types' => TRUE,
],
'Complete node migration, preexisting media types' => [
'Classic node migration' => FALSE,
'Preexisting media types' => TRUE,
],
];
if (version_compare(\Drupal::VERSION, '8.9', '<')) {
$test_cases = array_filter($test_cases, function ($test_case) {
return $test_case['Classic node migration'];
});
}
return $test_cases;
}
}