Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / rest / tests / src / Functional / EntityResource / MenuLinkContent / MenuLinkContentResourceTestBase.php
1 <?php
2
3 namespace Drupal\Tests\rest\Functional\EntityResource\MenuLinkContent;
4
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\Tests\rest\Functional\BcTimestampNormalizerUnixTestTrait;
7 use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase;
8
9 /**
10  * ResourceTestBase for MenuLinkContent entity.
11  */
12 abstract class MenuLinkContentResourceTestBase extends EntityResourceTestBase {
13
14   use BcTimestampNormalizerUnixTestTrait;
15
16   /**
17    * {@inheritdoc}
18    */
19   public static $modules = ['menu_link_content'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected static $entityTypeId = 'menu_link_content';
25
26   /**
27    * {@inheritdoc}
28    */
29   protected static $patchProtectedFieldNames = [
30     'changed',
31   ];
32
33   /**
34    * The MenuLinkContent entity.
35    *
36    * @var \Drupal\menu_link_content\MenuLinkContentInterface
37    */
38   protected $entity;
39
40   /**
41    * {@inheritdoc}
42    */
43   protected function setUpAuthorization($method) {
44     switch ($method) {
45       case 'GET':
46       case 'POST':
47       case 'PATCH':
48       case 'DELETE':
49         $this->grantPermissionsToTestedRole(['administer menu']);
50         break;
51     }
52   }
53
54   /**
55    * {@inheritdoc}
56    */
57   protected function createEntity() {
58     $menu_link = MenuLinkContent::create([
59       'id' => 'llama',
60       'title' => 'Llama Gabilondo',
61       'description' => 'Llama Gabilondo',
62       'link' => 'https://nl.wikipedia.org/wiki/Llama',
63       'weight' => 0,
64       'menu_name' => 'main',
65     ]);
66     $menu_link->save();
67
68     return $menu_link;
69   }
70
71   /**
72    * {@inheritdoc}
73    */
74   protected function getNormalizedPostEntity() {
75     return [
76       'title' => [
77         [
78           'value' => 'Dramallama',
79         ],
80       ],
81       'link' => [
82         [
83           'uri' => 'http://www.urbandictionary.com/define.php?term=drama%20llama',
84         ],
85       ],
86       'bundle' => [
87         [
88           'value' => 'menu_link_content',
89         ],
90       ],
91     ];
92   }
93
94   /**
95    * {@inheritdoc}
96    */
97   protected function getExpectedNormalizedEntity() {
98     return [
99       'uuid' => [
100         [
101           'value' => $this->entity->uuid(),
102         ],
103       ],
104       'id' => [
105         [
106           'value' => 1,
107         ],
108       ],
109       'title' => [
110         [
111           'value' => 'Llama Gabilondo',
112         ],
113       ],
114       'link' => [
115         [
116           'uri' => 'https://nl.wikipedia.org/wiki/Llama',
117           'title' => NULL,
118           'options' => [],
119         ],
120       ],
121       'weight' => [
122         [
123           'value' => 0,
124         ],
125       ],
126       'menu_name' => [
127         [
128           'value' => 'main',
129         ],
130       ],
131       'langcode' => [
132         [
133           'value' => 'en',
134         ],
135       ],
136       'bundle' => [
137         [
138           'value' => 'menu_link_content',
139         ],
140       ],
141       'description' => [
142         [
143           'value' => 'Llama Gabilondo',
144         ],
145       ],
146       'external' => [
147         [
148           'value' => FALSE,
149         ],
150       ],
151       'rediscover' => [
152         [
153           'value' => FALSE,
154         ],
155       ],
156       'expanded' => [
157         [
158           'value' => FALSE,
159         ],
160       ],
161       'enabled' => [
162         [
163           'value' => TRUE,
164         ],
165       ],
166       'changed' => [
167         $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()),
168       ],
169       'default_langcode' => [
170         [
171           'value' => TRUE,
172         ],
173       ],
174       'parent' => [],
175     ];
176   }
177
178   /**
179    * {@inheritdoc}
180    */
181   protected function getExpectedUnauthorizedAccessMessage($method) {
182     if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) {
183       return parent::getExpectedUnauthorizedAccessMessage($method);
184     }
185
186     switch ($method) {
187       case 'DELETE':
188         return "You are not authorized to delete this menu_link_content entity.";
189       default:
190         return parent::getExpectedUnauthorizedAccessMessage($method);
191     }
192   }
193
194 }