public function CropCRUDTest::testOrphanRemoval in Crop API 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/CropCRUDTest.php \Drupal\Tests\crop\Kernel\CropCRUDTest::testOrphanRemoval()
Tests automatic removal of orphaned crops.
File
- tests/
src/ Kernel/ CropCRUDTest.php, line 120
Class
- CropCRUDTest
- Tests the crop entity CRUD operations.
Namespace
Drupal\Tests\crop\KernelCode
public function testOrphanRemoval() {
$this
->installSchema('file', [
'file_usage',
]);
$file = $this
->getTestFile();
$file
->save();
$values = [
'type' => $this->cropType
->id(),
'entity_id' => $file
->id(),
'entity_type' => $file
->getEntityTypeId(),
'x' => '100',
'y' => '150',
'width' => '200',
'height' => '250',
];
/** @var \Drupal\crop\CropInterface $crop */
$crop = $this->cropStorage
->create($values);
$crop
->save();
// Check if the crop is automatically removed at file removal.
$file
->delete();
$crops = $this->cropStorage
->loadByProperties([
'uri' => $crop->uri->value,
]);
$this
->assertEquals([], $crops, 'Crop deleted correctly.');
}