function ContentModerationTest::testAdministrationPage

Same name in other branches
  1. 8.9.x core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php \Drupal\Tests\media_library\FunctionalJavascript\ContentModerationTest::testAdministrationPage()
  2. 10 core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php \Drupal\Tests\media_library\FunctionalJavascript\ContentModerationTest::testAdministrationPage()
  3. 11.x 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\FunctionalJavascript

Code

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();
}

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