You are here

public function ExtlinkTestNoFollow::testExtlinkEnabledNoFollowEnabled in External Links 8

Checks to see if extlink and nofollow work together when both are enabled.

File

tests/src/FunctionalJavascript/ExtlinkTestNoFollow.php, line 15

Class

ExtlinkTestNoFollow
Testing the rel nofollow/follow functionality of External Links.

Namespace

Drupal\Tests\extlink\FunctionalJavascript

Code

public function testExtlinkEnabledNoFollowEnabled() {

  // No Follow Enabled.
  $this
    ->config('extlink.settings')
    ->set('extlink_nofollow', TRUE)
    ->save();

  // Login.
  $this
    ->drupalLogin($this->adminUser);

  // Create a node with an external link.
  $settings = [
    'type' => 'page',
    'title' => 'test page',
    'body' => [
      [
        'value' => '<p><a href="http://google.com">Google!</a></p>',
        'format' => $this->emptyFormat
          ->id(),
      ],
    ],
  ];
  $node = $this
    ->drupalCreateNode($settings);

  // Get the page.
  $this
    ->drupalGet($node
    ->toUrl());
  $page = $this
    ->getSession()
    ->getPage();
  $this
    ->assertTrue($page
    ->hasLink('Google!'));

  // Test that the page has the external link svg.
  $externalLink = $page
    ->find('xpath', self::EXTLINK_EXT_XPATH);
  $this
    ->assertTrue(!is_null($externalLink) && $externalLink
    ->isVisible(), 'External Link does not exist.');

  // Does the anchor tag have no follow?
  $link = $page
    ->findLink('Google!');
  $this
    ->assertTrue($link
    ->hasAttribute('rel'), 'ExtLink does not have rel attribute.');
  $this
    ->assertStringContainsString('nofollow', $link
    ->getAttribute('rel'), 'ExtLink rel attribute does not contain "nofollow".');
}