You are here

public function MediaImageModifyTest::testFocalPointChange in Thunder 8.2

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

Test Focal Point change.

File

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

Class

MediaImageModifyTest
Tests the Image media modification.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testFocalPointChange() {

  // Media ID used for testing.
  $mediaId = 9;
  $this
    ->drupalGet("media/{$mediaId}/edit");
  $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 = Media::load($mediaId);
  $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();
}