You are here

function NofollowListTestCase::testNoRelFollowOnBlacklist in Nofollow List 7

Tests blacklist functionality.

Tests that:

  • rel="nofollow" is added to links that are on the blacklist.
  • rel="nofollow" is not added to internal links.
  • rel="nofollow" is not added to links that are not on the blacklist.

File

./nofollowlist.test, line 99
Tests for nofollowlist.module.

Class

NofollowListTestCase
Tests the rel="nofollow" whitelist functionality.

Code

function testNoRelFollowOnBlacklist() {
  $this
    ->setupNofollowlist('black', "drupal.org\nwww.drupal.org");

  // Add page.
  $this
    ->drupalGet('node/add/page');
  $edit = array();
  $edit['title'] = $this
    ->randomName(8);

  // Add drupal.org link.
  $body_text = '<a href="http://drupal.org">drupal.org</a>';

  // Add www.drupal.org link.
  $body_text .= '<a href="http://www.drupal.org">wwwdrupal.org</a>';

  // Add internal link.
  $body_text .= '<a href="/drupal.org">internal link to drupal</a>';

  // Add external link.
  $body_text .= '<a href="http://www.example.com">example.com</a>';
  $edit['body[und][0][value]'] = $body_text;

  // Full html text format.
  $edit['body[und][0][format]'] = 'full_html';
  $this
    ->drupalPost('node/add/page', $edit, t('Save'));

  // Check that drupal.org link does has a rel="nofollow".
  $this
    ->assertPattern('|<a href="http://drupal.org" rel="nofollow">drupal.org</a>|', 'Drupal.org link has rel="nofollow".');

  // Check that www.drupal.org has a rel="nofollow".
  $this
    ->assertPattern('|<a href="http://www.drupal.org" rel="nofollow">wwwdrupal.org</a>|', 'Www.drupal.org link has rel="nofollow".');

  // Check that drupal internal link does not hav a rel="nofollow".
  $this
    ->assertPattern('|<a href="/drupal.org">internal link to drupal</a>|', 'Internal link does not have rel="nofollow".');

  // Check that example.com does not have a rel=nofollow.
  $this
    ->assertPattern('|<a href="http://www.example.com">example.com</a>|', 'Example.com link does not have rel="nofollow".');
}