function MediaLibraryTest::testButton

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testButton()
  2. 9 core/modules/ckeditor/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\MediaLibraryTest::testButton()
  3. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testButton()

Tests using drupalMedia button to embed media into CKEditor 5.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php, line 158

Class

MediaLibraryTest
@coversDefaultClass \Drupal\ckeditor5\Plugin\CKEditor5Plugin\MediaLibrary @group ckeditor5 @internal

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testButton() : void {
    // Skipped due to frequent random test failures.
    // @todo Fix this and stop skipping it at https://www.drupal.org/i/3351597.
    $this->markTestSkipped();
    $media_preview_selector = '.ck-content .ck-widget.drupal-media .media';
    $this->drupalGet('/node/add/blog');
    $this->waitForEditor();
    $this->pressEditorButton('Insert Media');
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-modal #media-library-content'));
    // Ensure that the tab order is correct.
    $tabs = $page->findAll('css', '.media-library-menu__link');
    $expected_tab_order = [
        'Show Image media (selected)',
        'Show Arrakis media',
    ];
    foreach ($tabs as $key => $tab) {
        $this->assertSame($expected_tab_order[$key], $tab->getText());
    }
    $assert_session->pageTextContains('0 of 1 item selected');
    $assert_session->elementExists('css', '.js-media-library-item')
        ->click();
    $assert_session->pageTextContains('1 of 1 item selected');
    $assert_session->elementExists('css', '.ui-dialog-buttonpane')
        ->pressButton('Insert selected');
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', $media_preview_selector, 1000));
    $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $drupal_media = $xpath->query('//drupal-media')[0];
    $expected_attributes = [
        'data-entity-type' => 'media',
        'data-entity-uuid' => $this->media
            ->uuid(),
    ];
    foreach ($expected_attributes as $name => $expected) {
        $this->assertSame($expected, $drupal_media->getAttribute($name));
    }
    $this->assertEditorButtonEnabled('Undo');
    $this->pressEditorButton('Undo');
    $this->assertEmpty($assert_session->waitForElementVisible('css', $media_preview_selector, 1000));
    $this->assertEditorButtonDisabled('Undo');
    $this->pressEditorButton('Redo');
    $this->assertEditorButtonEnabled('Undo');
    // Ensure that data-align attribute is set by default when media is inserted
    // while filter_align is enabled.
    FilterFormat::load('test_format')->setFilterConfig('filter_align', [
        'status' => TRUE,
    ])
        ->save();
    $this->drupalGet('/node/add/blog');
    $this->waitForEditor();
    $this->pressEditorButton('Insert Media');
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-modal #media-library-content'));
    $assert_session->elementExists('css', '.js-media-library-item')
        ->click();
    $assert_session->elementExists('css', '.ui-dialog-buttonpane')
        ->pressButton('Insert selected');
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', $media_preview_selector, 1000));
    $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $drupal_media = $xpath->query('//drupal-media')[0];
    $expected_attributes = [
        'data-entity-type' => 'media',
        'data-entity-uuid' => $this->media
            ->uuid(),
    ];
    foreach ($expected_attributes as $name => $expected) {
        $this->assertSame($expected, $drupal_media->getAttribute($name));
    }
    // Ensure that by default, data-align attribute is not set.
    $this->assertFalse($drupal_media->hasAttribute('data-align'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.