function FilterKernelTest::testUrlFilterContent

Same name and namespace in other branches
  1. 9 core/modules/filter/tests/src/Kernel/FilterKernelTest.php \Drupal\Tests\filter\Kernel\FilterKernelTest::testUrlFilterContent()
  2. 10 core/modules/filter/tests/src/Kernel/FilterKernelTest.php \Drupal\Tests\filter\Kernel\FilterKernelTest::testUrlFilterContent()
  3. 11.x core/modules/filter/tests/src/Kernel/FilterKernelTest.php \Drupal\Tests\filter\Kernel\FilterKernelTest::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/tests/src/Kernel/FilterKernelTest.php, line 917

Class

FilterKernelTest
Tests Filter module filters individually.

Namespace

Drupal\Tests\filter\Kernel

Code

public function testUrlFilterContent() {
    // Get FilterUrl object.
    $filter = $this->filters['filter_url'];
    $filter->setConfiguration([
        'settings' => [
            'filter_url_length' => 496,
        ],
    ]);
    $path = __DIR__ . '/../..';
    $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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.