function MediaLibraryTestBase::assertMediaAdded

Same name in other branches
  1. 9 core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::assertMediaAdded()
  2. 8.9.x core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::assertMediaAdded()
  3. 11.x core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php \Drupal\Tests\media_library\FunctionalJavascript\MediaLibraryTestBase::assertMediaAdded()

Asserts a media item was added, but not yet saved.

Parameters

int $index: (optional) The index of the media item, if multiple items can be added at once. Defaults to 0.

5 calls to MediaLibraryTestBase::assertMediaAdded()
WidgetOEmbedTest::testWidgetOEmbed in core/modules/media_library/tests/src/FunctionalJavascript/WidgetOEmbedTest.php
Tests that oEmbed media can be added in the Media library's widget.
WidgetOEmbedTest::testWidgetOEmbedAdvancedUi in core/modules/media_library/tests/src/FunctionalJavascript/WidgetOEmbedTest.php
Tests that oEmbed media can be added in the widget's advanced UI.
WidgetOverflowTest::uploadFiles in core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php
Uploads multiple test images into the media library.
WidgetUploadTest::testWidgetUpload in core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
Tests that uploads in the 'media_library_widget' works as expected.
WidgetUploadTest::testWidgetUploadAdvancedUi in core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php
Tests that uploads in the widget's advanced UI works as expected.

File

core/modules/media_library/tests/src/FunctionalJavascript/MediaLibraryTestBase.php, line 320

Class

MediaLibraryTestBase
Base class for functional tests of Media Library functionality.

Namespace

Drupal\Tests\media_library\FunctionalJavascript

Code

protected function assertMediaAdded($index = 0) {
    $selector = '.js-media-library-add-form-added-media';
    // Assert that focus is shifted to the new media items.
    $this->assertJsCondition('jQuery("' . $selector . '").is(":focus")');
    $assert_session = $this->assertSession();
    $assert_session->pageTextMatches('/The media items? ha(s|ve) been created but ha(s|ve) not yet been saved. Fill in any required fields and save to add (it|them) to the media library./');
    $assert_session->elementAttributeContains('css', $selector, 'aria-label', 'Added media items');
    $fields = $this->assertElementExistsAfterWait('css', '[data-drupal-selector="edit-media-' . $index . '-fields"]');
    $assert_session->elementNotExists('css', '.js-media-library-menu');
    // Assert extraneous components were removed in
    // FileUploadForm::hideExtraSourceFieldComponents().
    $assert_session->elementNotExists('css', '[data-drupal-selector$="preview"]', $fields);
    $assert_session->buttonNotExists('Remove', $fields);
    $assert_session->elementNotExists('css', '[data-drupal-selector$="filename"]', $fields);
}

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