You are here

class CKEditor5DialogTest in Drupal 10

Tests for CKEditor 5 to ensure correct focus management in dialogs.

@group ckeditor5 @internal

Hierarchy

  • class \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5DialogTest extends \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5TestBase uses \Drupal\Tests\ckeditor5\Traits\CKEditor5TestTrait

Expanded class hierarchy of CKEditor5DialogTest

File

core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5DialogTest.php, line 18

Namespace

Drupal\Tests\ckeditor5\FunctionalJavascript
View source
class CKEditor5DialogTest extends CKEditor5TestBase {
  use CKEditor5TestTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'node',
    'ckeditor5',
    'ckeditor5_test',
  ];

  /**
   * Tests if CKEditor 5 tooltips can be interacted with in dialogs.
   */
  public function testCKEditor5FocusInTooltipsInDialog() {
    FilterFormat::create([
      'format' => 'test_format',
      'name' => 'CKEditor 5 with link',
      'roles' => [
        RoleInterface::AUTHENTICATED_ID,
      ],
    ])
      ->save();
    Editor::create([
      'format' => 'test_format',
      'editor' => 'ckeditor5',
      'settings' => [
        'toolbar' => [
          'items' => [
            'link',
          ],
        ],
      ],
    ])
      ->save();
    $this
      ->assertSame([], array_map(function (ConstraintViolation $v) {
      return (string) $v
        ->getMessage();
    }, iterator_to_array(CKEditor5::validatePair(Editor::load('test_format'), FilterFormat::load('test_format')))));
    $page = $this
      ->getSession()
      ->getPage();
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalGet('/ckeditor5_test/dialog');
    $page
      ->clickLink('Add Node');
    $assert_session
      ->waitForElementVisible('css', '[role="dialog"]');
    $assert_session
      ->assertWaitOnAjaxRequest();
    $content_area = $assert_session
      ->waitForElementVisible('css', '.ck-editor__editable');

    // Focus the editable area first.
    $content_area
      ->click();

    // Then press the button to add a link.
    $this
      ->pressEditorButton('Link');
    $link_url = '/ckeditor5_test/dialog';
    $input = $assert_session
      ->waitForElementVisible('css', '.ck-balloon-panel input.ck-input-text');

    // Make sure the input field can have focus and we can type into it.
    $input
      ->setValue($link_url);

    // Save the new link.
    $page
      ->find('css', '.ck-balloon-panel .ck-button-save')
      ->click();

    // Make sure something was added to the text.
    $this
      ->assertNotEmpty($content_area
      ->getText());
  }

}

Members