function FilterAPITest::testCheckMarkupFilterSubset in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/filter/src/Tests/FilterAPITest.php \Drupal\filter\Tests\FilterAPITest::testCheckMarkupFilterSubset()
Tests the ability to apply only a subset of filters.
File
- core/
modules/ filter/ src/ Tests/ FilterAPITest.php, line 68 - Contains \Drupal\filter\Tests\FilterAPITest.
Class
- FilterAPITest
- Tests the behavior of the API of the Filter module.
Namespace
Drupal\filter\TestsCode
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', '', array());
$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', '', array(
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', '', array(
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.');
}