function MediaUiFunctionalTest::testMediaCreateRedirect

Same name in other branches
  1. 9 core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCreateRedirect()
  2. 8.9.x core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php \Drupal\Tests\media\Functional\MediaUiFunctionalTest::testMediaCreateRedirect()
  3. 11.x 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 204

Class

MediaUiFunctionalTest
Ensures that media UI works correctly.

Namespace

Drupal\Tests\media\Functional

Code

public function testMediaCreateRedirect() : void {
    $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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.