Skip navigation


7 filter.test FilterUnitTestCase::testNoFollowFilter()

Test the spam deterrent.


drupal/modules/filter/filter.test, line 1109
Tests for filter.module.


function testNoFollowFilter() {
  // Setup 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="">text</a>', $filter);
  $this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent -- no evasion.'));

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

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

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

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