You are here

public function FocalPointEffectsTest::testGetOriginalFocalPoint in Focal Point 8

Test getting the original focal point.

@covers ::getOriginalFocalPoint

File

tests/src/Unit/Effects/FocalPointEffectsTest.php, line 134

Class

FocalPointEffectsTest
Tests the Focal Point image effects.

Namespace

Drupal\Tests\focal_point\Unit\Effects

Code

public function testGetOriginalFocalPoint() {
  $original_image = $this
    ->getTestImage(50, 50);

  // Create a instance of TestFocalPointEffectBase since we need to override
  // the getPreviewValue method.
  $logger = $this
    ->prophesize(LoggerInterface::class);
  $crop_storage = $this
    ->prophesize(CropStorageInterface::class);
  $immutable_config = $this
    ->prophesize(ImmutableConfig::class);
  $request = $this
    ->prophesize(Request::class);
  $effect = new TestFocalPointEffectBase([], 'plugin_id', [], $logger
    ->reveal(), $this->focalPointManager, $crop_storage
    ->reveal(), $immutable_config
    ->reveal(), $request
    ->reveal());
  $effect
    ->setOriginalImageSize($original_image
    ->getWidth(), $original_image
    ->getHeight());

  // Use reflection to test a private/protected method.
  $effect_reflection = new \ReflectionClass(TestFocalPointEffectBase::class);
  $method = $effect_reflection
    ->getMethod('getOriginalFocalPoint');
  $method
    ->setAccessible(TRUE);

  // Mock crop object.
  $expected = [
    'x' => 313,
    'y' => 404,
  ];
  $crop = $this
    ->prophesize(CropInterface::class);
  $crop
    ->position()
    ->willReturn($expected);

  // Non-preview.
  $this
    ->assertSame($expected, $method
    ->invokeArgs($effect, [
    $crop
      ->reveal(),
    $this->focalPointManager,
  ]));

  // Preview test.
  $query_string = '500x250';
  $expected = [
    'x' => 250,
    'y' => 125,
  ];
  $effect
    ->setPreviewValue($query_string);
  $this
    ->assertSame($expected, $method
    ->invokeArgs($effect, [
    $crop
      ->reveal(),
    $this->focalPointManager,
  ]));
}