function CKEditor5MarkupTest::testComments

Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5MarkupTest::testComments()

Ensures that HTML comments are preserved in CKEditor 5.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php, line 154

Class

CKEditor5MarkupTest
Tests for CKEditor 5.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testComments() : void {
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    // Add a node with text rendered via the Plain Text format.
    $this->drupalGet('node/add');
    $page->fillField('title[0][value]', 'My test content');
    $page->fillField('body[0][value]', '<!-- Hamsters, alpacas, llamas, and kittens are cute! --><p>This is a <em>test!</em></p>');
    $page->pressButton('Save');
    FilterFormat::create([
        'format' => 'ckeditor5',
        'name' => 'CKEditor 5 HTML comments test',
        'roles' => [
            RoleInterface::AUTHENTICATED_ID,
        ],
    ])->save();
    Editor::create([
        'format' => 'ckeditor5',
        'editor' => 'ckeditor5',
        'image_upload' => [
            'status' => FALSE,
        ],
    ])->save();
    $this->assertSame([], array_map(function (ConstraintViolationInterface $v) {
        return (string) $v->getMessage();
    }, iterator_to_array(CKEditor5::validatePair(Editor::load('ckeditor5'), FilterFormat::load('ckeditor5')))));
    $this->drupalGet('node/1/edit');
    $page->selectFieldOption('body[0][format]', 'ckeditor5');
    $this->assertNotEmpty($assert_session->waitForText('Change text format?'));
    $page->pressButton('Continue');
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ck-editor'));
    $page->pressButton('Save');
    $assert_session->responseContains('<!-- Hamsters, alpacas, llamas, and kittens are cute! --><p>This is a <em>test!</em></p>');
}

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