You are here

public function MediaImageModifyTest::testFocalPointChange in Thunder 6.1.x

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()
  2. 8.2 tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()
  3. 8.3 tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()
  4. 8.4 tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()
  5. 6.2.x tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()
  6. 6.0.x tests/src/FunctionalJavascript/MediaImageModifyTest.php \Drupal\Tests\thunder\FunctionalJavascript\MediaImageModifyTest::testFocalPointChange()

Test Focal Point change.

File

tests/src/FunctionalJavascript/MediaImageModifyTest.php, line 21

Class

MediaImageModifyTest
Tests the Image media modification.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testFocalPointChange() {
  $media = $this
    ->loadMediaByUuid('f5f7fc5d-b2b8-426a-adf3-ee6aff6379da');
  $this
    ->drupalGet($media
    ->toUrl('edit-form'));
  $this
    ->createScreenshot($this
    ->getScreenshotFolder() . '/MediaImageModifyTest_BeforeFocalPointChange_' . date('Ymd_His') . '.png');
  $this
    ->getSession()
    ->getDriver()
    ->executeScript('var e = new jQuery.Event("click"); e.offsetX = 48; e.offsetY = 15; jQuery(".focal-point-wrapper img").trigger(e);');
  $this
    ->createScreenshot($this
    ->getScreenshotFolder() . '/MediaImageModifyTest_AfterFocalPointChange_' . date('Ymd_His') . '.png');
  $this
    ->clickSave();
  $media = $this
    ->loadMediaByUuid('f5f7fc5d-b2b8-426a-adf3-ee6aff6379da');
  $img = $media
    ->get('field_image')->target_id;
  $file = File::load($img);
  $path = $file
    ->getFileUri();
  $derivativeUri = ImageStyle::load('teaser')
    ->buildUri($path);
  ImageStyle::load('teaser')
    ->createDerivative($path, $derivativeUri);
  $image1 = new \Imagick($derivativeUri);
  $image2 = new \Imagick(realpath(dirname(__FILE__) . '/../../fixtures/reference.jpg'));
  $result = $image1
    ->compareImages($image2, \Imagick::METRIC_MEANSQUAREERROR);
  $this
    ->assertTrue($result[1] < 0.01, 'Images are identical');
  $image1
    ->clear();
  $image2
    ->clear();
}