function CKEditor5CodeSyntaxTest::testCKEditor5CodeSyntax

Tests code block configured languages are respected.

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5CodeSyntaxTest.php, line 24

Class

CKEditor5CodeSyntaxTest
Tests code block configured languages are respected.

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript

Code

public function testCKEditor5CodeSyntax() : void {
    $this->addNewTextFormat();
    
    /** @var \Drupal\editor\Entity\Editor $editor */
    $editor = Editor::load('ckeditor5');
    $editor->setSettings([
        'toolbar' => [
            'items' => [
                'codeBlock',
            ],
        ],
        'plugins' => [
            'ckeditor5_codeBlock' => [
                'languages' => [
                    [
                        'label' => 'Twig',
                        'language' => 'twig',
                    ],
                    [
                        'label' => 'YML',
                        'language' => 'yml',
                    ],
                ],
            ],
        ],
    ])
        ->save();
    $this->drupalGet('/node/add/page');
    $this->waitForEditor();
    // Open code block dropdown, and verify that correct languages are present.
    $assertSession = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $page->find('css', '.ck-code-block-dropdown .ck-dropdown__button .ck-splitbutton__arrow')
        ->click();
    $codeBlockOptionsSelector = '.ck-code-block-dropdown .ck-dropdown__panel .ck-list__item .ck-button__label';
    $assertSession->waitForElementVisible('css', $codeBlockOptionsSelector);
    $codeBlockOptions = $page->findAll('css', $codeBlockOptionsSelector);
    $this->assertCount(2, $codeBlockOptions);
    $this->assertEquals([
        'Twig',
        'YML',
    ], \array_map(static fn(NodeElement $el) => $el->getText(), $codeBlockOptions));
}

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