+ /**
+ * Tests the redirect URL after creating a media item.
+ */
+ 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()
+ ->execute();
+ $media_id = reset($media_id);
+ $assert_session->addressEquals('media/' . $media_id);
+
+ // 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');
+ }
+