1 filter.test | 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 email addresses in one content.
File
- core/
modules/ filter/ tests/ filter.test, line 1767 - Tests for filter.module.
Class
- FilterUnitTestCase
- Unit tests for core filters.
Code
function testUrlFilterContent() {
// Set up dummy filter object.
$filter = new stdClass();
$filter->settings = array(
'filter_url_length' => 496,
);
$path = backdrop_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.');
}