1 filter.test FilterUnitTestCase::testNoFollowFilter()

Tests the spam deterrent.

File

core/modules/filter/tests/filter.test, line 1296
Tests for filter.module.

Class

FilterUnitTestCase
Unit tests for core filters.

Code

function testNoFollowFilter() {
  // Set up dummy filter object.
  $filter = new stdClass();
  $filter->settings = array(
    'allowed_html' => '<a>',
    'filter_html_help' => 1,
    'filter_html_nofollow' => 1,
  );

  // Test if the rel="nofollow" attribute is added, even if we try to prevent
  // it.
  $f = _filter_html('<a href="http://www.example.com/">text</a>', $filter);
  $this->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent -- no evasion.');

  $f = _filter_html('<A href="http://www.example.com/">text</a>', $filter);
  $this->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- capital A.');

  $f = _filter_html("<a/href=\"http://www.example.com/\">text</a>", $filter);
  $this->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- non whitespace character after tag name.');

  $f = _filter_html("<\0a\0 href=\"http://www.example.com/\">text</a>", $filter);
  $this->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- some nulls.');

  $f = _filter_html('<a href="http://www.example.com/" rel="follow">text</a>', $filter);
  $this->assertNoNormalized($f, 'rel="follow"', 'Spam deterrent evasion -- with rel set - rel="follow" removed.');
  $this->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- with rel set - rel="nofollow" added.');
}