function EmphasisTest::testEmphasisArbitraryHtml

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\EmphasisTest::testEmphasisArbitraryHtml()
  2. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\EmphasisTest::testEmphasisArbitraryHtml()

Tests that arbitrary attributes are allowed via GHS.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php, line 142

Class

EmphasisTest
Tests emphasis in CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testEmphasisArbitraryHtml() : void {
    $assert_session = $this->assertSession();
    $editor = Editor::load('test_format');
    $settings = $editor->getSettings();
    // Allow the data-foo attribute in img via GHS.
    $settings['plugins']['ckeditor5_sourceEditing']['allowed_tags'] = [
        '<em data-foo>',
    ];
    $editor->setSettings($settings);
    $editor->save();
    // Add data-foo use to an existing em tag.
    $original_value = $this->host->body->value;
    $this->host->body->value = str_replace('<em>', '<em data-foo="bar">', $original_value);
    $this->host
        ->save();
    $this->drupalGet($this->host
        ->toUrl('edit-form'));
    $this->waitForEditor();
    $emphasis_element = $assert_session->waitForElementVisible('css', '.ck-content p em');
    $this->assertEquals('bar', $emphasis_element->getAttribute('data-foo'));
    $xpath = new \DOMXPath($this->getEditorDataAsDom());
    $this->assertNotEmpty($xpath->query('//em[@data-foo="bar"]'));
}

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