public function CropEffectTest::testCropDimenssions in Crop API 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/CropEffectTest.php \Drupal\Tests\crop\Kernel\CropEffectTest::testCropDimenssions()
Test image crop effect dimensions.
File
- tests/
src/ Kernel/ CropEffectTest.php, line 68
Class
- CropEffectTest
- Tests the crop image effect.
Namespace
Drupal\Tests\crop\KernelCode
public function testCropDimenssions() {
// Create image to be cropped.
$file = $this
->getTestFile();
$file
->save();
$file_uri = $file
->getFileUri();
// Create crop.
$values = [
'type' => $this->cropType
->id(),
'entity_id' => $file
->id(),
'entity_type' => 'file',
'uri' => $file_uri,
'x' => '190',
'y' => '120',
'width' => '50',
'height' => '50',
];
$dimensions = [
'width' => 0,
'height' => 0,
];
/** @var \Drupal\crop\CropInterface $crop */
$crop = $this->container
->get('entity_type.manager')
->getStorage('crop')
->create($values);
$crop
->save();
/** @var $effect \Drupal\crop\Plugin\ImageEffect\CropEffect */
$effect = $this->imageEffectManager
->createInstance('crop_crop', [
'data' => [
'crop_type' => $this->cropType
->id(),
],
]);
$effect
->transformDimensions($dimensions, $file_uri);
$this
->assertEquals($crop
->size(), $dimensions, t('CropEffect::transformDimensions() transform image dimensions correctly.'));
}