You are here

public function EditorLoadingTest::testSupportedElementTypes in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/editor/src/Tests/EditorLoadingTest.php \Drupal\editor\Tests\EditorLoadingTest::testSupportedElementTypes()

Test supported element types.

File

core/modules/editor/src/Tests/EditorLoadingTest.php, line 222
Contains \Drupal\editor\Tests\EditorLoadingTest.

Class

EditorLoadingTest
Tests loading of text editors.

Namespace

Drupal\editor\Tests

Code

public function testSupportedElementTypes() {

  // Associate the unicorn text editor with the "Full HTML" text format.
  $editor = entity_create('editor', array(
    'format' => 'full_html',
    'editor' => 'unicorn',
    'image_upload' => array(
      'status' => FALSE,
      'scheme' => file_default_scheme(),
      'directory' => 'inline-images',
      'max_size' => '',
      'max_dimensions' => array(
        'width' => '',
        'height' => '',
      ),
    ),
  ));
  $editor
    ->save();

  // Create an "page" node that uses the full_html text format.
  $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'field_text' => array(
      array(
        'value' => $this
          ->randomMachineName(32),
        'format' => 'full_html',
      ),
    ),
  ));

  // Assert the unicorn editor works with textfields.
  $this
    ->drupalLogin($this->privilegedUser);
  $this
    ->drupalGet('node/1/edit');
  list(, $editor_settings_present, $editor_js_present, $field, $format_selector) = $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
    ->assertTrue(count($field) === 1, 'A text field exists.');
  $this
    ->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.');
  $specific_format_selector = $this
    ->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-field-text-0-value"]');
  $this
    ->assertTrue(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.');

  // Associate the trex text editor with the "Full HTML" text format.
  $editor
    ->delete();
  entity_create('editor', array(
    'format' => 'full_html',
    'editor' => 'trex',
  ))
    ->save();
  $this
    ->drupalGet('node/1/edit');
  list(, $editor_settings_present, $editor_js_present, $field, $format_selector) = $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
    ->assertTrue(count($field) === 1, 'A text field exists.');
  $this
    ->assertTrue(count($format_selector) === 1, 'A single text format selector exists on the page.');
  $specific_format_selector = $this
    ->xpath('//select[contains(@class, "filter-list") and contains(@class, "editor") and @data-editor-for="edit-field-text-0-value"]');
  $this
    ->assertFalse(count($specific_format_selector) === 1, 'A single text format selector exists on the page and has the "editor" class and a "data-editor-for" attribute with the correct value.');
}