protected function MediaMigrationAssertionsForMediaSourceTrait::assertMedia2FieldValues in Media Migration 8
Assertions of media 2.
Assert that the image that was the content of the field_image field of the test article with node ID 1 was migrated successfully, and make sure that its original alt and title properties from the image field are present.
5 calls to MediaMigrationAssertionsForMediaSourceTrait::assertMedia2FieldValues()
- DrushWithCoreMigrationsFromMediaTest::testAllMigrationWithDrush in tests/
src/ Functional/ DrushWithCoreMigrationsFromMediaTest.php - Test all migrations with Drush and Migrate Tools.
- DrushWithCoreMigrationsFromMediaTest::testMigrationWithDrush in tests/
src/ Functional/ DrushWithCoreMigrationsFromMediaTest.php - Test media migrations with Drush and Migrate Tools.
- DrushWithMigrateUpgradeFromMediaTest::testMigrationWithDrush in tests/
src/ Functional/ DrushWithMigrateUpgradeFromMediaTest.php - Tests migrations with Migrate Upgrade, Drush and Migrate Tools.
- MediaMigrationTest::testMediaMigration in tests/
src/ Kernel/ Migrate/ MediaMigrationTest.php - Tests the migration of media entities.
- MigrateMediaTest::testMediaMigrate in tests/
src/ Functional/ MigrateMediaTest.php - Tests the result of the media migration.
File
- tests/
src/ Traits/ MediaMigrationAssertionsForMediaSourceTrait.php, line 63
Class
- MediaMigrationAssertionsForMediaSourceTrait
- Trait for media migration tests.
Namespace
Drupal\Tests\media_migration\TraitsCode
protected function assertMedia2FieldValues() {
$media2 = $this->container
->get('entity_type.manager')
->getStorage('media')
->load(2);
assert($media2 instanceof MediaInterface);
$this
->assertEquals('green.jpg', $media2
->label());
$this
->assertEquals('image', $media2
->bundle());
// Check 'field media image' field.
$media2_image = $this
->getReferencedEntities($media2, 'field_media_image', 1);
assert($media2_image[0] instanceof FileInterface);
$this
->assertEquals('2', $media2_image[0]
->id());
$this
->assertEquals('2', $media2->field_media_image->target_id);
// Alt and title properties should be migrated to the corresponding media
// image field and have to be editable on the UI.
$this
->assertEquals('Alternate text for green.jpg image', $media2->field_media_image->alt);
$this
->assertEquals('Title text for green.jpg image', $media2->field_media_image->title);
$this
->assertEquals('', $media2->field_media_integer->value);
// The following fields should not be present.
$this
->assertFalse($media2
->hasField('field_file_image_alt_text'));
$this
->assertFalse($media2
->hasField('field_file_image_title_text'));
// Author should be user 1.
$this
->assertEquals('1', $media2
->getOwnerId());
// Assert authored on date.
$this
->assertEquals('1587730322', $media2
->getCreatedTime());
// The image file should exist.
$this
->assertTrue(file_exists($media2_image[0]
->getFileUri()));
}