function MediaLibraryTest::testAllowedMediaTypes
Same name and namespace in other branches
- 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testAllowedMediaTypes()
- 9 core/modules/ckeditor/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\MediaLibraryTest::testAllowedMediaTypes()
- 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testAllowedMediaTypes()
Tests the allowed media types setting on the MediaEmbed filter.
File
-
core/
modules/ ckeditor5/ tests/ src/ FunctionalJavascript/ MediaLibraryTest.php, line 229
Class
- MediaLibraryTest
- @coversDefaultClass <a href="/api/drupal/core%21modules%21ckeditor5%21src%21Plugin%21CKEditor5Plugin%21MediaLibrary.php/class/MediaLibrary/11.x" title="CKEditor 5 Media Library plugin." class="local">\Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary</a> @group ckeditor5 @internal
Namespace
Drupal\Tests\ckeditor5\FunctionalJavascriptCode
public function testAllowedMediaTypes() : void {
$test_cases = [
'all_media_types' => [],
'only_image' => [
'image' => 'image',
],
'only_arrakis' => [
'arrakis' => 'arrakis',
],
'both_items_checked' => [
'image' => 'image',
'arrakis' => 'arrakis',
],
];
foreach ($test_cases as $allowed_media_types) {
// Update the filter format to set the allowed media types.
FilterFormat::load('test_format')->setFilterConfig('media_embed', [
'status' => TRUE,
'settings' => [
'allowed_media_types' => $allowed_media_types,
],
])
->save();
// Now test opening the media library from the CKEditor plugin, and
// verify the expected behavior.
$this->drupalGet('/node/add/blog');
$this->waitForEditor();
$this->pressEditorButton('Insert Media');
$assert_session = $this->assertSession();
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-modal #media-library-wrapper'));
if (empty($allowed_media_types) || count($allowed_media_types) === 2) {
$menu = $assert_session->elementExists('css', '.js-media-library-menu');
$assert_session->elementExists('named', [
'link',
'Image',
], $menu);
$assert_session->elementExists('named', [
'link',
'Arrakis',
], $menu);
$assert_session->elementTextContains('css', '.js-media-library-item', 'Fear is the mind-killer');
}
elseif (count($allowed_media_types) === 1 && !empty($allowed_media_types['image'])) {
// No tabs should appear if there's only one media type available.
$assert_session->elementNotExists('css', '.js-media-library-menu');
$assert_session->elementTextContains('css', '.js-media-library-item', 'Fear is the mind-killer');
}
elseif (count($allowed_media_types) === 1 && !empty($allowed_media_types['arrakis'])) {
// No tabs should appear if there's only one media type available.
$assert_session->elementNotExists('css', '.js-media-library-menu');
$assert_session->elementTextContains('css', '.js-media-library-item', 'Le baron Vladimir Harkonnen');
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.