function FilterAPITest::testCheckMarkup

Tests the ability to apply only a subset of filters.

File

drupal/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php, line 64
Definition of Drupal\filter\Tests\FilterAPITest.

Class

FilterAPITest
Tests the behavior of Filter's API.

Namespace

Drupal\filter\Tests

Code

function testCheckMarkup() {
  $text = "Text with <marquee>evil content and</marquee> a URL: http://drupal.org!";
  $expected_filtered_text = "Text with evil content and a URL: <a href=\"http://drupal.org\">http://drupal.org</a>!";
  $expected_filter_text_without_html_generators = "Text with evil content and a URL: http://drupal.org!";
  $this
    ->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array()), $expected_filtered_text, 'Expected filter result.');
  $this
    ->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array(
    FILTER_TYPE_MARKUP_LANGUAGE,
  )), $expected_filter_text_without_html_generators, 'Expected filter result when skipping FILTER_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.
  $this
    ->assertIdentical(check_markup($text, 'filtered_html', '', FALSE, array(
    FILTER_TYPE_HTML_RESTRICTOR,
    FILTER_TYPE_MARKUP_LANGUAGE,
  )), $expected_filter_text_without_html_generators, 'Expected filter result when skipping FILTER_TYPE_MARKUP_LANGUAGE filters, even when trying to disable filters of the FILTER_TYPE_HTML_RESTRICTOR type.');
}