You are here

public function InsertImageTest::testImageUrlOutput in Insert 8.2

File

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

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testImageUrlOutput() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($fieldName, [
    'alt_field' => '0',
  ]);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'image' => 'image',
      'thumbnail' => 'thumbnail',
    ],
    'default' => 'image',
  ]);
  $images = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('admin/config/content/formats/manage/plain_text');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->findField('filters[filter_html_escape][status]')
    ->uncheck();
  $page
    ->findField('filters[editor_file_reference][status]')
    ->check();
  $page
    ->findButton('Save configuration')
    ->click();
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($images[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $page
    ->find('css', '.insert select.insert-style')
    ->selectOption('thumbnail');
  $page
    ->findButton('Insert')
    ->click();
  $page
    ->findField('title[0][value]')
    ->setValue('title');
  $page
    ->findButton('Save')
    ->click();
  $page = $this
    ->getSession()
    ->getPage();
  $count = preg_match_all('!(src="[^"]+")!', $page
    ->find('css', '.field--name-body')
    ->getHtml(), $matches);
  $this
    ->assertEquals(2, $count, 'Verified two image being inserted in body.');
  $this
    ->assertFalse(strpos($matches[0][0], 'thumbnail'), 'First image refers to original URL.');
  $this
    ->assertTrue(strpos($matches[0][1], 'thumbnail') !== FALSE, 'Second image refers to style URL.');
}