You are here

public function InsertImageTest::testLinkImageSetting in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertImageTest.php, line 560

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testLinkImageSetting() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($fieldName, [
    'alt_field' => '0',
  ]);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'thumbnail' => 'thumbnail',
    ],
    'default' => 'thumbnail',
    'link_image' => 'large',
  ]);
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $images = $this
    ->drupalGetTestFiles('image');
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($images[0]->uri));
  $body = $page
    ->findField('body[0][value]');
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $this
    ->assertEquals(1, preg_match('!^<a href=".+/large/[^>]+><img src=".+/thumbnail/[^>]+></a>$!', $body
    ->getValue()), 'Inserted linked image: ' . $body
    ->getValue());
}