function EditorLoadingTest::testSupportedElementTypes

Same name and namespace in other branches
  1. 9 core/modules/editor/tests/src/Functional/EditorLoadingTest.php \Drupal\Tests\editor\Functional\EditorLoadingTest::testSupportedElementTypes()
  2. 8.9.x core/modules/editor/tests/src/Functional/EditorLoadingTest.php \Drupal\Tests\editor\Functional\EditorLoadingTest::testSupportedElementTypes()
  3. 11.x core/modules/editor/tests/src/Functional/EditorLoadingTest.php \Drupal\Tests\editor\Functional\EditorLoadingTest::testSupportedElementTypes()

Tests supported element types.

File

core/modules/editor/tests/src/Functional/EditorLoadingTest.php, line 253

Class

EditorLoadingTest
Tests loading of text editors.

Namespace

Drupal\Tests\editor\Functional

Code

public function testSupportedElementTypes() : void {
  // Associate the unicorn text editor with the "Full HTML" text format.
  $editor = Editor::create([
    'format' => 'full_html',
    'editor' => 'unicorn',
    'image_upload' => [
      'status' => FALSE,
      'scheme' => 'public',
      'directory' => 'inline-images',
      'max_size' => '',
      'max_dimensions' => [
        'width' => '',
        'height' => '',
      ],
    ],
  ]);
  $editor->save();
  // Create a "page" node that uses the full_html text format.
  $this->drupalCreateNode([
    'type' => 'page',
    'field_text' => [
      [
        'value' => $this->randomMachineName(32),
        'format' => 'full_html',
      ],
    ],
  ]);
  // Assert the unicorn editor works with textfields.
  $this->drupalLogin($this->privilegedUser);
  $this->drupalGet('node/1/edit');
  [
    ,
    $editor_settings_present,
    $editor_js_present,
    $field,
  ] = $this->getThingsToCheck('field-text', 'input');
  $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page.");
  $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.');
  $this->assertSession()
    ->elementsCount('xpath', $field, 1);
  // Verify that a single text format selector exists on the page and has the
  // "editor" class and a "data-editor-for" attribute with the correct value.
  $this->assertSession()
    ->elementsCount('css', 'select.js-filter-list', 1);
  $select = $this->assertSession()
    ->elementExists('css', 'select.js-filter-list');
  $this->assertStringContainsString('editor', $select->getAttribute('class'));
  $this->assertSame('edit-field-text-0-value', $select->getAttribute('data-editor-for'));
  // Associate the trex text editor with the "Full HTML" text format.
  $editor->delete();
  Editor::create([
    'format' => 'full_html',
    'editor' => 'trex',
  ])->save();
  $this->drupalGet('node/1/edit');
  [
    ,
    $editor_settings_present,
    $editor_js_present,
    $field,
  ] = $this->getThingsToCheck('field-text', 'input');
  $this->assertFalse($editor_settings_present, "Text Editor module's JavaScript settings are not on the page.");
  $this->assertFalse($editor_js_present, 'Text Editor JavaScript is not present.');
  $this->assertSession()
    ->elementsCount('xpath', $field, 1);
  // Verify that a single text format selector exists on the page but without
  // the "editor" class or a "data-editor-for" attribute with the expected
  // value.
  $this->assertSession()
    ->elementsCount('css', 'select.js-filter-list', 1);
  $select = $this->assertSession()
    ->elementExists('css', 'select.js-filter-list');
  $this->assertStringNotContainsString('editor', $select->getAttribute('class'));
  $this->assertNotSame('edit-field-text-0-value', $select->getAttribute('data-editor-for'));
}

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