protected function SingleItemTest::insertMediaItem in Media Library Form API Element 2.x
Parameters
string $selector_type: The css selector of the media library form element to test.
string $selector: The css selector of the media library form element to test.
string $bundle: The bundle of the media item to insert.
int $index: The index of the media item to insert.
1 call to SingleItemTest::insertMediaItem()
- SingleItemTest::testForm in tests/
src/ FunctionalJavascript/ SingleItemTest.php - Tests the setting form.
File
- tests/
src/ FunctionalJavascript/ SingleItemTest.php, line 197
Class
- SingleItemTest
- Test using the media library element.
Namespace
Drupal\Tests\media_library_form_element\FunctionalJavascriptCode
protected function insertMediaItem($selector_type, $selector, $bundle, $index) {
$assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$media_type = MediaType::load($bundle);
$media_type_label = $media_type
->label();
// Open the media library.
$assert
->elementExists($selector_type, $selector)
->press();
// Wait for the media library to open.
$assert
->assertWaitOnAjaxRequest();
// Select the proper bundle from the menu (if it exists).
if ($page
->hasLink($media_type_label)) {
$page
->clickLink($media_type_label);
$assert
->assertWaitOnAjaxRequest();
}
// Select the item.
$page
->find('css', 'input[name="media_library_select_form[' . $index . ']"]')
->setValue('1');
$assert
->assertWaitOnAjaxRequest();
$assert
->checkboxChecked('media_library_select_form[' . $index . ']');
// Insert the item.
$insert_button = $page
->find('css', '.ui-dialog-buttonset .form-submit');
$insert_button
->press();
$assert
->assertWaitOnAjaxRequest();
}