View source
<?php
namespace Drupal\Tests\media_migration\Functional;
use Drupal\Tests\TestFileCreationTrait;
class MigrateMediaTest extends MigrateMediaTestBase {
use TestFileCreationTrait;
protected function getExpectedEntities() {
return [];
}
public function testMediaMigrate(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();
$assert_session = $this
->assertSession();
$this
->assertArticleImageFieldsAllowedTypes();
$this
->assertArticleMediaFieldsAllowedTypes();
$this
->assertMedia1FieldValues();
$this
->drupalGet('media/1/edit');
$assert_session
->statusCodeEquals(200);
$this
->assertPageTitle('Edit Image Blue PNG');
$assert_session
->hiddenFieldValueEquals('field_media_image[0][fids]', '1');
$assert_session
->fieldValueEquals('field_media_image[0][alt]', 'Alternative text about blue.png');
$assert_session
->fieldValueEquals('field_media_image[0][title]', 'Title copy for blue.png');
$assert_session
->fieldValueEquals('field_media_integer[0][value]', '1000');
$assert_session
->fieldNotExists('field_file_image_alt_text[0][value]');
$assert_session
->fieldNotExists('field_file_image_title_text[0][value]');
$assert_session
->fieldValueEquals('uid[0][target_id]', 'user (1)');
$assert_session
->fieldValueEquals('created[0][value][date]', '2020-04-24');
$assert_session
->fieldValueEquals('created[0][value][time]', '06:58:29');
$this
->getSession()
->getPage()
->clickLink('Blue PNG');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertMedia2FieldValues();
$this
->drupalGet('media/2/edit');
$assert_session
->statusCodeEquals(200);
$this
->assertPageTitle('Edit Image green.jpg');
$assert_session
->hiddenFieldValueEquals('field_media_image[0][fids]', '2');
$assert_session
->fieldValueEquals('field_media_image[0][alt]', 'Alternate text for green.jpg image');
$assert_session
->fieldValueEquals('field_media_image[0][title]', 'Title text for green.jpg image');
$assert_session
->fieldValueEquals('field_media_integer[0][value]', '');
$assert_session
->fieldNotExists('field_file_image_alt_text[0][value]');
$assert_session
->fieldNotExists('field_file_image_title_text[0][value]');
$assert_session
->fieldValueEquals('uid[0][target_id]', 'user (1)');
$assert_session
->fieldValueEquals('created[0][value][date]', '2020-04-24');
$assert_session
->fieldValueEquals('created[0][value][time]', '08:12:02');
$this
->getSession()
->getPage()
->clickLink('green.jpg');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertMedia3FieldValues();
$this
->drupalGet('media/3/edit');
$assert_session
->statusCodeEquals(200);
$this
->assertPageTitle('Edit Image red.jpeg');
$assert_session
->hiddenFieldValueEquals('field_media_image[0][fids]', '3');
$assert_session
->fieldValueEquals('field_media_image[0][alt]', 'Alternative text about red.jpeg');
$assert_session
->fieldValueEquals('field_media_image[0][title]', 'Title copy for red.jpeg');
$assert_session
->fieldValueEquals('field_media_integer[0][value]', '333');
$assert_session
->fieldNotExists('field_file_image_alt_text[0][value]');
$assert_session
->fieldNotExists('field_file_image_title_text[0][value]');
$assert_session
->fieldValueEquals('uid[0][target_id]', 'user (1)');
$assert_session
->fieldValueEquals('created[0][value][date]', '2020-04-24');
$assert_session
->fieldValueEquals('created[0][value][time]', '07:00:37');
$this
->getSession()
->getPage()
->clickLink('red.jpeg');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertMedia4FieldValues();
$this
->assertMedia5FieldValues();
$this
->assertMedia6FieldValues();
$this
->drupalGet('media/6/edit');
$assert_session
->statusCodeEquals(200);
$this
->assertPageTitle('Edit Document LICENSE.txt');
$assert_session
->hiddenFieldValueEquals('field_media_document[0][fids]', '6');
$assert_session
->fieldValueEquals('uid[0][target_id]', 'user (1)');
$assert_session
->fieldValueEquals('created[0][value][date]', '2020-04-24');
$assert_session
->fieldValueEquals('created[0][value][time]', '08:25:11');
$this
->getSession()
->getPage()
->clickLink('LICENSE.txt');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertMedia7FieldValues();
$this
->drupalGet('media/7/edit');
$assert_session
->statusCodeEquals(200);
$this
->assertPageTitle('Edit Image yellow.jpg');
$assert_session
->hiddenFieldValueEquals('field_media_image[0][fids]', '7');
$assert_session
->fieldValueEquals('field_media_image[0][alt]', '');
$assert_session
->fieldValueEquals('field_media_image[0][title]', '');
$assert_session
->fieldValueEquals('field_media_integer[0][value]', '');
$assert_session
->fieldNotExists('field_file_image_alt_text[0][value]');
$assert_session
->fieldNotExists('field_file_image_title_text[0][value]');
$assert_session
->fieldValueEquals('uid[0][target_id]', 'editor (2)');
$assert_session
->fieldValueEquals('created[0][value][date]', '2020-05-04');
$assert_session
->fieldValueEquals('created[0][value][time]', '09:53:55');
$this
->getSession()
->getPage()
->clickLink('yellow.jpg');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertMedia8FieldValues();
$this
->assertMedia9FieldValues();
$this
->assertMedia10FieldValues();
$this
->assertMedia11FieldValues();
$this
->assertMedia12FieldValues();
$this
->assertNode1FieldValues();
$this
->drupalGet('/media/add/image');
$this
->submitForm([
'name[0][value]' => 'New media',
'files[field_media_image_0]' => \Drupal::service('file_system')
->realpath($this
->getTestFiles('image')[0]->uri),
], 'Save');
$this
->assertSession()
->pageTextNotContains('The file could not be uploaded because the destination');
$this
->assertSession()
->pageTextContains('Image New media has been created.');
}
public function providerTestMediaMigrate() {
$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;
}
}