You are here

public function InsertImageWidgetTest::testRotationWithAbsoluteUrl in Insert 8

File

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

Class

InsertImageWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testRotationWithAbsoluteUrl() {
  $field_names = [
    strtolower($this
      ->randomMachineName()),
    strtolower($this
      ->randomMachineName()),
  ];
  $this
    ->createImageField($field_names[0], 'article', [], [
    'alt_field' => '0',
  ], [
    'insert_default' => 'image',
    'insert_absolute' => '1',
    'insert_rotate' => '1',
  ]);
  $this
    ->createImageField($field_names[1], 'article', [], [
    'alt_field' => '0',
  ], [
    'insert_default' => 'thumbnail',
    'insert_absolute' => '1',
    'insert_rotate' => '1',
  ]);
  $files = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_names[0] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $page
    ->attachFileToField('files[' . $field_names[1] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_names[0] . '[0][fids]');
  $this
    ->assertSession()
    ->waitForField($field_names[1] . '[0][fids]');
  $body = $page
    ->find('css', '#edit-body-0-value');
  $wrappers = [
    $page
      ->find('css', '#edit-' . $field_names[0] . '-wrapper'),
    $page
      ->find('css', '#edit-' . $field_names[1] . '-wrapper'),
  ];
  $wrappers[0]
    ->findButton('Insert')
    ->click();
  $this
    ->assertTrue(strpos($body
    ->getValue(), '<img src="http') !== FALSE, 'Verified absolute path: ' . $body
    ->getValue());
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="40"') !== FALSE && strpos($body
    ->getValue(), 'height="20"') !== FALSE, 'Verified default dimension attributes: ' . $body
    ->getValue());
  $wrappers[0]
    ->findLink('↺')
    ->click();
  $body
    ->waitFor(20, function ($element) {

    /** @var \Behat\Mink\Element\NodeElement $element */
    return strpos($element
      ->getValue(), 'width="20"') !== FALSE;
  });
  $this
    ->assertTrue(strpos($body
    ->getValue(), '<img src="http') !== FALSE, 'Verified absolute path after rotating: ' . $body
    ->getValue());
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="20"') !== FALSE && strpos($body
    ->getValue(), 'height="40"') !== FALSE, 'Switched dimension attributes: ' . $body
    ->getValue());
  $body
    ->setValue('');
  $wrappers[1]
    ->findButton('Insert')
    ->click();
  $this
    ->assertTrue(strpos($body
    ->getValue(), '<img src="http') !== FALSE, 'Styled image - verified absolute path on: ' . $body
    ->getValue());
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="40"') !== FALSE && strpos($body
    ->getValue(), 'height="20"') !== FALSE, 'Styled image - verified default dimension attributes: ' . $body
    ->getValue());
  $wrappers[1]
    ->findLink('↺')
    ->click();
  $body
    ->waitFor(20, function ($element) {

    /** @var \Behat\Mink\Element\NodeElement $element */
    return strpos($element
      ->getValue(), 'width="20"') !== FALSE;
  });
  $this
    ->assertTrue(strpos($body
    ->getValue(), '<img src="http') !== FALSE, 'Styled image - verified absolute path after rotating: ' . $body
    ->getValue());
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="20"') !== FALSE && strpos($body
    ->getValue(), 'height="40"') !== FALSE, 'Styled image - switched dimension attributes: ' . $body
    ->getValue());
}