You are here

public function InsertFileWidgetTest::testInsertStyleSelectDefault in Insert 8

File

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

Class

InsertFileWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testInsertStyleSelectDefault() {
  $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]');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '[name="' . $field_name . '[0][insert_template][link]"]')), 'Insert link template exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '[name="' . $field_name . '[0][insert_template][icon_link]"]')), 'Insert icon link template exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert select.insert-style')), 'Insert style select box exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert select.insert-style > option[value="link"]')), 'Insert style option "link" exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert select.insert-style > option[value="icon_link"]')), 'Insert style option "icon link" exists');
  $page
    ->findButton('Insert')
    ->click();
  $body_value = $page
    ->find('css', '#edit-body-0-value')
    ->getValue();
  $this
    ->assertEquals(1, preg_match('!<a href="[^"]+/text-0.txt" data-insert-type="file">text-0.txt</a>!', $body_value), 'Verified inserted HTML: "' . $body_value . '"');
}