Verified Commit 2041dbb5 authored by Dave Long's avatar Dave Long
Browse files

Issue #3517023 by acbramley, mstrelan: Convert ckEditor5CodeSyntaxTest to WebDriver test

parent 4e42a4f9
Loading
Loading
Loading
Loading
Loading
+0 −240
Original line number Diff line number Diff line
@@ -12507,78 +12507,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/Functional/MediaEntityMetadataApiTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5DialogTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5DialogTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5DialogTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5DialogTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5MarkupTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5MarkupTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5MarkupTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5MarkupTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5MarkupTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5Test\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5Test\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5Test\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5Test\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\CKEditor5TestBase\\:\\:assertHtmlEsqueFieldValueEquals\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -12603,60 +12531,12 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5TestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\EmphasisTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\EmphasisTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\EmphasisTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\EmphasisTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/EmphasisTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestBase\\:\\:addImage\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestBase\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestBase\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestBase\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestBase\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\ImageTestProviderTest\\:\\:providerAlignment\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -12675,132 +12555,12 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/ImageUrlProviderTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaLibraryTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaLibraryTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaLibraryTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaLibraryTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaPreviewTest\\:\\:previewAccessProvider\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaPreviewTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaTestBase\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaTestBase\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaTestBase\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\MediaTestBase\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/MediaTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\SourceEditingTestBase\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\SourceEditingTestBase\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\SourceEditingTestBase\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\SourceEditingTestBase\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/SourceEditingTestBase.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\StyleTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\StyleTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\StyleTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\StyleTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/StyleTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\TableTest\\:\\:assertEditorButtonDisabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\TableTest\\:\\:assertEditorButtonEnabled\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\TableTest\\:\\:pressEditorButton\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\FunctionalJavascript\\\\TableTest\\:\\:waitForEditor\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/ckeditor5/tests/src/FunctionalJavascript/TableTest.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\Tests\\\\ckeditor5\\\\Kernel\\\\CKEditor5PluginManagerTest\\:\\:assertConfigSchema\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
+60 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\ckeditor5\FunctionalJavascript;

use Behat\Mink\Element\NodeElement;
use Drupal\editor\Entity\Editor;
use Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait;

/**
 * Tests code block configured languages are respected.
 *
 * @group ckeditor5
 * @internal
 */
class CKEditor5CodeSyntaxTest extends CKEditor5TestBase {

  use CKEditor5TestTrait;

  /**
   * Tests code block configured languages are respected.
   */
  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));
  }

}
+0 −157
Original line number Diff line number Diff line
// cspell:ignore sourceediting

