ckeditor5-1.0.x-dev/tests/src/FunctionalJavascript/AdminUiTest.php

tests/src/FunctionalJavascript/AdminUiTest.php
<?php

namespace Drupal\Tests\ckeditor5\FunctionalJavascript;

/**
 * Tests for CKEditor 5 in the admin UI.
 *
 * @group ckeditor5
 */
class AdminUiTest extends CKEditor5TestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'media_library',
    'ckeditor',
  ];

  /**
   * Confirm settings only trigger AJAX when select value is CKEditor 5.
   */
  public function testSettingsOnlyFireAjaxWithCkeditor5() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();
    $this->addNewTextFormat($page, $assert_session);
    $this->addNewTextFormat($page, $assert_session, 'ckeditor');

    $this->drupalGet('admin/config/content/formats/manage/ckeditor5');
    $number_ajax_instances_before = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');

    // Enable media embed to trigger an AJAX rebuild.
    $this->assertTrue($page->hasUncheckedField('filters[media_embed][status]'));
    $page->checkField('filters[media_embed][status]');
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ajax-progress-throbber'));
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContains('Media types selectable in the Media Library');
    $assert_session->assertWaitOnAjaxRequest();
    $number_ajax_instances_after = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');

    // After the rebuild, there should be more AJAX instances.
    $this->assertGreaterThan($number_ajax_instances_before, $number_ajax_instances_after);

    // Perform the same steps as above with CKEditor, and confirm AJAX callbacks
    // are not triggered on settings changes.
    $this->drupalGet('admin/config/content/formats/manage/ckeditor');
    $number_ajax_instances_before = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');

    // Enable media embed to confirm a format not using CKEditor 5 will not
    // trigger an AJAX rebuild.
    $this->assertTrue($page->hasUncheckedField('filters[media_embed][status]'));
    $page->checkField('filters[media_embed][status]');
    $this->assertEmpty($assert_session->waitForElement('css', '.ajax-progress-throbber'));
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContains('Media types selectable in the Media Library');
    $assert_session->assertWaitOnAjaxRequest();

    $number_ajax_instances_after = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');
    $this->assertSame($number_ajax_instances_before, $number_ajax_instances_after);

    // Confirm that AJAX updates happen when attempting to switch to CKEditor 5,
    // even if prevented from doing so by validation.
    $this->drupalGet('admin/config/content/formats/add');
    $page->fillField('name', 'trigger validator');
    $assert_session->waitForText('Machine name');
    $page->checkField('roles[authenticated]');

    // Enable a filter that is incompatible with CKEditor 5, so validation is
    // triggered when attempting to switch.
    $number_ajax_instances_before = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');
    $this->assertTrue($page->hasUncheckedField('filters[filter_autop][status]'));
    $page->checkField('filters[filter_autop][status]');
    $this->assertEmpty($assert_session->waitForElement('css', '.ajax-progress-throbber'));
    $assert_session->assertWaitOnAjaxRequest();
    $number_ajax_instances_after = $this->getSession()->evaluateScript('Drupal.ajax.instances.length');
    $this->assertSame($number_ajax_instances_before, $number_ajax_instances_after);

    $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();

    // The presence of this validation error message confirms the AJAX callback
    // was invoked.
    $assert_session->pageTextContains('CKEditor 5 only works with HTML-based text formats');

    // Disable the incompatible filter. This should trigger another AJAX rebuild
    // which will include the removal of the validation error as the issue has
    // been corrected.
    $this->assertTrue($page->hasCheckedField('filters[filter_autop][status]'));
    $page->uncheckField('filters[filter_autop][status]');
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ajax-progress-throbber'));
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextNotContains('CKEditor 5 only works with HTML-based text formats');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc