You are here

public function ExtlinkTestNoFollow::testExtlinkNoFollowNoOverride in External Links 8

Checks to see if rel no follow is overridden.

File

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

Class

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

Namespace

Drupal\Tests\extlink\FunctionalJavascript

Code

public function testExtlinkNoFollowNoOverride() {

  // No Follow Enabled, Extlink Disabled.
  $this
    ->config('extlink.settings')
    ->set('extlink_nofollow', TRUE)
    ->save();
  $this
    ->config('extlink.settings')
    ->set('extlink_follow_no_override', 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" rel="follow">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('follow', $link
    ->getAttribute('rel'), 'ExtLink rel attribute does not contain "follow".');
}