public function ContentModerationTest::testAdministrationPage in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php \Drupal\Tests\media_library\FunctionalJavascript\ContentModerationTest::testAdministrationPage()
- 10 core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php \Drupal\Tests\media_library\FunctionalJavascript\ContentModerationTest::testAdministrationPage()
Tests the media library widget only shows published media.
File
- core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ ContentModerationTest.php, line 179
Class
- ContentModerationTest
- Tests media library integration with content moderation.
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
public function testAdministrationPage() {
// User 1 should be able to see all media items.
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// The media admin user should be able to see all media items.
$this
->drupalLogin($this->userAdmin);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// The media viewer user should be able to see only published media items.
$this
->drupalLogin($this->userViewer);
$this
->drupalGet('admin/content/media');
$this
->assertOnlyPublishedMedia();
// The media viewer user that can also view its own unpublished media should
// also be able to see only published media items since it is not the owner
// of the created media items.
$this
->drupalLogin($this->userViewOwnUnpublished);
$this
->drupalGet('admin/content/media');
$this
->assertOnlyPublishedMedia();
// When content moderation is enabled, a media viewer that can view any
// unpublished content should be able to see all media.
// @see content_moderation_entity_access()
$this
->drupalLogin($this->userViewAnyUnpublished);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// Assign all media to the user with the 'view own unpublished media'
// permission.
foreach (Media::loadMultiple() as $media) {
$media
->setOwner($this->userViewOwnUnpublished);
$media
->save();
}
// User 1 should still be able to see all media items.
$this
->drupalLogin($this->rootUser);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// The media admin user should still be able to see all media items.
$this
->drupalLogin($this->userAdmin);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// The media viewer user should still be able to see only published media
// items.
$this
->drupalLogin($this->userViewer);
$this
->drupalGet('admin/content/media');
$this
->assertOnlyPublishedMedia();
// The media viewer user that can also view its own unpublished media
// should now be able to see all media items since it is the owner of the
// created media items.
$this
->drupalLogin($this->userViewOwnUnpublished);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
// The media viewer that can view any unpublished content should still be
// able to see all media.
$this
->drupalLogin($this->userViewAnyUnpublished);
$this
->drupalGet('admin/content/media');
$this
->assertAllMedia();
}