You are here

public function InsertImageWidgetTest::testOriginalImageRotation in Insert 8

File

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

Class

InsertImageWidgetTest
@group insert

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testOriginalImageRotation() {
  $field_name = strtolower($this
    ->randomMachineName());
  $this
    ->createImageField($field_name, 'article', [], [
    'alt_field' => '0',
  ], [
    'insert_default' => 'image',
    'insert_rotate' => '1',
  ]);
  $images = $this
    ->drupalGetTestFiles('image');
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $page
    ->attachFileToField('files[' . $field_name . '_0]', \Drupal::service('file_system')
    ->realpath($images[0]->uri));
  $this
    ->assertSession()
    ->waitForField($field_name . '[0][fids]');
  $page
    ->findButton('Insert')
    ->click();
  $body = $page
    ->find('css', '#edit-body-0-value');
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="40"') !== FALSE && strpos($body
    ->getValue(), 'height="20"') !== FALSE, 'Verified default dimension attributes: ' . $body
    ->getValue());
  $page
    ->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(), 'width="20"') !== FALSE && strpos($body
    ->getValue(), 'height="40"') !== FALSE, 'Switched dimension attribute values: ' . $body
    ->getValue());
  $page
    ->findLink('↺')
    ->click();
  $body
    ->waitFor(20, function ($element) {

    /** @var \Behat\Mink\Element\NodeElement $element */
    return strpos($element
      ->getValue(), 'width="40"') !== FALSE;
  });
  $this
    ->assertTrue(strpos($body
    ->getValue(), 'width="40"') !== FALSE && strpos($body
    ->getValue(), 'height="20"') !== FALSE, 'Switched dimension attribute values again after rotating a second time: ' . $body
    ->getValue());
}