You are here

public function ExtlinkTest::testExtlinkImg in External Links 8

Checks to see if an image link gets extlink svg.

File

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

Class

ExtlinkTest
Testing the basic functionality of External Links.

Namespace

Drupal\Tests\extlink\FunctionalJavascript

Code

public function testExtlinkImg() {

  // Login.
  $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);

  // Create a node with an external link on an image.
  $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);

  // Get 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) && $externalLink
    ->isVisible(), 'External Link Exists.');
}