public function ExtlinkTestNoFollow::testExtlinkDisabledNoFollowEnabled in External Links 8
Checks to see if external link no follow works with extlink disabled.
File
- tests/
src/ FunctionalJavascript/ ExtlinkTestNoFollow.php, line 53
Class
- ExtlinkTestNoFollow
- Testing the rel nofollow/follow functionality of External Links.
Namespace
Drupal\Tests\extlink\FunctionalJavascriptCode
public function testExtlinkDisabledNoFollowEnabled() {
// No Follow Enabled, Disable Extlink.
$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();
// 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), 'External Link exists.');
// 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".');
}