You are here

public function InsertFileWidgetTest::testInsertStyleSelectOption in Insert 8

File

tests/src/FunctionalJavaScript/InsertFileWidgetTest.php, line 102

Class

InsertFileWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testInsertStyleSelectOption() {
  $field_name = strtolower($this
    ->randomMachineName());
  $this
    ->createFileField($field_name, 'article', [], [], [
    'insert_styles' => [
      'link' => 'link',
      'icon_link' => 'icon_link',
    ],
  ]);
  $files = $this
    ->drupalGetTestFiles('text');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_name . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_name . '[0][fids]');
  $page
    ->find('css', '.insert select.insert-style')
    ->selectOption('icon_link');
  $page
    ->findButton('Insert')
    ->click();
  $body_value = $page
    ->find('css', '#edit-body-0-value')
    ->getValue();
  $this
    ->assertEquals(1, preg_match('!<span class="file [^"]+" contenteditable="false" data-insert-type="file"><a href="[^"]+/text-0.txt" type="text/plain; length=1024">text-0.txt</a>!', $body_value), 'Verified inserted HTML: "' . $body_value . '"');
}