You are here

public function FocalPointManagerTest::testSaveCropEntity in Focal Point 8

Save Crop Entity.

@covers ::saveCropEntity

File

tests/src/Unit/FocalPointManagerTest.php, line 150

Class

FocalPointManagerTest
@coversDefaultClass \Drupal\focal_point\FocalPointManager

Namespace

Drupal\Tests\focal_point\Unit

Code

public function testSaveCropEntity() {

  // Test that crop is saved when focal point value has changed.
  $crop = $this
    ->prophesize(CropInterface::class);
  $crop
    ->anchor()
    ->willReturn([
    'x' => 50,
    'y' => 50,
  ])
    ->shouldBeCalledTimes(1);
  $crop
    ->setPosition(20, 20)
    ->willReturn($crop
    ->reveal())
    ->shouldBeCalledTimes(1);
  $crop
    ->save()
    ->willReturn($crop
    ->reveal())
    ->shouldBeCalledTimes(1);
  $this->focalPointManager
    ->saveCropEntity(10, 10, 200, 200, $crop
    ->reveal());

  // Test that crop is not saved when focal point value is unchanged.
  $crop = $this
    ->prophesize(CropInterface::class);
  $crop
    ->anchor()
    ->willReturn([
    'x' => 20,
    'y' => 20,
  ])
    ->shouldBeCalledTimes(1);
  $crop
    ->setPosition()
    ->willReturn($crop
    ->reveal())
    ->shouldBeCalledTimes(0);
  $crop
    ->save()
    ->willReturn($crop
    ->reveal())
    ->shouldBeCalledTimes(0);
  $this->focalPointManager
    ->saveCropEntity(10, 10, 200, 200, $crop
    ->reveal());
}