You are here

public function MediaUiFunctionalTest::testMediaCreateRedirect in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCreateRedirect()

Tests the redirect URL after creating a media item.

File

core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php, line 430

Class

MediaUiFunctionalTest
Ensures that media UI works correctly.

Namespace

Drupal\Tests\media\Functional

Code

public function testMediaCreateRedirect() {
  $session = $this
    ->getSession();
  $page = $session
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->createMediaType('test', [
    'queue_thumbnail_downloads' => FALSE,
  ]);

  // Test a redirect to the media canonical URL for a user without the 'access
  // media overview' permission.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'view media',
    'create media',
  ]));
  $this
    ->drupalGet('media/add');
  $page
    ->fillField('name[0][value]', $this
    ->randomMachineName());
  $page
    ->fillField('field_media_test[0][value]', $this
    ->randomString());
  $page
    ->pressButton('Save');
  $media_id = $this->container
    ->get('entity_type.manager')
    ->getStorage('media')
    ->getQuery()
    ->accessCheck(FALSE)
    ->execute();
  $media_id = reset($media_id);
  $assert_session
    ->addressEquals("media/{$media_id}/edit");

  // Test a redirect to the media overview for a user with the 'access media
  // overview' permission.
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'view media',
    'create media',
    'access media overview',
  ]));
  $this
    ->drupalGet('media/add');
  $page
    ->fillField('name[0][value]', $this
    ->randomMachineName());
  $page
    ->fillField('field_media_test[0][value]', $this
    ->randomString());
  $page
    ->pressButton('Save');
  $assert_session
    ->addressEquals('admin/content/media');
}