$page = $session->getPage();
$assert_session = $this->assertSession();
- $media_type = $this->createMediaType([
- 'new_revision' => FALSE,
+ $media_type = $this->createMediaType('test', [
'queue_thumbnail_downloads' => FALSE,
]);
$source_field = $this->randomString();
$page->fillField('field_media_test[0][value]', $source_field);
$page->pressButton('Save');
- $media_id = $this->container->get('entity.query')->get('media')->execute();
+ $media_id = $this->container->get('entity_type.manager')
+ ->getStorage('media')
+ ->getQuery()
+ ->execute();
$media_id = reset($media_id);
/** @var \Drupal\media\MediaInterface $media */
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
- $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message);
- $this->assertEquals($media->getName(), $media_name);
+ $this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
+ $this->assertSame($media->getName(), $media_name);
+ $this->drupalGet('media/' . $media_id);
$assert_session->titleEquals($media_name . ' | Drupal');
// Tests media edit form.
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
- $this->assertEquals($media->getName(), $media_name2);
+ $this->assertSame($media->getName(), $media_name2);
+ $this->drupalGet('media/' . $media_id);
$assert_session->titleEquals($media_name2 . ' | Drupal');
// Test that there is no empty vertical tabs element, if the container is
$page->fillField('name[0][value]', $media_name);
$page->fillField('revision_log_message[0][value]', $revision_log_message);
$page->pressButton('Save');
+ $this->drupalGet('media/' . $media_id);
$assert_session->titleEquals($media_name . ' | Drupal');
/** @var \Drupal\media\MediaInterface $media */
$media = $this->container->get('entity_type.manager')
->getStorage('media')
->loadUnchanged($media_id);
- $this->assertEquals($media->getRevisionLogMessage(), $revision_log_message);
+ $this->assertSame($media->getRevisionLogMessage(), $revision_log_message);
$this->assertNotEquals($previous_revision_id, $media->getRevisionId());
// Test the status checkbox.
$assert_session = $this->assertSession();
// Tests and creates the first media type.
- $first_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]);
+ $first_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
// Test and create a second media type.
- $second_media_type = $this->createMediaType(['description' => $this->randomMachineName(32)]);
+ $second_media_type = $this->createMediaType('test', ['description' => $this->randomMachineName()]);
// Test if media/add displays two media type options.
$this->drupalGet('media/add');
$this->drupalGet('media/' . $first_media_item->id());
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains($first_media_item->getName());
+ $assert_session->elementsCount('css', '.media--view-mode-full', 1);
// Go to second media item.
$this->drupalGet('media/' . $second_media_item->id());
$create_media_types[] = "media_type_$id";
$permissions[] = "create media_type_$id media";
}
- $this->createMediaType(['bundle' => "media_type_$id"]);
+ $this->createMediaType('test', [
+ 'id' => "media_type_$id",
+ 'label' => "media_type_$id",
+ ]);
$media_types["media_type_$id"] = "media_type_$id";
}
}
}
+ /**
+ * 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');
+ }
+
/**
* Asserts that the given texts are present exactly once.
*
$this->assertNotEmpty($link);
foreach ($attributes as $attribute => $value) {
- $this->assertEquals($link->getAttribute($attribute), $value);
+ $this->assertSame($link->getAttribute($attribute), $value);
}
}
$this->container->get('module_installer')->uninstall(['views']);
// Create a media type and media item.
- $media_type = $this->createMediaType();
+ $media_type = $this->createMediaType('test');
$media = $media_storage->create([
'bundle' => $media_type->id(),
'name' => 'Unnamed',