You are here

public function InsertImageTest::testUpdatingTitleAttribute in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertImageTest.php, line 479

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

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