View source
<?php
namespace Drupal\Tests\media_migration\Kernel\Migrate;
use Drupal\Core\Extension\ModuleInstallerInterface;
use PHPUnit\Framework\AssertionFailedError;
class MediaMigrationPlainTest extends MediaMigrationPlainTestBase {
public function testPlainFileToMediaMigration(bool $classic_node_migration, bool $preexisting_media_types) {
$this
->setClassicNodeMigration($classic_node_migration);
if ($preexisting_media_types) {
$this
->createStandardMediaTypes(TRUE);
}
$this
->assertArticleBodyFieldMigrationProcesses($classic_node_migration ? 'd7_node:article' : 'd7_node_complete:article', [
[
'plugin' => 'get',
'source' => 'body',
],
[
'plugin' => 'media_wysiwyg_filter',
],
[
'plugin' => 'ckeditor_link_file_to_linkit',
],
]);
$this
->executeMediaMigrations($classic_node_migration);
$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();
$this
->assertFilterFormats();
}
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;
}
public function testChangeTracking() {
$module_installer = \Drupal::service('module_installer');
assert($module_installer instanceof ModuleInstallerInterface);
$module_installer
->install([
'media_migration_test_change_tracking',
]);
$this
->testPlainFileToMediaMigration(FALSE, FALSE);
$this->sourceDatabase
->update('file_managed')
->condition('fid', 1)
->fields([
'filename' => 'Blue PNG changed',
])
->execute();
try {
$this
->executeMediaMigrations();
} catch (\Exception $exception) {
throw new AssertionFailedError($exception
->getMessage() . "\n" . $exception
->getLine() . "\n" . $exception
->getTraceAsString());
}
$this
->assertNonMediaToMedia1FieldValues('Blue PNG changed');
}
}