Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/MenuLinkContentTest.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\jsonapi\Functional; | |
4 | |
5 use Drupal\Core\Url; | |
6 use Drupal\menu_link_content\Entity\MenuLinkContent; | |
7 use Drupal\Tests\jsonapi\Traits\CommonCollectionFilterAccessTestPatternsTrait; | |
8 | |
9 /** | |
10 * JSON:API integration test for the "MenuLinkContent" content entity type. | |
11 * | |
12 * @group jsonapi | |
13 */ | |
14 class MenuLinkContentTest extends ResourceTestBase { | |
15 | |
16 use CommonCollectionFilterAccessTestPatternsTrait; | |
17 | |
18 /** | |
19 * {@inheritdoc} | |
20 */ | |
21 public static $modules = ['menu_link_content']; | |
22 | |
23 /** | |
24 * {@inheritdoc} | |
25 */ | |
26 protected static $entityTypeId = 'menu_link_content'; | |
27 | |
28 /** | |
29 * {@inheritdoc} | |
30 */ | |
31 protected static $resourceTypeName = 'menu_link_content--menu_link_content'; | |
32 | |
33 /** | |
34 * {@inheritdoc} | |
35 * | |
36 * @var \Drupal\menu_link_content\MenuLinkContentInterface | |
37 */ | |
38 protected $entity; | |
39 | |
40 /** | |
41 * {@inheritdoc} | |
42 */ | |
43 protected static $patchProtectedFieldNames = [ | |
44 'changed' => NULL, | |
45 ]; | |
46 | |
47 /** | |
48 * {@inheritdoc} | |
49 */ | |
50 protected function setUpAuthorization($method) { | |
51 $this->grantPermissionsToTestedRole(['administer menu']); | |
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 getExpectedDocument() { | |
75 $self_url = Url::fromUri('base:/jsonapi/menu_link_content/menu_link_content/' . $this->entity->uuid())->setAbsolute()->toString(TRUE)->getGeneratedUrl(); | |
76 return [ | |
77 'jsonapi' => [ | |
78 'meta' => [ | |
79 'links' => [ | |
80 'self' => ['href' => 'http://jsonapi.org/format/1.0/'], | |
81 ], | |
82 ], | |
83 'version' => '1.0', | |
84 ], | |
85 'links' => [ | |
86 'self' => ['href' => $self_url], | |
87 ], | |
88 'data' => [ | |
89 'id' => $this->entity->uuid(), | |
90 'type' => 'menu_link_content--menu_link_content', | |
91 'links' => [ | |
92 'self' => ['href' => $self_url], | |
93 ], | |
94 'attributes' => [ | |
95 'bundle' => 'menu_link_content', | |
96 'link' => [ | |
97 'uri' => 'https://nl.wikipedia.org/wiki/Llama', | |
98 'title' => NULL, | |
99 'options' => [], | |
100 ], | |
101 'changed' => (new \DateTime())->setTimestamp($this->entity->getChangedTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), | |
102 'default_langcode' => TRUE, | |
103 'description' => 'Llama Gabilondo', | |
104 'enabled' => TRUE, | |
105 'expanded' => FALSE, | |
106 'external' => FALSE, | |
107 'langcode' => 'en', | |
108 'menu_name' => 'main', | |
109 'parent' => NULL, | |
110 'rediscover' => FALSE, | |
111 'title' => 'Llama Gabilondo', | |
112 'weight' => 0, | |
113 'drupal_internal__id' => 1, | |
114 'drupal_internal__revision_id' => 1, | |
115 'revision_created' => (new \DateTime())->setTimestamp($this->entity->getRevisionCreationTime())->setTimezone(new \DateTimeZone('UTC'))->format(\DateTime::RFC3339), | |
116 'revision_log_message' => NULL, | |
117 // @todo Attempt to remove this in https://www.drupal.org/project/drupal/issues/2933518. | |
118 'revision_translation_affected' => TRUE, | |
119 ], | |
120 'relationships' => [ | |
121 'revision_user' => [ | |
122 'data' => NULL, | |
123 'links' => [ | |
124 'related' => [ | |
125 'href' => $self_url . '/revision_user', | |
126 ], | |
127 'self' => [ | |
128 'href' => $self_url . '/relationships/revision_user', | |
129 ], | |
130 ], | |
131 ], | |
132 ], | |
133 ], | |
134 ]; | |
135 } | |
136 | |
137 /** | |
138 * {@inheritdoc} | |
139 */ | |
140 protected function getPostDocument() { | |
141 return [ | |
142 'data' => [ | |
143 'type' => 'menu_link_content--menu_link_content', | |
144 'attributes' => [ | |
145 'title' => 'Dramallama', | |
146 'link' => [ | |
147 'uri' => 'http://www.urbandictionary.com/define.php?term=drama%20llama', | |
148 ], | |
149 ], | |
150 ], | |
151 ]; | |
152 } | |
153 | |
154 /** | |
155 * {@inheritdoc} | |
156 */ | |
157 protected function getExpectedUnauthorizedAccessMessage($method) { | |
158 switch ($method) { | |
159 case 'DELETE': | |
160 return "The 'administer menu' permission is required."; | |
161 | |
162 default: | |
163 return parent::getExpectedUnauthorizedAccessMessage($method); | |
164 } | |
165 } | |
166 | |
167 /** | |
168 * {@inheritdoc} | |
169 */ | |
170 public function testRelated() { | |
171 $this->markTestSkipped('Remove this in https://www.drupal.org/project/jsonapi/issues/2940339'); | |
172 } | |
173 | |
174 /** | |
175 * {@inheritdoc} | |
176 */ | |
177 public function testCollectionFilterAccess() { | |
178 $this->doTestCollectionFilterAccessBasedOnPermissions('title', 'administer menu'); | |
179 } | |
180 | |
181 } |