You are here

public function InsertImageTest::testAlign in Insert 8.2

File

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

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testAlign() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($fieldName, [
    'alt_field' => '0',
  ]);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'image' => 'image',
    ],
    'default' => 'image',
    'align' => TRUE,
  ]);
  $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]');
  $page
    ->findButton('Insert')
    ->click();
  $this
    ->assertEquals(1, preg_match('!data-align="none"[^>]*>$!', $body
    ->getValue()), 'Verified initial align attribute: ' . $body
    ->getValue());
  $elements = $page
    ->findAll('css', '.insert-align-controls input');
  end($elements)
    ->click();
  $this
    ->assertEquals(1, preg_match('!data-align="right"[^>]*>$!', $body
    ->getValue()), 'Verified altering align attribute: ' . $body
    ->getValue());
  $page
    ->findField('title[0][value]')
    ->setValue('title');
  $page
    ->findButton('Save')
    ->click();
  $this
    ->drupalGet('node/1/edit');
  $this
    ->assertEquals('right', $page
    ->find('css', '.insert-align-controls input:checked')
    ->getValue(), 'Verified align attribute after reloading form: ' . $body
    ->getValue());
  $page
    ->find('css', '.insert-align-controls input')
    ->click();
  $this
    ->assertEquals(1, preg_match('!data-align="none"[^>]*>$!', $body
    ->getValue()), 'Verified reset align attribute: ' . $body
    ->getValue());
}