You are here

public function ExtlinkTest::testExtlink in External Links 8

Checks to see if external link gets extlink svg.

File

tests/src/FunctionalJavascript/ExtlinkTest.php, line 15

Class

ExtlinkTest
Testing the basic functionality of External Links.

Namespace

Drupal\Tests\extlink\FunctionalJavascript

Code

public function testExtlink() {

  // 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><p><a href="mailto:someone@example.com">Send Mail</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!'));
  $this
    ->assertTrue($page
    ->hasLink('Send Mail'));

  // 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 Exists.');

  // Test that the page has the Mailto external link svg.
  $mailToLink = $page
    ->find('xpath', self::EXTLINK_MAILTO_XPATH);
  $this
    ->assertTrue(!is_null($mailToLink) && $mailToLink
    ->isVisible(), 'External Link MailTo Exists.');
}