function FilterUnitTestCase::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 e-mail addresses in one content.
File
-
modules/
filter/ filter.test, line 1638
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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.