function FilterUnitTest::testNoFollowFilter in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/filter/src/Tests/FilterUnitTest.php \Drupal\filter\Tests\FilterUnitTest::testNoFollowFilter()
Tests the spam deterrent.
File
- core/
modules/ filter/ src/ Tests/ FilterUnitTest.php, line 501 - Contains \Drupal\filter\Tests\FilterUnitTest.
Class
- FilterUnitTest
- Tests Filter module filters individually.
Namespace
Drupal\filter\TestsCode
function testNoFollowFilter() {
// Get FilterHtml object.
$filter = $this->filters['filter_html'];
$filter
->setConfiguration(array(
'settings' => array(
'allowed_html' => '<a href>',
'filter_html_help' => 1,
'filter_html_nofollow' => 1,
),
));
// Test if the rel="nofollow" attribute is added, even if we try to prevent
// it.
$f = (string) $filter
->process('<a href="http://www.example.com/">text</a>', Language::LANGCODE_NOT_SPECIFIED);
$this
->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent -- no evasion.');
$f = (string) $filter
->process('<A href="http://www.example.com/">text</a>', Language::LANGCODE_NOT_SPECIFIED);
$this
->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- capital A.');
$f = (string) $filter
->process("<a/href=\"http://www.example.com/\">text</a>", Language::LANGCODE_NOT_SPECIFIED);
$this
->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- non whitespace character after tag name.');
$f = (string) $filter
->process("<\0a\0 href=\"http://www.example.com/\">text</a>", Language::LANGCODE_NOT_SPECIFIED);
$this
->assertNormalized($f, 'rel="nofollow"', 'Spam deterrent evasion -- some nulls.');
$f = (string) $filter
->process('<a href="http://www.example.com/" rel="follow">text</a>', Language::LANGCODE_NOT_SPECIFIED);
$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.');
}