You are here

public function ContentModerationTest::testWidget in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php \Drupal\Tests\media_library\FunctionalJavascript\ContentModerationTest::testWidget()

Tests the media library widget only shows published media.

File

core/modules/media_library/tests/src/FunctionalJavascript/ContentModerationTest.php, line 249

Class

ContentModerationTest
Tests media library integration with content moderation.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

public function testWidget() {
  $assert_session = $this
    ->assertSession();

  // All users should only be able to see published media items.
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userAdmin);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewer);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewOwnUnpublished);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewAnyUnpublished);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();

  // After we change the owner to the user with 'view own unpublished media'
  // permission, all users should still only be able to see published media.
  foreach (Media::loadMultiple() as $media) {
    $media
      ->setOwner($this->userViewOwnUnpublished);
    $media
      ->save();
  }
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userAdmin);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewer);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewOwnUnpublished);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
  $this
    ->drupalLogin($this->userViewAnyUnpublished);
  $this
    ->drupalGet('node/add/article');
  $assert_session
    ->elementExists('css', '.js-media-library-open-button[name^="field_media"]')
    ->click();
  $assert_session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertOnlyPublishedMedia();
}