You are here

protected function MediaLibraryWidgetTest::setUp in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/tests/src/Kernel/MediaLibraryWidgetTest.php \Drupal\Tests\media_library\Kernel\MediaLibraryWidgetTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/media_library/tests/src/Kernel/MediaLibraryWidgetTest.php, line 47

Class

MediaLibraryWidgetTest
Tests the media library widget.

Namespace

Drupal\Tests\media_library\Kernel

Code

protected function setUp() {
  parent::setUp();
  $this->baseField = BaseFieldDefinition::create('entity_reference')
    ->setName('media')
    ->setSetting('target_type', 'media')
    ->setSetting('handler_settings', [
    'target_bundles' => [
      'test_type' => 'test_type',
    ],
  ]);
  $this->container
    ->get('state')
    ->set('entity_test.additional_base_field_definitions', [
    'media' => $this->baseField,
  ]);
  $this->container
    ->get('state')
    ->set('entity_test_rev.additional_base_field_definitions', [
    'media' => $this->baseField,
  ]);
  $this
    ->installEntitySchema('entity_test');
  $this
    ->installEntitySchema('entity_test_rev');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('system', [
    'sequences',
    'key_value_expire',
  ]);
  $this
    ->installConfig([
    'system',
    'image',
    'media',
    'media_library',
  ]);
  MediaType::create([
    'id' => 'test_type',
    'label' => 'Test type',
    'source' => 'image',
  ])
    ->save();

  // Create user 1 so the test user doesn't bypass access control.
  $this
    ->createUser();
  $this->adminUser = $this
    ->createUser([
    'administer entity_test content',
    'view media',
  ]);
}