You are here

public function BasicCreationTest::testMediaBundleCreation in Media entity 8

Tests creating a media bundle programmatically.

File

tests/src/Kernel/BasicCreationTest.php, line 68

Class

BasicCreationTest
Tests creation of Media Bundles and Media Entities.

Namespace

Drupal\Tests\media_entity\Kernel

Code

public function testMediaBundleCreation() {

  /** @var \Drupal\media_entity\MediaBundleInterface $bundle_storage */
  $bundle_storage = $this->container
    ->get('entity_type.manager')
    ->getStorage('media_bundle');
  $bundle_exists = (bool) $bundle_storage
    ->load($this->testBundle
    ->id());
  $this
    ->assertTrue($bundle_exists, 'The new media bundle has not been correctly created in the database.');

  // Test default bundle created from default configuration.
  $this->container
    ->get('module_installer')
    ->install([
    'media_entity_test_bundle',
  ]);
  $test_bundle = $bundle_storage
    ->load('test');
  $this
    ->assertTrue((bool) $test_bundle, 'The media bundle from default configuration has not been created in the database.');
  $this
    ->assertEquals($test_bundle
    ->get('label'), 'Test bundle', 'Could not assure the correct bundle label.');
  $this
    ->assertEquals($test_bundle
    ->get('description'), 'Test bundle.', 'Could not assure the correct bundle description.');
  $this
    ->assertEquals($test_bundle
    ->get('type'), 'generic', 'Could not assure the correct bundle plugin type.');
  $this
    ->assertEquals($test_bundle
    ->get('type_configuration'), [], 'Could not assure the correct plugin configuration.');
  $this
    ->assertEquals($test_bundle
    ->get('field_map'), [], 'Could not assure the correct field map.');
}