Mercurial > hg > isophonics-drupal-site
comparison core/modules/jsonapi/tests/src/Functional/MessageTest.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\jsonapi\Functional; | |
4 | |
5 use Drupal\Component\Utility\NestedArray; | |
6 use Drupal\contact\Entity\ContactForm; | |
7 use Drupal\contact\Entity\Message; | |
8 use Drupal\Core\Url; | |
9 use GuzzleHttp\RequestOptions; | |
10 use Symfony\Component\Routing\Exception\RouteNotFoundException; | |
11 | |
12 /** | |
13 * JSON:API integration test for the "Message" content entity type. | |
14 * | |
15 * @group jsonapi | |
16 */ | |
17 class MessageTest extends ResourceTestBase { | |
18 | |
19 /** | |
20 * {@inheritdoc} | |
21 */ | |
22 public static $modules = ['contact']; | |
23 | |
24 /** | |
25 * {@inheritdoc} | |
26 */ | |
27 protected static $entityTypeId = 'contact_message'; | |
28 | |
29 /** | |
30 * {@inheritdoc} | |
31 */ | |
32 protected static $resourceTypeName = 'contact_message--camelids'; | |
33 | |
34 /** | |
35 * {@inheritdoc} | |
36 * | |
37 * @var \Drupal\contact\MessageInterface | |
38 */ | |
39 protected $entity; | |
40 | |
41 /** | |
42 * {@inheritdoc} | |
43 */ | |
44 protected static $labelFieldName = 'subject'; | |
45 | |
46 /** | |
47 * {@inheritdoc} | |
48 */ | |
49 protected function setUpAuthorization($method) { | |
50 $this->grantPermissionsToTestedRole(['access site-wide contact form']); | |
51 } | |
52 | |
53 /** | |
54 * {@inheritdoc} | |
55 */ | |
56 protected function createEntity() { | |
57 if (!ContactForm::load('camelids')) { | |
58 // Create a "Camelids" contact form. | |
59 ContactForm::create([ | |
60 'id' => 'camelids', | |
61 'label' => 'Llama', | |
62 'message' => 'Let us know what you think about llamas', | |
63 'reply' => 'Llamas are indeed awesome!', | |
64 'recipients' => [ | |
65 'llama@example.com', | |
66 'contact@example.com', | |
67 ], | |
68 ])->save(); | |
69 } | |
70 | |
71 $message = Message::create([ | |
72 'contact_form' => 'camelids', | |
73 'subject' => 'Llama Gabilondo', | |
74 'message' => 'Llamas are awesome!', | |
75 ]); | |
76 $message->save(); | |
77 | |
78 return $message; | |
79 } | |
80 | |
81 /** | |
82 * {@inheritdoc} | |
83 */ | |
84 protected function getExpectedDocument() { | |
85 throw new \Exception('Not yet supported.'); | |
86 } | |
87 | |
88 /** | |
89 * {@inheritdoc} | |
90 */ | |
91 protected function getPostDocument() { | |
92 return [ | |
93 'data' => [ | |
94 'type' => 'contact_message--camelids', | |
95 'attributes' => [ | |
96 'subject' => 'Dramallama', | |
97 'message' => 'http://www.urbandictionary.com/define.php?term=drama%20llama', | |
98 ], | |
99 ], | |
100 ]; | |
101 } | |
102 | |
103 /** | |
104 * {@inheritdoc} | |
105 */ | |
106 protected function getExpectedUnauthorizedAccessMessage($method) { | |
107 if ($method === 'POST') { | |
108 return "The 'access site-wide contact form' permission is required."; | |
109 } | |
110 return parent::getExpectedUnauthorizedAccessMessage($method); | |
111 } | |
112 | |
113 /** | |
114 * {@inheritdoc} | |
115 */ | |
116 public function testGetIndividual() { | |
117 // Contact Message entities are not stored, so they cannot be retrieved. | |
118 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); | |
119 | |
120 Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); | |
121 } | |
122 | |
123 /** | |
124 * {@inheritdoc} | |
125 */ | |
126 public function testPatchIndividual() { | |
127 // Contact Message entities are not stored, so they cannot be modified. | |
128 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); | |
129 | |
130 Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); | |
131 } | |
132 | |
133 /** | |
134 * {@inheritdoc} | |
135 */ | |
136 public function testDeleteIndividual() { | |
137 // Contact Message entities are not stored, so they cannot be deleted. | |
138 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); | |
139 | |
140 Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); | |
141 } | |
142 | |
143 /** | |
144 * {@inheritdoc} | |
145 */ | |
146 public function testRelated() { | |
147 // Contact Message entities are not stored, so they cannot be retrieved. | |
148 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.related" does not exist.'); | |
149 | |
150 Url::fromRoute('jsonapi.contact_message--camelids.related')->toString(TRUE); | |
151 } | |
152 | |
153 /** | |
154 * {@inheritdoc} | |
155 */ | |
156 public function testRelationships() { | |
157 // Contact Message entities are not stored, so they cannot be retrieved. | |
158 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.relationship.get" does not exist.'); | |
159 | |
160 Url::fromRoute('jsonapi.contact_message--camelids.relationship.get')->toString(TRUE); | |
161 } | |
162 | |
163 /** | |
164 * {@inheritdoc} | |
165 */ | |
166 public function testCollection() { | |
167 $collection_url = Url::fromRoute('jsonapi.contact_message--camelids.collection.post')->setAbsolute(TRUE); | |
168 $request_options = []; | |
169 $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json'; | |
170 $request_options = NestedArray::mergeDeep($request_options, $this->getAuthenticationRequestOptions()); | |
171 | |
172 // 405 because Message entities are not stored, so they cannot be retrieved, | |
173 // yet the same URL can be used to POST them. | |
174 $response = $this->request('GET', $collection_url, $request_options); | |
175 $this->assertSame(405, $response->getStatusCode()); | |
176 $this->assertSame(['POST'], $response->getHeader('Allow')); | |
177 } | |
178 | |
179 /** | |
180 * {@inheritdoc} | |
181 */ | |
182 public function testRevisions() { | |
183 // Contact Message entities are not stored, so they cannot be retrieved. | |
184 $this->setExpectedException(RouteNotFoundException::class, 'Route "jsonapi.contact_message--camelids.individual" does not exist.'); | |
185 | |
186 Url::fromRoute('jsonapi.contact_message--camelids.individual')->toString(TRUE); | |
187 } | |
188 | |
189 } |