You are here

function FilterUnitTestCase::testUrlFilterContent in Drupal 7

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 e-mail addresses in one content.

File

modules/filter/filter.test, line 1631
Tests for filter.module.

Class

FilterUnitTestCase
Unit tests for core filters.

Code

function testUrlFilterContent() {

  // Setup dummy filter object.
  $filter = new stdClass();
  $filter->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.');
}