Added missing modules, including some as submodules.
[yaffs-website] / web / modules / contrib / crop / tests / src / Kernel / CropUnitTestBase.php
1 <?php
2
3 namespace Drupal\Tests\crop\Kernel;
4
5 use Drupal\Core\StreamWrapper\PublicStream;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests the crop entity CRUD operations.
10  */
11 abstract class CropUnitTestBase extends KernelTestBase {
12
13   /**
14    * The crop storage.
15    *
16    * @var \Drupal\crop\CropStorageInterface
17    */
18   protected $cropStorage;
19
20   /**
21    * The file storage service.
22    *
23    * @var \Drupal\Core\Entity\EntityStorageInterface
24    */
25   protected $fileStorage;
26
27   /**
28    * The crop storage.
29    *
30    * @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
31    */
32   protected $cropTypeStorage;
33
34   /**
35    * The image style storage.
36    *
37    * @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface
38    */
39   protected $imageStyleStorage;
40
41   /**
42    * Test image style.
43    *
44    * @var \Drupal\image\ImageStyleInterface
45    */
46   protected $testStyle;
47
48   /**
49    * Test crop type.
50    *
51    * @var \Drupal\crop\CropInterface
52    */
53   protected $cropType;
54
55   /**
56    * The image effect manager.
57    *
58    * @var \Drupal\image\ImageEffectManager
59    */
60   protected $imageEffectManager;
61
62   /**
63    * {@inheritdoc}
64    */
65   protected function setUp() {
66     parent::setUp();
67
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');
75
76     // Create DB schemas.
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'));
83
84     // Create test image style.
85     $uuid = $this->container->get('uuid')->generate();
86     $this->testStyle = $this->imageStyleStorage->create([
87       'name' => 'test',
88       'label' => 'Test image style',
89       'effects' => [
90         $uuid => [
91           'id' => 'crop_crop',
92           'data' => ['crop_type' => 'test_type'],
93           'weight' => 0,
94           'uuid' => $uuid,
95         ],
96       ],
97     ]);
98     $this->testStyle->save();
99
100     // Create test crop type.
101     $this->cropType = $this->cropTypeStorage->create([
102       'id' => 'test_type',
103       'label' => 'Test crop type',
104       'description' => 'Some nice desc.',
105     ]);
106     $this->cropType->save();
107   }
108
109   /**
110    * Creates and gets test image file.
111    *
112    * @return \Drupal\file\FileInterface
113    *   File object.
114    */
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,
120     ]);
121   }
122
123 }