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