module.exports = {
  '@tags': ['core', 'ckeditor5'],
  before(browser) {
    browser.drupalInstall({ installProfile: 'testing' });
  },
  after(browser) {
    browser.drupalUninstall();
  },
  'Verify code block configured languages are respected': (browser) => {
    browser.drupalLoginAsAdmin(() => {
      browser
        // Enable required modules.
        .drupalRelativeURL('/admin/modules')
        .click('[name="modules[ckeditor5][enable]"]')
        .click('[name="modules[node][enable]"]')
        .click('[name="modules[field_ui][enable]"]')
        .submitForm('input[type="submit"]') // Submit module form.
        .waitForElementVisible(
          '.system-modules-confirm-form input[value="Continue"]',
        )
        .submitForm('input[value="Continue"]') // Confirm installation of dependencies.
        .waitForElementVisible('.system-modules', 10000)

        // Create new input format.
        .drupalRelativeURL('/admin/config/content/formats/add')
        .waitForElementVisible('[data-drupal-selector="edit-name"]')
        .updateValue('[data-drupal-selector="edit-name"]', 'test')
        .waitForElementVisible('#edit-name-machine-name-suffix')
        .click(
          '[data-drupal-selector="edit-editor-editor"] option[value=ckeditor5]',
        )
        // Wait for CKEditor 5 settings to be visible.
        .waitForElementVisible(
          '[data-drupal-selector="edit-editor-settings-toolbar"]',
        )
        .click('.ckeditor5-toolbar-button-sourceEditing') // Select the Source Editing button.
        // Hit the down arrow key to move it to the toolbar.
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ARROW_DOWN);
        })
        // Wait for new source editing vertical tab to be present before continuing.
        .waitForElementVisible(
          '[href*=edit-editor-settings-plugins-ckeditor5-sourceediting]',
        )
        .click('.ckeditor5-toolbar-item-codeBlock') // Select the Code Block button.
        // Hit the down arrow key to move it to the toolbar.
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ARROW_DOWN);
        })
        // Wait for new code editing vertical tab to be present before continuing.
        .waitForElementVisible(
          '[href*=edit-editor-settings-plugins-ckeditor5-codeblock]',
        )
        .click('[href*=edit-editor-settings-plugins-ckeditor5-codeblock]')
        .setValue(
          '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-codeblock-languages"]',
          'twig|Twig\nyml|YML',
        )
        .submitForm('input[type="submit"]')
        .waitForElementVisible('[data-drupal-messages]')
        .assert.textContains('[data-drupal-messages]', 'Added text format')

        // Create a new content type.
        .drupalRelativeURL('/admin/structure/types/add')
        .waitForElementVisible('[data-drupal-selector="edit-name"]')
        .updateValue('[data-drupal-selector="edit-name"]', 'test')
        .waitForElementVisible('#edit-name-machine-name-suffix') // Wait for machine name to update.
        .submitForm('input[type="submit"]')
        .waitForElementVisible('[data-drupal-messages]')
        .assert.textContains(
          '[data-drupal-messages]',
          'The content type test has been added',
        )

        // Navigate to create new content.
        .drupalRelativeURL('/node/add/test')
        .waitForElementVisible('.ck-editor__editable')

        // Open code block dropdown, and verify that correct languages are present.
        .click(
          '.ck-code-block-dropdown .ck-dropdown__button .ck-splitbutton__arrow',
        )
        .assert.textContains(
          '.ck-code-block-dropdown .ck-dropdown__panel .ck-list__item:nth-child(1) .ck-button__label',
          'Twig',
        )
        .assert.textContains(
          '.ck-code-block-dropdown .ck-dropdown__panel .ck-list__item:nth-child(2) .ck-button__label',
          'YML',
        )

        // Click the first language (which should be 'Twig').
        .click(
          '.ck-code-block-dropdown .ck-dropdown__panel .ck-list__item:nth-child(1) button',
        )
        .waitForElementVisible('.ck-editor__main pre[data-language="Twig"]')
        // Press 'X' to ensure there's data in CKEditor before switching to source view.
        .perform(function () {
          return this.actions().sendKeys('x');
        })
        .pause(50)

        // Go into source editing and verify that correct CSS class is added.
        .click('.ck-source-editing-button')
        .waitForElementVisible('.ck-source-editing-area')
        .assert.valueContains(
          '.ck-source-editing-area textarea',
          '<pre><code class="language-twig">',
        )

        // Go back into WYSIWYG mode and hit enter three times to break out of code block.
        .click('.ck-source-editing-button') // Disable source editing.
        .waitForElementVisible('.ck-editor__editable:not(.ck-hidden)')
        // Go to end of line.
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ARROW_RIGHT);
        })
        .pause(50)

        // Hit Enter three times to break out of CKEditor's code block.
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ENTER);
        })
        .pause(50)
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ENTER);
        })
        .pause(50)
        .perform(function () {
          return this.actions().sendKeys(browser.Keys.ENTER);
        })
        .pause(50)

        // Open up the code syntax dropdown, and click the 2nd item (which should be 'YML').
        .click(
          '.ck-code-block-dropdown .ck-dropdown__button .ck-splitbutton__arrow',
        )
        .click(
          '.ck-code-block-dropdown .ck-dropdown__panel .ck-list__item:nth-child(2) button',
        )
        // Press 'X' to ensure there's data in CKEditor before switching to source view.
        .perform(function () {
          return this.actions().sendKeys('x');
        })

        // Go into source editing and verify that correct CSS class is added.
        .click('.ck-source-editing-button')
        .waitForElementVisible('.ck-source-editing-area')
        .assert.valueContains(
          '.ck-source-editing-area textarea',
          '<pre><code class="language-yml">',
        );
    });
  },
};
+4 −4
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ protected function getEditorDataAsHtmlString(): string {
  /**
   * Waits for CKEditor to initialize.
   */
  protected function waitForEditor() {
  protected function waitForEditor(): void {
    $assert_session = $this->assertSession();
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ck-editor'));
  }
@@ -60,7 +60,7 @@ protected function waitForEditor() {
   * @param string $name
   *   The name of the button, such as `drupallink`, `source`, etc.
   */
  protected function pressEditorButton($name) {
  protected function pressEditorButton($name): void {
    $this->getEditorButton($name)->click();
  }

@@ -85,7 +85,7 @@ protected function getEditorButton($name) {
   * @param string $name
   *   The name of the button, such as `drupallink`, `source`, etc.
   */
  protected function assertEditorButtonDisabled($name) {
  protected function assertEditorButtonDisabled($name): void {
    $button = $this->getEditorButton($name);
    $this->assertTrue($button->hasAttribute('aria-disabled'));
    $this->assertTrue($button->hasClass('ck-disabled'));
@@ -97,7 +97,7 @@ protected function assertEditorButtonDisabled($name) {
   * @param string $name
   *   The name of the button, such as `drupallink`, `source`, etc.
   */
  protected function assertEditorButtonEnabled($name) {
  protected function assertEditorButtonEnabled($name): void {
    $button = $this->getEditorButton($name);
    $this->assertFalse($button->hasAttribute('aria-disabled'));
    $this->assertFalse($button->hasClass('ck-disabled'));