function WidgetOverflowTest::testWidgetOverflow
Same name in other branches
- 10 core/modules/media_library/tests/src/FunctionalJavascript/WidgetOverflowTest.php \Drupal\Tests\media_library\FunctionalJavascript\WidgetOverflowTest::testWidgetOverflow()
Tests that the Media Library constrains the number of selected items.
@dataProvider providerWidgetOverflow
Parameters
string|null $selected_operation: The operation of the button to click. For example, if this is "insert", the "Save and insert" button will be pressed. If NULL, the "Save" button will be pressed.
File
-
core/
modules/ media_library/ tests/ src/ FunctionalJavascript/ WidgetOverflowTest.php, line 101
Class
- WidgetOverflowTest
- Tests that uploads in the 'media_library_widget' works as expected.
Namespace
Drupal\Tests\media_library\FunctionalJavascriptCode
public function testWidgetOverflow(?string $selected_operation) : void {
// If we want to press the "Save and insert" or "Save and select" buttons,
// we need to enable the advanced UI.
if ($selected_operation) {
$this->config('media_library.settings')
->set('advanced_ui', TRUE)
->save();
}
$assert_session = $this->assertSession();
$page = $this->getSession()
->getPage();
$this->drupalGet('node/add/basic_page');
// Upload 5 files into a media field that only allows 2.
$this->openMediaLibraryForField('field_twin_media');
$this->uploadFiles(5);
// Save the media items and ensure that the user is warned that they have
// selected too many items.
if ($selected_operation) {
$this->saveAnd($selected_operation);
}
else {
$this->pressSaveButton();
}
$this->waitForElementTextContains('.messages--warning', 'There are currently 5 items selected. The maximum number of items for the field is 2. Remove 3 items from the selection.');
// If the user tries to insert the selected items anyway, they should get
// an error.
$this->pressInsertSelected(NULL, FALSE);
$this->waitForElementTextContains('.messages--error', 'There are currently 5 items selected. The maximum number of items for the field is 2. Remove 3 items from the selection.');
$assert_session->elementNotExists('css', '.messages--warning');
// Once the extra items are deselected, all should be well.
$this->deselectMediaItem(2);
$this->deselectMediaItem(3);
$this->deselectMediaItem(4);
$this->pressInsertSelected('Added 2 media items.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.