You are here

public function InsertImageTest::testRotationWithAbsoluteUrl in Insert 8.2

File

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

Class

InsertImageTest
Tests Insert module's image insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testRotationWithAbsoluteUrl() {
  $page = $this
    ->gotoInsertConfig();
  $page
    ->checkField('absolute');
  $this
    ->saveInsertConfig($page);
  $fieldNames = [
    strtolower($this
      ->randomMachineName()),
    strtolower($this
      ->randomMachineName()),
  ];
  $this
    ->createImageField($fieldNames[0], [
    'alt_field' => '0',
  ]);
  $this
    ->createImageField($fieldNames[1], [
    'alt_field' => '0',
  ]);
  $this
    ->updateInsertSettings($fieldNames[0], [
    'styles' => [
      'thumbnail' => 'thumbnail',
    ],
    'default' => 'image',
    'rotate' => '1',
  ]);
  $this
    ->updateInsertSettings($fieldNames[1], [
    'styles' => [
      'thumbnail' => 'thumbnail',
    ],
    'default' => 'thumbnail',
    'rotate' => '1',
  ]);
  $files = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $fieldNames[0] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $page
    ->attachFileToField('files[' . $fieldNames[1] . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldNames[0] . '[0][fids]');
  $this
    ->assertSession()
    ->waitForField($fieldNames[1] . '[0][fids]');
  $body = $page
    ->findField('body[0][value]');
  $wrappers = [
    $page
      ->find('css', '#edit-' . $fieldNames[0] . '-wrapper'),
    $page
      ->find('css', '#edit-' . $fieldNames[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());
}