You are here

public function InsertImageTest::testUpdatingAltAttributeRevisitingForm in Insert 8.2

File

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

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testUpdatingAltAttributeRevisitingForm() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($fieldName);
  $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]');
  $altField
    ->setValue('initial');
  $page
    ->findButton('Insert')
    ->click();
  $page
    ->findField('title[0][value]')
    ->setValue('title');
  $page
    ->findButton('Save')
    ->click();
  $this
    ->drupalGet('node/1/edit');
  $altField = $page
    ->findField($fieldName . '[0][alt]');
  $altField
    ->setValue('altered');
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'alt="altered"') !== FALSE, 'Verified altered string set on alt attribute: ' . $body
    ->getValue());
}