function MediaLibraryTest::testAllowedMediaTypes

Same name in this branch
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testAllowedMediaTypes()
Same name and namespace in other branches
  1. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testAllowedMediaTypes()
  2. 11.x 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/ckeditor/tests/src/FunctionalJavascript/MediaLibraryTest.php, line 275

Class

MediaLibraryTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21ckeditor%21src%21Plugin%21CKEditorPlugin%21DrupalMediaLibrary.php/class/DrupalMediaLibrary/9" title="Defines the &quot;drupalmedialibrary&quot; plugin." class="local">\Drupal\ckeditor\Plugin\CKEditorPlugin\DrupalMediaLibrary</a> @group ckeditor @group legacy

Namespace

Drupal\Tests\ckeditor\FunctionalJavascript

Code

public function testAllowedMediaTypes() {
    $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' => [
                'default_view_mode' => 'view_mode_1',
                'allowed_media_types' => $allowed_media_types,
                'allowed_view_modes' => [
                    'view_mode_1' => 'view_mode_1',
                    'view_mode_2' => 'view_mode_2',
                ],
            ],
        ])
            ->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('drupalmedialibrary');
        $assert_session = $this->assertSession();
        $this->assertNotEmpty($assert_session->waitForId('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.