You are here

function FilterUnitTest::testUrlFilterContent in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/filter/src/Tests/FilterUnitTest.php \Drupal\filter\Tests\FilterUnitTest::testUrlFilterContent()

Tests URL filter on longer content.

Filters based on regular expressions should also be tested with a more complex content than just isolated test lines. The most common errors are:

  • accidental '*' (greedy) match instead of '*?' (minimal) match.
  • only matching first occurrence instead of all.
  • newlines not matching '.*'.

This test covers:

  • Document with multiple newlines and paragraphs (two newlines).
  • Mix of several HTML tags, invalid non-HTML tags, tags to ignore and HTML comments.
  • Empty HTML tags (BR, IMG).
  • Mix of absolute and partial URLs, and email addresses in one content.

File

core/modules/filter/src/Tests/FilterUnitTest.php, line 928
Contains \Drupal\filter\Tests\FilterUnitTest.

Class

FilterUnitTest
Tests Filter module filters individually.

Namespace

Drupal\filter\Tests

Code

function testUrlFilterContent() {

  // Get FilterUrl object.
  $filter = $this->filters['filter_url'];
  $filter
    ->setConfiguration(array(
    'settings' => array(
      'filter_url_length' => 496,
    ),
  ));
  $path = drupal_get_path('module', 'filter') . '/tests';
  $input = file_get_contents($path . '/filter.url-input.txt');
  $expected = file_get_contents($path . '/filter.url-output.txt');
  $result = _filter_url($input, $filter);
  $this
    ->assertIdentical($result, $expected, 'Complex HTML document was correctly processed.');
}