You are here

public function ExtlinkTestNoFollow::testExtlinkDisabledNoFollowDisabled in External Links 8

Checks to see if rel no follow is added if disabled.

File

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

Class

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

Namespace

Drupal\Tests\extlink\FunctionalJavascript

Code

public function testExtlinkDisabledNoFollowDisabled() {

  // No Follow Enabled, Extlink Disabled.
  $this
    ->config('extlink.settings')
    ->set('extlink_nofollow', FALSE)
    ->save();
  $this
    ->config('extlink.settings')
    ->set('extlink_follow_no_override', FALSE)
    ->save();
  $this
    ->config('extlink.settings')
    ->set('extlink_class', '0')
    ->save();
  $this
    ->config('extlink.settings')
    ->set('extlink_mailto_class', '0')
    ->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 doesn't have the external link svg.
  $externalLink = $page
    ->find('xpath', self::EXTLINK_EXT_XPATH);
  $this
    ->assertTrue(is_null($externalLink), 'External Link exists.');

  // Check for no 'nofollow'.
  $link = $page
    ->findLink('Google!');
  $this
    ->assertStringNotContainsString('nofollow', $link
    ->getAttribute('rel'), 'ExtLink rel attribute does not contain "nofollow".');
}