You are here

public function WidgetAnonymousTest::testWidgetAnonymous in Drupal 8

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

Tests that the widget works as expected for anonymous users.

File

core/modules/media_library/tests/src/FunctionalJavascript/WidgetAnonymousTest.php, line 40

Class

WidgetAnonymousTest
Tests that the widget works as expected for anonymous users.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

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

  // Allow the anonymous user to create pages and view media.
  $role = Role::load(RoleInterface::ANONYMOUS_ID);
  $this
    ->grantPermissions($role, [
    'access content',
    'create basic_page content',
    'view media',
  ]);

  // Ensure the widget works as an anonymous user.
  $this
    ->drupalGet('node/add/basic_page');

  // Add to the unlimited cardinality field.
  $this
    ->openMediaLibraryForField('field_unlimited_media');

  // Select the first media item (should be Dog).
  $this
    ->selectMediaItem(0);
  $this
    ->pressInsertSelected('Added one media item.');

  // Ensure that the selection completed successfully.
  $this
    ->waitForText('Dog');

  // Save the form.
  $assert_session
    ->elementExists('css', '.js-media-library-widget-toggle-weight')
    ->click();
  $this
    ->submitForm([
    'title[0][value]' => 'My page',
    'field_unlimited_media[selection][0][weight]' => '0',
  ], 'Save');
  $assert_session
    ->pageTextContains('Basic Page My page has been created');
  $assert_session
    ->pageTextContains('Dog');
}