You are here

public function InsertFileTest::testAbsoluteUrlSetting in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertFileTest.php, line 318

Class

InsertFileTest
Tests Insert module's generic file insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testAbsoluteUrlSetting() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createFileField($fieldName);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'link' => 1,
      'icon_link' => 1,
    ],
    'default' => 'link',
  ]);
  $files = $this
    ->drupalGetTestFiles('text');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $body = $page
    ->findField('body[0][value]');
  $this
    ->assertEquals(1, preg_match('!^<a href="/!', $body
    ->getValue()), 'Inserted relative URL: ' . $body
    ->getValue());
  $page = $this
    ->gotoInsertConfig();
  $page
    ->checkField('absolute');
  $this
    ->saveInsertConfig($page);
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $body = $page
    ->findField('body[0][value]');
  $this
    ->assertEquals(1, preg_match('!^<a href="http://!', $body
    ->getValue()), 'Inserted absolute URL: ' . $body
    ->getValue());
}