FilterHtmlTest.php

Same filename in this branch
  1. 9 core/modules/filter/tests/src/Unit/FilterHtmlTest.php
Same filename and directory in other branches
  1. 8.9.x core/modules/filter/tests/src/Unit/FilterHtmlTest.php
  2. 10 core/modules/filter/tests/src/Unit/FilterHtmlTest.php
  3. 10 core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php
  4. 11.x core/modules/filter/tests/src/Unit/FilterHtmlTest.php
  5. 11.x core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php

Namespace

Drupal\Tests\filter\FunctionalJavascript

File

core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php

View source
<?php

namespace Drupal\Tests\filter\FunctionalJavascript;

use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;

/**
 * Tests the 'filter_html' plugin javascript functionality.
 *
 * @group filter
 */
class FilterHtmlTest extends WebDriverTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected static $modules = [
        'editor',
        'filter',
    ];
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Tests restricting HTML to table tags.
     */
    public function testTableTags() {
        FilterFormat::create([
            'format' => 'some_html',
            'name' => 'Some HTML',
            'filters' => [
                'filter_html' => [
                    'status' => 1,
                    'settings' => [
                        'allowed_html' => '<caption> <tbody> <thead> <tfoot> <th> <td> <tr>',
                    ],
                ],
            ],
        ])->save();
        $this->drupalLogin($this->drupalCreateUser([
            'administer filters',
        ]));
        $this->drupalGet('admin/config/content/formats/manage/some_html');
        $js_condition = "Drupal.behaviors.filterFilterHtmlUpdating._parseSetting(\n      jQuery('#edit-filters-filter-html-settings-allowed-html').val()\n    )['td'].tags.length >= 0";
        $this->assertJsCondition($js_condition);
    }
    
    /**
     * Tests the Allowed Tags configuration with CSS classes.
     *
     * @group legacy
     */
    public function testStylesToAllowedTagsSync() {
        \Drupal::service('module_installer')->install([
            'ckeditor',
        ]);
        FilterFormat::create([
            'format' => 'some_html',
            'name' => 'Some HTML',
            'filters' => [
                'filter_html' => [
                    'status' => 1,
                    'settings' => [
                        'allowed_html' => '<span class>',
                    ],
                ],
            ],
        ])->save();
        Editor::create([
            'format' => 'some_html',
            'editor' => 'ckeditor',
            'settings' => [
                'plugins' => [
                    'stylescombo' => [
                        'styles' => 'span.hello-world|Hello World',
                    ],
                ],
            ],
        ])->save();
        $this->drupalLogin($this->drupalCreateUser([
            'administer filters',
        ]));
        $this->drupalGet('admin/config/content/formats/manage/some_html');
        $js_condition = "jQuery('#edit-filters-filter-html-settings-allowed-html').val() === \"<span class> <strong> <em> <a href> <ul> <li> <ol> <blockquote> <img src alt data-entity-type data-entity-uuid>\"";
        $this->assertJsCondition($js_condition);
    }

}

Classes

Title Deprecated Summary
FilterHtmlTest Tests the 'filter_html' plugin javascript functionality.

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