a2a84312b8ecc11ec09e0c29c87a0da6f6f45ec7
[yaffs-website] / web / core / modules / image / tests / src / Functional / Rest / ImageStyleResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\image\Functional\Rest;
4
5 use Drupal\image\Entity\ImageStyle;
6 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
7
8 /**
9  * ResourceTestBase for ImageStyle entity.
10  */
11 abstract class ImageStyleResourceTestBase extends EntityResourceTestBase {
12
13   /**
14    * {@inheritdoc}
15    */
16   public static $modules = ['image'];
17
18   /**
19    * {@inheritdoc}
20    */
21   protected static $entityTypeId = 'image_style';
22
23   /**
24    * The ImageStyle entity.
25    *
26    * @var \Drupal\image\ImageStyleInterface
27    */
28   protected $entity;
29
30   /**
31    * The effect UUID.
32    *
33    * @var string
34    */
35   protected $effectUuid;
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function setUpAuthorization($method) {
41     $this->grantPermissionsToTestedRole(['administer image styles']);
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   protected function createEntity() {
48     // Create a "Camelids" image style.
49     $camelids = ImageStyle::create([
50       'name' => 'camelids',
51       'label' => 'Camelids',
52     ]);
53
54     // Add an image effect.
55     $effect = [
56       'id' => 'image_scale_and_crop',
57       'data' => [
58         'anchor' => 'center-center',
59         'width' => 120,
60         'height' => 121,
61       ],
62       'weight' => 0,
63     ];
64     $this->effectUuid = $camelids->addImageEffect($effect);
65
66     $camelids->save();
67
68     return $camelids;
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   protected function getExpectedNormalizedEntity() {
75     return [
76       'dependencies' => [],
77       'effects' => [
78         $this->effectUuid => [
79           'uuid' => $this->effectUuid,
80           'id' => 'image_scale_and_crop',
81           'weight' => 0,
82           'data' => [
83             'anchor' => 'center-center',
84             'width' => 120,
85             'height' => 121,
86           ],
87         ],
88       ],
89       'label' => 'Camelids',
90       'langcode' => 'en',
91       'name' => 'camelids',
92       'status' => TRUE,
93       'uuid' => $this->entity->uuid(),
94     ];
95   }
96
97   /**
98    * {@inheritdoc}
99    */
100   protected function getNormalizedPostEntity() {
101     // @todo Update in https://www.drupal.org/node/2300677.
102   }
103
104   /**
105    * {@inheritdoc}
106    */
107   protected function getExpectedUnauthorizedAccessMessage($method) {
108     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
109       return parent::getExpectedUnauthorizedAccessMessage($method);
110     }
111
112     return "The 'administer image styles' permission is required.";
113   }
114
115 }