View source
<?php
namespace Drupal\Tests\extlink\FunctionalJavascript;
class ExtlinkTestNoFollow extends ExtlinkTestBase {
public function testExtlinkEnabledNoFollowEnabled() {
$this
->config('extlink.settings')
->set('extlink_nofollow', TRUE)
->save();
$this
->drupalLogin($this->adminUser);
$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);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(!is_null($externalLink) && $externalLink
->isVisible(), 'External Link does not exist.');
$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".');
}
public function testExtlinkDisabledNoFollowEnabled() {
$this
->config('extlink.settings')
->set('extlink_nofollow', TRUE)
->save();
$this
->config('extlink.settings')
->set('extlink_class', '0')
->save();
$this
->config('extlink.settings')
->set('extlink_mailto_class', '0')
->save();
$this
->drupalLogin($this->adminUser);
$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);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(is_null($externalLink), 'External Link exists.');
$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".');
}
public function testExtlinkDisabledNoFollowDisabled() {
$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();
$this
->drupalLogin($this->adminUser);
$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);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(is_null($externalLink), 'External Link exists.');
$link = $page
->findLink('Google!');
$this
->assertStringNotContainsString('nofollow', $link
->getAttribute('rel'), 'ExtLink rel attribute does not contain "nofollow".');
}
public function testExtlinkNoFollowNoOverride() {
$this
->config('extlink.settings')
->set('extlink_nofollow', TRUE)
->save();
$this
->config('extlink.settings')
->set('extlink_follow_no_override', TRUE)
->save();
$this
->drupalLogin($this->adminUser);
$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);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(!is_null($externalLink) && $externalLink
->isVisible(), 'External Link does not exist.');
$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".');
}
}