You are here

public function InsertImageWidgetTest::testAbsoluteUrlSetting in Insert 8

File

tests/src/FunctionalJavaScript/InsertImageWidgetTest.php, line 148

Class

InsertImageWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testAbsoluteUrlSetting() {
  $field_names = [
    strtolower($this
      ->randomMachineName()),
    strtolower($this
      ->randomMachineName()),
  ];
  $this
    ->createImageField($field_names[0], 'article', [], [
    'alt_field' => '0',
  ], [
    'insert_default' => 'thumbnail',
  ]);
  $this
    ->createImageField($field_names[1], 'article', [], [
    'alt_field' => '0',
  ], [
    'insert_default' => 'thumbnail',
    'insert_absolute' => '1',
  ]);
  $files = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_names[0] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $page
    ->attachFileToField('files[' . $field_names[1] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_names[0] . '[0][fids]');
  $this
    ->assertSession()
    ->waitForField($field_names[1] . '[0][fids]');
  $page
    ->find('css', '#edit-' . $field_names[0] . '-wrapper')
    ->findButton('Insert')
    ->click();
  $body_value = $page
    ->find('css', '#edit-body-0-value')
    ->getValue();
  $this
    ->assertEquals(1, preg_match('!^<img src="/!', $body_value), 'Inserted relative URL: ' . $body_value);
  $page
    ->find('css', '#edit-body-0-value')
    ->setValue('');
  $page
    ->find('css', '#edit-' . $field_names[1] . '-wrapper')
    ->findButton('Insert')
    ->click();
  $body_value = $page
    ->find('css', '#edit-body-0-value')
    ->getValue();
  $this
    ->assertEquals(1, preg_match('!^<img src="http://!', $body_value), 'Inserted absolute URL: ' . $body_value);
}