View source
<?php
namespace Drupal\Tests\extlink\FunctionalJavascript;
class ExtlinkTest extends ExtlinkTestBase {
public function testExtlink() {
$this
->drupalLogin($this->adminUser);
$settings = [
'type' => 'page',
'title' => 'test page',
'body' => [
[
'value' => '<p><a href="http://google.com">Google!</a></p><p><a href="mailto:someone@example.com">Send Mail</a></p>',
'format' => $this->emptyFormat
->id(),
],
],
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$this
->assertTrue($page
->hasLink('Send Mail'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(!is_null($externalLink) && $externalLink
->isVisible(), 'External Link Exists.');
$mailToLink = $page
->find('xpath', self::EXTLINK_MAILTO_XPATH);
$this
->assertTrue(!is_null($mailToLink) && $mailToLink
->isVisible(), 'External Link MailTo Exists.');
}
public function testExtlinkImg() {
$this
->drupalLogin($this->adminUser);
$this
->config('extlink.settings')
->set('extlink_img_class', TRUE)
->save();
$test_image = current($this
->drupalGetTestFiles('image'));
$image_file_path = \Drupal::service('file_system')
->realpath($test_image->uri);
$settings = [
'type' => 'page',
'title' => 'test page',
'body' => [
[
'value' => '<p><a href="http://google.com"><img src="' . $image_file_path . '" alt="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 Exists.');
}
public function testExtlinkDisabled() {
$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><p><a href="mailto:someone@example.com">Send Mail</a></p>',
'format' => $this->emptyFormat
->id(),
],
],
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$this
->assertTrue($page
->hasLink('Send Mail'));
$externalLink = $page
->find('xpath', self::EXTLINK_EXT_XPATH);
$this
->assertTrue(is_null($externalLink), 'External Link does not exist.');
$mailToLink = $page
->find('xpath', self::EXTLINK_MAILTO_XPATH);
$this
->assertTrue(is_null($mailToLink), 'External Link MailTo does not exist.');
}
public function testExtlinkDomainMatching() {
$this
->drupalLogin($this->adminUser);
$domains = [
'http://www.example.com',
'http://www.example.com:8080',
'http://www.example.co.uk',
'http://test.example.com',
'http://example.com',
'http://www.whatever.com',
'http://www.domain.org',
'http://www.domain.nl',
'http://www.domain.de',
'http://www.auspigs.com',
'http://www.usapigs.com',
'http://user:password@example.com',
];
$node_html = '';
foreach ($domains as $item) {
$node_html .= '<p><a href="' . $item . '">' . $item . '</a></p><p>';
}
$settings = [
'type' => 'page',
'title' => 'test page',
'body' => [
[
'value' => $node_html,
'format' => $this->emptyFormat
->id(),
],
],
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
foreach ($domains as $item) {
$externalLink = $page
->findLink($item);
$this
->assertTrue($externalLink
->hasAttribute('data-extlink'), 'External Link failed for "' . $item . '"');
}
}
public function testExtlinkDomainMatchingExcludeSubDomainsEnabled() {
$this
->config('extlink.settings')
->set('extlink_subdomains', TRUE)
->save();
$this
->testExtlinkDomainMatching();
}
public function testExtlinkUseFontAwesome() {
$this
->config('extlink.settings')
->set('extlink_use_font_awesome', TRUE)
->save();
$this
->drupalLogin($this->adminUser);
$settings = [
'type' => 'page',
'title' => 'test page',
'body' => [
[
'value' => '<p><a href="http://google.com">Google!</a></p><p><a href="mailto:someone@example.com">Send Mail</a></p>',
'format' => $this->emptyFormat
->id(),
],
],
];
$node = $this
->drupalCreateNode($settings);
$this
->drupalGet($node
->toUrl());
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasLink('Google!'));
$this
->assertTrue($page
->hasLink('Send Mail'));
$this
->assertSession()
->elementExists('css', 'span.fa-external-link');
$this
->assertSession()
->elementExists('css', 'span.fa-envelope-o');
}
}