You are here

public function InsertImageWidgetTest::testUpdatingTitleAttribute in Insert 8

File

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

Class

InsertImageWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testUpdatingTitleAttribute() {
  $field_name = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($field_name, 'article', [], [
    'title_field' => '1',
  ], [
    'insert_default' => 'image',
    'insert_styles' => [
      'thumbnail' => 'thumbnail',
    ],
  ]);
  $images = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_name . '_0]', \Drupal::service('file_system')
    ->realpath($images[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_name . '[0][fids]');
  $body = $page
    ->findField('body[0][value]');
  $altField = $page
    ->findField($field_name . '[0][alt]');
  $titleField = $page
    ->findField($field_name . '[0][title]');
  $altField
    ->setValue('alt');
  $titleField
    ->setValue('initial');
  $page
    ->findButton('Insert')
    ->click();
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'title="initial"') !== FALSE, 'Verified initial string set on title attribute: ' . $body
    ->getValue());
  $titleField
    ->setValue('altered');
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'title="altered"') !== FALSE, 'Verified altered string set on title attribute: ' . $body
    ->getValue());
}