public function CoreMediaUpdatePath8dot7Test::testUpdatePath in Media entity 8.2
Tests the media_entity to media update.
File
- tests/
src/ Functional/ CoreMediaUpdatePath8dot7Test.php, line 37
Class
- CoreMediaUpdatePath8dot7Test
- Tests the media_entity to media update.
Namespace
Drupal\Tests\media_entity\FunctionalCode
public function testUpdatePath() {
$icon_base_uri = $this
->config('media_entity.settings')
->get('icon_base');
$this
->runUpdates();
$assert = $this
->assertSession();
// Ensure the full view mode was created.
$view_mode_storage = $this->container
->get('entity_type.manager')
->getStorage('entity_view_mode');
$this
->assertNotNull($view_mode_storage
->load('media.full'));
// As with all translatable, versionable content entity types, media
// entities should have the revision_translation_affected base field.
// This may have been created during the update path by system_update_8402,
// so we should check for it here.
/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $field_manager */
$field_manager = $this->container
->get('entity_field.manager');
$this
->assertArrayHasKey('revision_translation_affected', $field_manager
->getBaseFieldDefinitions('media'));
// Ensure that media fields that were created during module install are
// deleted properly.
$base_field_definitions = $field_manager
->getBaseFieldDefinitions('media');
$field_map = $field_manager
->getFieldMap();
$this
->assertArrayNotHasKey('field_media_document', $base_field_definitions);
$this
->assertArrayNotHasKey('field_media_document', $field_map['media']);
$this
->assertArrayNotHasKey('field_media_oembed_video', $base_field_definitions);
$this
->assertArrayNotHasKey('field_media_oembed_video', $field_map['media']);
$this
->assertArrayNotHasKey('field_media_video_file', $base_field_definitions);
$this
->assertArrayNotHasKey('field_media_video_file', $field_map['media']);
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('/admin/modules');
$assert
->checkboxNotChecked('modules[media_entity_document][enable]');
$assert
->checkboxNotChecked('modules[media_entity_image][enable]');
$assert
->checkboxNotChecked('modules[media_entity][enable]');
$assert
->checkboxChecked('modules[media_entity_generic][enable]');
$this
->assertArrayHasKey('media', $this
->config('core.extension')
->get('module'));
$this
->drupalGet('/admin/structure/media/manage/document');
$assert
->statusCodeEquals(200);
$assert
->fieldValueEquals('source', 'generic');
$assert
->pageTextContains('Generic media field is used to store the essential information');
// Assert that Media Entity's config is migrated.
$this
->assertTrue($this
->config('media_entity.settings')
->isNew());
$this
->assertEquals($icon_base_uri, $this
->config('media.settings')
->get('icon_base_uri'));
$this
->assertEmpty($this->container
->get('config.factory')
->listAll('media_entity.bundle'));
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container
->get('entity_type.manager')
->getStorage('media_type');
foreach ([
'document',
] as $type) {
$config = $this
->config("media.type.{$type}");
$this
->assertFalse($config
->isNew());
$this
->assertNull($config
->get('type'));
$this
->assertNull($config
->get('type_configuration'));
$this
->assertInternalType('string', $config
->get('source'));
$this
->assertInternalType('array', $config
->get('source_configuration'));
$this
->assertInternalType('string', $config
->get('source_configuration.source_field'));
// Ensure that the media type can be queried by UUID.
$uuid = $config
->get('uuid');
$this
->assertNotEmpty($uuid);
$result = $storage
->getQuery()
->condition('uuid', $uuid)
->execute();
$this
->assertEquals($result[$type], $type);
}
// The UUID map for legacy media bundles should be cleared out.
$old_uuid_map = $this->container
->get('keyvalue')
->get(QueryFactory::CONFIG_LOOKUP_PREFIX . 'media_bundle')
->getAll();
$this
->assertEmpty($old_uuid_map);
}