protected function SingleItemTest::assertAllowedBundles in Media Library Form API Element 2.x
Asserts that only allowed entities are listed in the widget.
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.
array $allowed_bundles: The bundles that are allowed for the element to test.
1 call to SingleItemTest::assertAllowedBundles()
- SingleItemTest::testForm in tests/
src/ FunctionalJavascript/ SingleItemTest.php - Tests the setting form.
File
- tests/
src/ FunctionalJavascript/ SingleItemTest.php, line 115
Class
- SingleItemTest
- Test using the media library element.
Namespace
Drupal\Tests\media_library_form_element\FunctionalJavascriptCode
protected function assertAllowedBundles($selector_type, $selector, array $allowed_bundles) {
$assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
// Open the media library.
$assert
->elementExists($selector_type, $selector)
->press();
// Wait for the media library to open.
$assert
->assertWaitOnAjaxRequest();
// Make sure that the bundle menu works as intended.
if (count($allowed_bundles) === 1) {
// If a single bundle is allowed, the menu shouldn't be displayed.
$assert
->elementNotExists('css', '.media-library-menu');
}
else {
// Make sure that the proper menu items appear.
foreach (static::FIXTURES as $bundle => $entities) {
$media_type = MediaType::load($bundle);
$media_type_label = $media_type
->label();
if (in_array($bundle, $allowed_bundles, TRUE)) {
// If the bundle is allowed, it should be contained in the menu.
$assert
->elementTextContains('css', '.media-library-menu', $media_type_label);
// Switch to the proper bundle.
$page
->clickLink($media_type_label);
// Wait for the new entities to load in.
$assert
->assertWaitOnAjaxRequest();
// Make sure all the entities appear.
foreach ($entities as $entity) {
$assert
->linkExists($entity);
}
}
else {
// If the bundle is not allowed, it should not be contained in the menu.
$assert
->elementNotContains('css', '.media-library-menu', $media_type_label);
// If the bundle is not allowed, make sure none of the entities appear.
foreach ($entities as $entity) {
$assert
->linkNotExists($entity);
}
}
}
}
// Close out of the media library.
$assert
->elementExists('css', '.ui-dialog-titlebar-close')
->press();
}