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. 10 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()

Test supported element types.

File

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

Class

EditorLoadingTest
Tests loading of text editors.

Namespace

Drupal\Tests\editor\Functional

Code

public function testSupportedElementTypes() {
    // 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 an "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');
    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->assertCount(1, $field, 'A text field exists.');
    $this->assertCount(1, $format_selector, '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->assertCount(1, $specific_format_selector, '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();
    Editor::create([
        '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->assertCount(1, $field, 'A text field exists.');
    $this->assertCount(1, $format_selector, '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->assertCount(0, $specific_format_selector, 'No text format selector exists on the page with the "editor" class and a "data-editor-for" attribute with the expected value.');
}

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