Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / ImageStyle / ImageStyleResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\ImageStyle;
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         'width' => 120,
59         'height' => 121,
60       ],
61       'weight' => 0,
62     ];
63     $this->effectUuid = $camelids->addImageEffect($effect);
64
65     $camelids->save();
66
67     return $camelids;
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   protected function getExpectedNormalizedEntity() {
74     return [
75       'dependencies' => [],
76       'effects' => [
77         $this->effectUuid => [
78           'uuid' => $this->effectUuid,
79           'id' => 'image_scale_and_crop',
80           'weight' => 0,
81           'data' => [
82             'width' => 120,
83             'height' => 121,
84           ],
85         ],
86       ],
87       'label' => 'Camelids',
88       'langcode' => 'en',
89       'name' => 'camelids',
90       'status' => TRUE,
91       'uuid' => $this->entity->uuid(),
92     ];
93   }
94
95   /**
96    * {@inheritdoc}
97    */
98   protected function getNormalizedPostEntity() {
99     // @todo Update in https://www.drupal.org/node/2300677.
100   }
101
102   /**
103    * {@inheritdoc}
104    */
105   protected function getExpectedUnauthorizedAccessMessage($method) {
106     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
107       return parent::getExpectedUnauthorizedAccessMessage($method);
108     }
109
110     return "The 'administer image styles' permission is required.";
111   }
112
113 }