You are here

public function InsertImageCKEditorTest::testAlign in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertImageCKEditorTest.php, line 77

Class

InsertImageCKEditorTest
Tests Insert module's functionality on CKEditor instances.

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]');
  $page
    ->findButton('Insert')
    ->click();
  $alignQuery = 'CKEDITOR.instances["edit-body-0-value"].widgets.instances[0].data.align';
  $align = $this
    ->getSession()
    ->evaluateScript($alignQuery);
  $this
    ->assertEquals('none', $align, 'Verified initial align attribute: ' . $align);
  $elements = $page
    ->findAll('css', '.insert-align-controls input');
  end($elements)
    ->click();
  $align = $this
    ->getSession()
    ->evaluateScript($alignQuery);
  $this
    ->assertEquals('right', $align, 'Verified altering align attribute: ' . $align);
  $page
    ->findField('title[0][value]')
    ->setValue('title');
  $page
    ->findButton('Save')
    ->click();
  $this
    ->drupalGet('node/1/edit');
  $align = $this
    ->getSession()
    ->evaluateScript($alignQuery);
  $this
    ->assertEquals('right', $align, 'Verified align attribute after reloading form of saved node: ' . $align);
  $page
    ->find('css', '.insert-align-controls input')
    ->click();
  $align = $this
    ->getSession()
    ->evaluateScript($alignQuery);
  $this
    ->assertEquals('none', $align, 'Verified reset align attribute: ' . $align);
}