createNewTextFormat example

/** * Test enabling CKEditor 5 in a way that triggers validation. */
  public function testEnablingToVersion5Validation() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $incompatible_filter_name = 'filters[filter_incompatible][status]';
    $filter_warning = 'CKEditor 5 only works with HTML-based text formats. The "A TYPE_MARKUP_LANGUAGE filter incompatible with CKEditor 5" (filter_incompatible) filter implies this text format is not HTML anymore.';

    $this->createNewTextFormat($page$assert_session, 'unicorn');
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $assert_session->assertWaitOnAjaxRequest();
    $page->checkField('filters[filter_html][status]');
    $page->checkField($incompatible_filter_name);
    $assert_session->assertWaitOnAjaxRequest();
    $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextContains($filter_warning);

    // Disable the incompatible filter.     $page->uncheckField($incompatible_filter_name);

    
JS;
    return $this->getSession()->evaluateScript($javascript);
  }

  /** * CKEditor 5's filter UI modifications should not break it for other editors. */
  public function testUnavailableFiltersHiddenWhenSwitching() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();
    $this->createNewTextFormat($page$assert_session, 'unicorn');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextNotContains('Filter settings');

    // Switching to CKEditor 5 should keep the filter settings hidden.     $page->selectFieldOption('editor[editor]', 'ckeditor5');
    $assert_session->assertWaitOnAjaxRequest();
    $assert_session->pageTextNotContains('Filter settings');
  }

  /** * Test that filter settings are only visible when the filter is enabled. */
$this->drupalLogin($this->drupalCreateUser([
      'administer filters',
      'create page content',
      'edit own page content',
    ]));
  }

  /** * Add and save a new text format using CKEditor 5. */
  public function addNewTextFormat($page$assert_session$name = 'ckeditor5') {
    $this->createNewTextFormat($page$assert_session$name);
    $this->saveNewTextFormat($page$assert_session);
  }

  /** * Create a new text format using CKEditor 5. */
  public function createNewTextFormat($page$assert_session$name = 'ckeditor5') {
    $this->drupalGet('admin/config/content/formats/add');
    $page->fillField('name', $name);
    $assert_session->waitForText('Machine name');
    $this->assertNotEmpty($assert_session->waitForText($name));
    
'Heading 6',
    ]$available_headings);
  }

  /** * Test for plugin Language of parts. */
  public function testLanguageOfPartsPlugin() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    // Press arrow down key to add the button to the active toolbar.     $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-textPartLanguage'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-textPartLanguage', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    // The CKEditor 5 module should warn that `<span>` cannot be created.     $assert_session->waitForElement('css', '[role=alert][data-drupal-message-type="warning"]:contains("The Language plugin needs another plugin to create <span>, for it to be able to create the following attributes: <span lang dir>. Enable a plugin that supports creating this tag. If none exists, you can configure the Source Editing plugin to support it.")');

    // Make `<span>` creatable.     $this->assertNotEmpty($assert_session->elementExists('css', '.ckeditor5-toolbar-item-sourceEditing'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
    
use CKEditor5TestTrait;

  /** * @covers \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Style::buildConfigurationForm */
  public function testStyleSettingsForm() {
    $this->drupalLogin($this->drupalCreateUser(['administer filters']));

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $assert_session->assertWaitOnAjaxRequest();

    // The Style plugin settings form should not be present.     $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-style"]');

    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-style'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-style', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    // No validation error upon enabling the Style plugin.     $this->assertNoRealtimeValidationErrors();
    

  public function test(string $langcode, string $toolbar_item_name, string $toolbar_item_translation): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    // Special case: textPartLanguage toolbar item can only create `<span lang>`     // but not `<span>`. The purpose of this test is to test translations, not     // the configuration of the textPartLanguage functionality. So, make sure     // that `<span>` can be created so we can test how UI translations work when     // using `textPartLanguage`.     if ($toolbar_item_name === 'textPartLanguage') {
      $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-sourceEditing'));
      $this->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
      $assert_session->assertWaitOnAjaxRequest();

      // The Source Editing plugin settings form should now be present and should


  /** * @covers \Drupal\ckeditor5\Plugin\CKEditor5Plugin\SourceEditing::buildConfigurationForm */
  public function testSourceEditingSettingsForm() {
    $this->drupalLogin($this->drupalCreateUser(['administer filters']));

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $assert_session->assertWaitOnAjaxRequest();

    // The Source Editing plugin settings form should not be present.     $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-sourceediting"]');

    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-sourceEditing'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-sourceEditing', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    // The Source Editing plugin settings form should now be present and should     // have no allowed tags configured.
// Create a sample media entity to be embedded.     $this->createMediaType('image', ['id' => 'image', 'label' => 'Image']);
  }

  /** * Integration test to ensure that CKEditor 5 Plugins translations are loaded. */
  public function test(): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-drupalMedia'));
    $this->click('#edit-filters-media-embed-status');
    $assert_session->assertWaitOnAjaxRequest();
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalMedia', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();
    $this->saveNewTextFormat($page$assert_session);

    $langcode = 'fr';
    ConfigurableLanguage::createFromLangcode($langcode)->save();
    $this->config('system.site')->set('default_langcode', $langcode)->save();

    
Home | Imprint | This part of the site doesn't use cookies.