/**
* Waits for a file field to exist before uploading.
*/ publicfunctionaddMediaFileToField($locator, $path){ $page = $this->getSession()->getPage(); $this->waitForFieldExists($locator); $page->attachFileToField($locator, $path); }
/**
* Clicks "Save and select||insert" button and waits for AJAX completion.
*
* @param string $operation
* The final word of the button to be clicked.
*/ protectedfunctionsaveAnd($operation){ $this->assertElementExistsAfterWait('css', '.ui-dialog-buttonpane')->pressButton("Save and $operation");
$assert_session->pageTextNotContains('Cat'); // For reasons that are not clear, deleting media items by pressing the
// "Delete" button can fail (the button is found, but never actually pressed
// by the Mink driver). This workaround allows the delete form to be
// submitted.
$assert_session->elementExists('css', 'form')->submit(); $assert_session->pageTextNotContains('Dog'); $assert_session->pageTextContains('Cat');
// Test the 'Select all media' checkbox and assert that it makes the
// expected announcements.
$select_all = $this->waitForFieldExists('Select all media'); $select_all->check(); $this->waitForText('All 7 items selected'); $select_all->uncheck(); $this->waitForText('Zero items selected'); $select_all->check(); $page->selectFieldOption('Action', 'media_delete_action'); $this->submitForm([], 'Apply to selected items'); // For reasons that are not clear, deleting media items by pressing the
// "Delete" button can fail (the button is found, but never actually pressed
// by the Mink driver). This workaround allows the delete form to be
// submitted.
// Remove the item.
$assert_session->elementTextContains('css', '.field--name-field-twin-media', $png_image->filename); $assert_session->elementExists('css', '.field--name-field-twin-media')->pressButton('Remove'); $this->waitForElementTextContains('#drupal-live-announce', $png_image->filename . ' has been removed'); $assert_session->elementTextNotContains('css', '.field--name-field-twin-media', $png_image->filename);
// Also make sure that we can upload to the unlimited cardinality field.
$this->openMediaLibraryForField('field_unlimited_media'); $this->switchToMediaType('Three');
// Select a media item to check if the selection is persisted when adding
// new items.
$existing_media_name = $file_system->basename($png_uri_2);