function FilterAPITest::testCheckMarkupFilterSubset
Same name in other branches
- 9 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testCheckMarkupFilterSubset()
- 10 core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testCheckMarkupFilterSubset()
- 11.x core/modules/filter/tests/src/Kernel/FilterAPITest.php \Drupal\Tests\filter\Kernel\FilterAPITest::testCheckMarkupFilterSubset()
Tests the ability to apply only a subset of filters.
File
-
core/
modules/ filter/ tests/ src/ Kernel/ FilterAPITest.php, line 65
Class
- FilterAPITest
- Tests the behavior of the API of the Filter module.
Namespace
Drupal\Tests\filter\KernelCode
public function testCheckMarkupFilterSubset() {
$text = "Text with <marquee>evil content and</marquee> a URL: https://www.drupal.org!";
$expected_filtered_text = "Text with evil content and a URL: <a href=\"https://www.drupal.org\">https://www.drupal.org</a>!";
$expected_filter_text_without_html_generators = "Text with evil content and a URL: https://www.drupal.org!";
$actual_filtered_text = check_markup($text, 'filtered_html', '', []);
$this->verbose("Actual:<pre>{$actual_filtered_text}</pre>Expected:<pre>{$expected_filtered_text}</pre>");
$this->assertEqual($actual_filtered_text, $expected_filtered_text, 'Expected filter result.');
$actual_filtered_text_without_html_generators = check_markup($text, 'filtered_html', '', [
FilterInterface::TYPE_MARKUP_LANGUAGE,
]);
$this->verbose("Actual:<pre>{$actual_filtered_text_without_html_generators}</pre>Expected:<pre>{$expected_filter_text_without_html_generators}</pre>");
$this->assertEqual($actual_filtered_text_without_html_generators, $expected_filter_text_without_html_generators, 'Expected filter result when skipping FilterInterface::TYPE_MARKUP_LANGUAGE filters.');
// Related to @see FilterSecurityTest.php/testSkipSecurityFilters(), but
// this check focuses on the ability to filter multiple filter types at once.
// Drupal core only ships with these two types of filters, so this is the
// most extensive test possible.
$actual_filtered_text_without_html_generators = check_markup($text, 'filtered_html', '', [
FilterInterface::TYPE_HTML_RESTRICTOR,
FilterInterface::TYPE_MARKUP_LANGUAGE,
]);
$this->verbose("Actual:<pre>{$actual_filtered_text_without_html_generators}</pre>Expected:<pre>{$expected_filter_text_without_html_generators}</pre>");
$this->assertEqual($actual_filtered_text_without_html_generators, $expected_filter_text_without_html_generators, 'Expected filter result when skipping FilterInterface::TYPE_MARKUP_LANGUAGE filters, even when trying to disable filters of the FilterInterface::TYPE_HTML_RESTRICTOR type.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.