CropUnitTestBase.php in Crop API 8
File
tests/src/Kernel/CropUnitTestBase.php
View source
<?php
namespace Drupal\Tests\crop\Kernel;
use Drupal\Core\StreamWrapper\PublicStream;
use Drupal\KernelTests\KernelTestBase;
abstract class CropUnitTestBase extends KernelTestBase {
protected $cropStorage;
protected $fileStorage;
protected $cropTypeStorage;
protected $imageStyleStorage;
protected $testStyle;
protected $cropType;
protected $imageEffectManager;
protected function setUp() {
parent::setUp();
$entity_type_manager = $this->container
->get('entity_type.manager');
$this->cropStorage = $entity_type_manager
->getStorage('crop');
$this->cropTypeStorage = $entity_type_manager
->getStorage('crop_type');
$this->imageStyleStorage = $entity_type_manager
->getStorage('image_style');
$this->fileStorage = $entity_type_manager
->getStorage('file');
$this->imageEffectManager = $this->container
->get('plugin.manager.image.effect');
$entity_type_listener = $this->container
->get('entity_type.listener');
$entity_type_listener
->onEntityTypeCreate($entity_type_manager
->getDefinition('user'));
$entity_type_listener
->onEntityTypeCreate($entity_type_manager
->getDefinition('image_style'));
$entity_type_listener
->onEntityTypeCreate($entity_type_manager
->getDefinition('crop'));
$entity_type_listener
->onEntityTypeCreate($entity_type_manager
->getDefinition('file'));
$uuid = $this->container
->get('uuid')
->generate();
$this->testStyle = $this->imageStyleStorage
->create([
'name' => 'test',
'label' => 'Test image style',
'effects' => [
$uuid => [
'id' => 'crop_crop',
'data' => [
'crop_type' => 'test_type',
],
'weight' => 0,
'uuid' => $uuid,
],
],
]);
$this->testStyle
->save();
$this->cropType = $this->cropTypeStorage
->create([
'id' => 'test_type',
'label' => 'Test crop type',
'description' => 'Some nice desc.',
]);
$this->cropType
->save();
}
protected function getTestFile() {
file_unmanaged_copy(drupal_get_path('module', 'crop') . '/tests/files/sarajevo.png', PublicStream::basePath());
return $this->fileStorage
->create([
'uri' => 'public://sarajevo.png',
'status' => FILE_STATUS_PERMANENT,
]);
}
}