3 namespace Drupal\Tests\crop\Kernel;
5 use Drupal\Core\StreamWrapper\PublicStream;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests the crop entity CRUD operations.
11 abstract class CropUnitTestBase extends KernelTestBase {
16 * @var \Drupal\crop\CropStorageInterface
18 protected $cropStorage;
21 * The file storage service.
23 * @var \Drupal\Core\Entity\EntityStorageInterface
25 protected $fileStorage;
30 * @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
32 protected $cropTypeStorage;
35 * The image style storage.
37 * @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
39 protected $imageStyleStorage;
44 * @var \Drupal\image\ImageStyleInterface
51 * @var \Drupal\crop\CropInterface
56 * The image effect manager.
58 * @var \Drupal\image\ImageEffectManager
60 protected $imageEffectManager;
65 protected function setUp() {
68 /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
69 $entity_type_manager = $this->container->get('entity_type.manager');
70 $this->cropStorage = $entity_type_manager->getStorage('crop');
71 $this->cropTypeStorage = $entity_type_manager->getStorage('crop_type');
72 $this->imageStyleStorage = $entity_type_manager->getStorage('image_style');
73 $this->fileStorage = $entity_type_manager->getStorage('file');
74 $this->imageEffectManager = $this->container->get('plugin.manager.image.effect');
77 /** @var \Drupal\Core\Entity\EntityTypeListenerInterface $entity_type_listener */
78 $entity_type_listener = $this->container->get('entity_type.listener');
79 $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('user'));
80 $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('image_style'));
81 $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('crop'));
82 $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('file'));
84 // Create test image style.
85 $uuid = $this->container->get('uuid')->generate();
86 $this->testStyle = $this->imageStyleStorage->create([
88 'label' => 'Test image style',
92 'data' => ['crop_type' => 'test_type'],
98 $this->testStyle->save();
100 // Create test crop type.
101 $this->cropType = $this->cropTypeStorage->create([
103 'label' => 'Test crop type',
104 'description' => 'Some nice desc.',
106 $this->cropType->save();
110 * Creates and gets test image file.
112 * @return \Drupal\file\FileInterface
115 protected function getTestFile() {
116 file_unmanaged_copy(drupal_get_path('module', 'crop') . '/tests/files/sarajevo.png', PublicStream::basePath());
117 return $this->fileStorage->create([
118 'uri' => 'public://sarajevo.png',
119 'status' => FILE_STATUS_PERMANENT,