Index: modules/filter/filter.test =================================================================== RCS file: /cvs/drupal/drupal/modules/filter/filter.test,v retrieving revision 1.8 diff -u -p -r1.8 filter.test --- modules/filter/filter.test 12 Oct 2008 04:30:06 -0000 1.8 +++ modules/filter/filter.test 20 Nov 2008 21:43:12 -0000 @@ -216,7 +216,53 @@ class FilterTestCase extends DrupalWebTe * Test the HTML filter */ function testHtmlFilter() { + foreach ($this->getTestFilterHtml() as $id => $html) { + // Disable nofollow option. + variable_set('filter_html_nofollow_1', FALSE); + // Set allowed tags. + variable_set('allowed_html_1', $html['tags']); + // Filter tags out. + $filtered = _filter_html($html['original'], 1); + $this->assertEqual($filtered, $html['expected'], t('_filter_html() properly allows %tags: %scenario', array('%tags' => $html['tags'], '%scenario' => $html['scenario']))); + if (isset($html['expected_nofollow'])) { + // Enable nofollow option. + variable_set('filter_html_nofollow_1', TRUE); + // Filter and add rel=nofollow attribute. + $filtered = _filter_html($html['original'], 1); + $this->assertEqual($filtered, $html['expected_nofollow'], t('_filter_html() properly allows %tags and adds rel=nofollow when filter_html_nofollow is enabled: %scenario', array('%tags' => $html['tags'], '%scenario' => $html['scenario']))); + } + if (isset($html['expected_nohtml'])) { + // Escape all HTML. + $filtered = trim(check_plain($html['original'])); + $this->assertEqual($filtered, $html['expected_nohtml'], t('All html tags properly removed: %scenario', array('%scenario' => $html['scenario']))); + } + } + } + /** + * Test the HTML corrector. + */ + function testHtmlCorrector() { + foreach ($this->_getTestHtml() as $id => $html) { + $filtered = _filter_htmlcorrector($html['original']); + $this->assertEqual($filtered, $html['expected'], t('filter_htmlcorrector() properly fixes broken HTML: %scenario', array('%scenario' => $html['scenario']))); + } + } + + /** + * Test URL filter. + */ + function testUrlFilter() { + $url_long = 'http://www.example.com/sample/foo.html?variable=value&variable2=value2#anchor1'; + // Test url length filter. + $trimmed = _filter_url_trim($url_long, 27); + $this->assertEqual($trimmed, 'http://www.example.com/samp...', t('_filter_url_trim() function properly trims a long url.')); + + // Test www domains. + foreach ($this->_getTestUrls() as $id => $url) { + $filtered = _filter_url($url['original'], 1); + $this->assertEqual($filtered, $url['expected'], t('URL filter properly converts: @scenario', array('@scenario' => $url['scenario']))); + } } function createFormat($filter) { @@ -235,4 +281,150 @@ class FilterTestCase extends DrupalWebTe $this->drupalPost('admin/settings/filters/delete/' . $format->format, array(), t('Delete')); } } + + /** + * Get text with urls to test. + * + * @return + * Array of associative arrays containing: + * - scenario + * - original + * - expected + */ + function _getTestUrls() { + return array( + array( + 'scenario' => t('domain beginning with www in the middle of a sentence.'), + 'original' => 'A bit of text with a simple www domain placed in the middle www.example.com/foo/bar, like so.', + 'expected' => 'A bit of text with a simple www domain placed in the middle www.example.com/foo/bar, like so.', + ), + array( + 'scenario' => t('list item beggining with a domain.'), + 'original' => '

A list

as so.

', + 'expected' => '

A list

as so.

', + ), + array( + 'scenario' => t('email address'), + 'original' => 'An email address, positioned foobar@example.com in the middle of a sentence.', + 'expected' => 'An email address, positioned foobar@example.com in the middle of a sentence.', + ), + array( + 'scenario' => t('Insanely long links'), + 'original' => 'A http://www.reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyloong.com/link/to/test/on/the/url/filtere/index.html?but=wait&theres=more#also_an_anchor domain to test.', + 'expected' => 'A http://www.reallyreallyreallyreallyreallyreallyreallyreallyreallyreallyr... domain to test.', + ), + // These should go unchanged + array( + 'scenario' => t('does not replace urls in anchor tags'), + 'original' => 'An anchor tag in http://example.com the middle of a sentence.', + 'expected' => 'An anchor tag in http://example.com the middle of a sentence.', + ), + ); + } + + /** + * Get text with to test _filter_htmlcorrector(). + * + * @return + * Array of associative arrays containing: + * - scenario + * - original + * - expected + */ + function _getTestHtml() { + return array( + array( + // Note: This first scenario will fail. This is intentional so the + // comment (#222926) issue can be fixed. + 'scenario' => t('HTML comments are preserved.'), + 'original' => '

+Foobar foobar + +

', + 'expected' => '

+Foobar foobar + +

', + ), + array( + // This test will also fail. See above test. + 'scenario' => t('Incomplete comment is fixed.'), + 'original' => 'A comment gets started