|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the Functional\ContentTypeTest class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @version //autogentag// |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional; |
|
12
|
|
|
|
|
13
|
|
|
use Buzz\Message\Response; |
|
14
|
|
|
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; |
|
15
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\ContentType; |
|
16
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\ContentTypeGroup; |
|
17
|
|
|
use eZ\Publish\Core\REST\Server\Values\ContentTypeGroupList; |
|
18
|
|
|
use eZ\Publish\Core\REST\Server\Values\ContentTypeInfoList; |
|
19
|
|
|
|
|
20
|
|
|
class ContentTypeTest extends RESTFunctionalTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
private static $createdContentTypeRemoteId; |
|
23
|
|
|
private static $createdContentTypeIdentifier; |
|
24
|
|
|
private static $updatedContentTypeGroupIdentifier; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @covers POST /content/typegroups |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function testCreateContentTypeGroup() |
|
30
|
|
|
{ |
|
31
|
|
|
$identifier = uniqid('test'); |
|
32
|
|
|
$body = <<< XML |
|
33
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
34
|
|
|
<ContentTypeGroupInput> |
|
35
|
|
|
<identifier>$identifier</identifier> |
|
36
|
|
|
</ContentTypeGroupInput> |
|
37
|
|
|
XML; |
|
38
|
|
|
$request = $this->createHttpRequest('POST', '/api/ezp/v2/content/typegroups', 'ContentTypeGroupInput+xml', 'ContentTypeGroup+json'); |
|
39
|
|
|
$request->setContent($body); |
|
40
|
|
|
$response = $this->sendHttpRequest($request); |
|
41
|
|
|
|
|
42
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
43
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
44
|
|
|
|
|
45
|
|
|
$href = $response->getHeader('Location'); |
|
46
|
|
|
$this->addCreatedElement($href); |
|
47
|
|
|
|
|
48
|
|
|
return $href; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @depends testCreateContentTypeGroup |
|
53
|
|
|
* @covers PATCH /content/typegroups/<contentTypeGroupId> |
|
54
|
|
|
* |
|
55
|
|
|
* @return string the updated content type href |
|
56
|
|
|
*/ |
|
57
|
|
|
public function testUpdateContentTypeGroup($contentTypeGroupHref) |
|
58
|
|
|
{ |
|
59
|
|
|
$identifier = uniqid('test'); |
|
60
|
|
|
$body = <<< XML |
|
61
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
62
|
|
|
<ContentTypeGroupInput> |
|
63
|
|
|
<identifier>$identifier</identifier> |
|
64
|
|
|
</ContentTypeGroupInput> |
|
65
|
|
|
XML; |
|
66
|
|
|
|
|
67
|
|
|
$request = $this->createHttpRequest('PATCH', $contentTypeGroupHref, 'ContentTypeGroupInput+xml', 'ContentTypeGroup+json'); |
|
68
|
|
|
$request->setContent($body); |
|
69
|
|
|
$response = $this->sendHttpRequest($request); |
|
70
|
|
|
|
|
71
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
72
|
|
|
|
|
73
|
|
|
self::$updatedContentTypeGroupIdentifier = $identifier; |
|
74
|
|
|
|
|
75
|
|
|
return $contentTypeGroupHref; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @depends testCreateContentTypeGroup |
|
80
|
|
|
* @returns string The created content type href |
|
81
|
|
|
* @covers POST /content/typegroups/<contentTypeGroupId>/types?publish=true |
|
82
|
|
|
* |
|
83
|
|
|
* @todo write test with full workflow (draft, edit, publish) |
|
84
|
|
|
*/ |
|
85
|
|
|
public function testCreateContentType($contentTypeGroupHref) |
|
86
|
|
|
{ |
|
87
|
|
|
$identifier = uniqid('test'); |
|
88
|
|
|
$remoteId = md5($identifier); |
|
89
|
|
|
$body = <<< XML |
|
90
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
91
|
|
|
<ContentTypeCreate> |
|
92
|
|
|
<identifier>$identifier</identifier> |
|
93
|
|
|
<names> |
|
94
|
|
|
<value languageCode="eng-GB">$identifier</value> |
|
95
|
|
|
</names> |
|
96
|
|
|
<remoteId>$remoteId</remoteId> |
|
97
|
|
|
<urlAliasSchema><title></urlAliasSchema> |
|
98
|
|
|
<nameSchema><title></nameSchema> |
|
99
|
|
|
<isContainer>true</isContainer> |
|
100
|
|
|
<mainLanguageCode>eng-GB</mainLanguageCode> |
|
101
|
|
|
<defaultAlwaysAvailable>true</defaultAlwaysAvailable> |
|
102
|
|
|
<defaultSortField>PATH</defaultSortField> |
|
103
|
|
|
<defaultSortOrder>ASC</defaultSortOrder> |
|
104
|
|
|
<FieldDefinitions> |
|
105
|
|
|
<FieldDefinition> |
|
106
|
|
|
<identifier>title</identifier> |
|
107
|
|
|
<fieldType>ezstring</fieldType> |
|
108
|
|
|
<fieldGroup>content</fieldGroup> |
|
109
|
|
|
<position>1</position> |
|
110
|
|
|
<isTranslatable>true</isTranslatable> |
|
111
|
|
|
<isRequired>true</isRequired> |
|
112
|
|
|
<isInfoCollector>false</isInfoCollector> |
|
113
|
|
|
<defaultValue>New Title</defaultValue> |
|
114
|
|
|
<isSearchable>true</isSearchable> |
|
115
|
|
|
<names> |
|
116
|
|
|
<value languageCode="eng-GB">Title</value> |
|
117
|
|
|
</names> |
|
118
|
|
|
<descriptions> |
|
119
|
|
|
<value languageCode="eng-GB">This is the title</value> |
|
120
|
|
|
</descriptions> |
|
121
|
|
|
</FieldDefinition> |
|
122
|
|
|
</FieldDefinitions> |
|
123
|
|
|
</ContentTypeCreate> |
|
124
|
|
|
XML; |
|
125
|
|
|
|
|
126
|
|
|
$request = $this->createHttpRequest( |
|
127
|
|
|
'POST', |
|
128
|
|
|
"$contentTypeGroupHref/types?publish=true", |
|
129
|
|
|
'ContentTypeCreate+xml', |
|
130
|
|
|
'ContentType+json' |
|
131
|
|
|
); |
|
132
|
|
|
$request->setContent($body); |
|
133
|
|
|
$response = $this->sendHttpRequest($request); |
|
134
|
|
|
|
|
135
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
136
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
137
|
|
|
|
|
138
|
|
|
$this->addCreatedElement($response->getHeader('Location')); |
|
139
|
|
|
|
|
140
|
|
|
self::$createdContentTypeIdentifier = $identifier; |
|
141
|
|
|
self::$createdContentTypeRemoteId = $remoteId; |
|
142
|
|
|
|
|
143
|
|
|
return $response->getHeader('Location'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @depends testCreateContentTypeGroup |
|
148
|
|
|
* @covers GET /content/typegroups/<contentTypeGroupId> |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $contentTypeGroupHref |
|
151
|
|
|
*/ |
|
152
|
|
|
public function testListContentTypesForGroup($contentTypeGroupHref) |
|
153
|
|
|
{ |
|
154
|
|
|
$response = $this->sendHttpRequest( |
|
155
|
|
|
$request = $this->createHttpRequest('GET', "$contentTypeGroupHref/types", '', 'ContentTypeInfoList+json') |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
159
|
|
|
|
|
160
|
|
|
$contentTypeInfoList = $this->parseContentTypeInfoListFromResponse($response); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
163
|
|
|
$response, |
|
164
|
|
|
array_merge( |
|
165
|
|
|
['content-type-group-' . $this->extractLastIdFromHref($contentTypeGroupHref)], |
|
166
|
|
|
array_map( |
|
167
|
|
|
function (ContentType $contentType) { |
|
168
|
|
|
return 'content-type-' . $contentType->id; |
|
169
|
|
|
}, |
|
170
|
|
|
$contentTypeInfoList->contentTypes |
|
171
|
|
|
) |
|
172
|
|
|
) |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @covers GET /content/typegroups |
|
178
|
|
|
*/ |
|
179
|
|
|
public function testLoadContentTypeGroupList() |
|
180
|
|
|
{ |
|
181
|
|
|
$response = $this->sendHttpRequest( |
|
182
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/typegroups', '', 'ContentTypeGroupList+json') |
|
183
|
|
|
); |
|
184
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
185
|
|
|
|
|
186
|
|
|
$contentTypeGroupList = $this->parseContentTypeGroupListFromResponse($response); |
|
187
|
|
|
|
|
188
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
189
|
|
|
$response, |
|
190
|
|
|
array_map( |
|
191
|
|
|
function (ContentTypeGroup $contentTypeGroup) { |
|
192
|
|
|
return 'content-type-group-' . $contentTypeGroup->id; |
|
193
|
|
|
}, |
|
194
|
|
|
$contentTypeGroupList->contentTypeGroups |
|
195
|
|
|
) |
|
196
|
|
|
); |
|
197
|
|
|
|
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @depends testUpdateContentTypeGroup |
|
202
|
|
|
* @covers GET /content/typegroups?identifier=<contentTypeGroupIdentifier> |
|
203
|
|
|
*/ |
|
204
|
|
|
public function testLoadContentTypeGroupListWithIdentifier() |
|
205
|
|
|
{ |
|
206
|
|
|
$response = $this->sendHttpRequest( |
|
207
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/typegroups?identifier=' . self::$updatedContentTypeGroupIdentifier) |
|
208
|
|
|
); |
|
209
|
|
|
// @todo Check if list filtered by identifier is supposed to send a 307 |
|
210
|
|
|
self::assertHttpResponseCodeEquals($response, 307); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* @depends testUpdateContentTypeGroup |
|
215
|
|
|
* @covers GET /content/typegroups/<contentTypeGroupId> |
|
216
|
|
|
* |
|
217
|
|
|
* @param string $contentTypeGroupHref |
|
218
|
|
|
*/ |
|
219
|
|
View Code Duplication |
public function testLoadContentTypeGroup($contentTypeGroupHref) |
|
220
|
|
|
{ |
|
221
|
|
|
$response = $this->sendHttpRequest( |
|
222
|
|
|
$this->createHttpRequest('GET', $contentTypeGroupHref) |
|
223
|
|
|
); |
|
224
|
|
|
|
|
225
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
226
|
|
|
|
|
227
|
|
|
$contentTypeGroup = $this->parseContentTypeGroupFromResponse($response); |
|
228
|
|
|
|
|
229
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
230
|
|
|
$response, |
|
231
|
|
|
['content-type-group' => $contentTypeGroup->id] |
|
232
|
|
|
); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
/** |
|
236
|
|
|
* @depends testUpdateContentTypeGroup |
|
237
|
|
|
* @covers GET /content/typegroups/<contentTypeGroupId> |
|
238
|
|
|
* |
|
239
|
|
|
* @param string $contentTypeGroupHref |
|
240
|
|
|
*/ |
|
241
|
|
|
public function testLoadContentTypeGroupNotFound($contentTypeGroupHref) |
|
242
|
|
|
{ |
|
243
|
|
|
$response = $this->sendHttpRequest( |
|
244
|
|
|
$this->createHttpRequest('GET', "{$contentTypeGroupHref}1234") |
|
245
|
|
|
); |
|
246
|
|
|
|
|
247
|
|
|
self::assertHttpResponseCodeEquals($response, 404); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @depends testCreateContentType |
|
252
|
|
|
* @covers GET /content/types/<contentTypeId> |
|
253
|
|
|
*/ |
|
254
|
|
View Code Duplication |
public function testLoadContentType($contentTypeHref) |
|
255
|
|
|
{ |
|
256
|
|
|
$response = $this->sendHttpRequest( |
|
257
|
|
|
$this->createHttpRequest('GET', $contentTypeHref) |
|
258
|
|
|
); |
|
259
|
|
|
|
|
260
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
261
|
|
|
|
|
262
|
|
|
$contentType = $this->parseContentTypeFromResponse($response); |
|
263
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
264
|
|
|
$response, |
|
265
|
|
|
[ |
|
266
|
|
|
'content-type' => $contentType->id, |
|
267
|
|
|
'content-type-group' => $contentType->contentTypeGroups[0]->id, |
|
268
|
|
|
] |
|
269
|
|
|
); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @depends testCreateContentType |
|
274
|
|
|
* @covers GET /content/types/<contentTypeId> |
|
275
|
|
|
*/ |
|
276
|
|
|
public function testLoadContentTypeNotFound($contentTypeHref) |
|
277
|
|
|
{ |
|
278
|
|
|
$response = $this->sendHttpRequest( |
|
279
|
|
|
$this->createHttpRequest('GET', "{$contentTypeHref}1234") |
|
280
|
|
|
); |
|
281
|
|
|
|
|
282
|
|
|
self::assertHttpResponseCodeEquals($response, 404); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* @depends testCreateContentType |
|
287
|
|
|
* @covers GET /content/types |
|
288
|
|
|
*/ |
|
289
|
|
|
public function testListContentTypes() |
|
290
|
|
|
{ |
|
291
|
|
|
$response = $this->sendHttpRequest( |
|
292
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/types') |
|
293
|
|
|
); |
|
294
|
|
|
|
|
295
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
296
|
|
|
|
|
297
|
|
|
$this->parseContentTypeListFromRespose($response); |
|
|
|
|
|
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* @depends testCreateContentType |
|
302
|
|
|
* @covers GET /content/types?identifier=<contentTypeIdentifier> |
|
303
|
|
|
*/ |
|
304
|
|
|
public function testListContentTypesByIdentifier() |
|
305
|
|
|
{ |
|
306
|
|
|
$response = $this->sendHttpRequest( |
|
307
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/types?identifier=' . self::$createdContentTypeIdentifier) |
|
308
|
|
|
); |
|
309
|
|
|
|
|
310
|
|
|
// @todo This isn't consistent with the behaviour of /content/typegroups?identifier= |
|
311
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
312
|
|
|
|
|
313
|
|
|
$contentTypeList = $this->parseContentTypeListFromRespose($response); |
|
|
|
|
|
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* @depends testCreateContentType |
|
318
|
|
|
* @covers GET /content/types?remoteid=<contentTypeRemoteId> |
|
319
|
|
|
*/ |
|
320
|
|
|
public function testListContentTypesByRemoteId() |
|
321
|
|
|
{ |
|
322
|
|
|
$response = $this->sendHttpRequest( |
|
323
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/types?remoteId=' . self::$createdContentTypeRemoteId) |
|
324
|
|
|
); |
|
325
|
|
|
|
|
326
|
|
|
// @todo This isn't consistent with the behaviour of /content/typegroups?identifier= |
|
327
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
328
|
|
|
|
|
329
|
|
|
$contentTypeList = $this->parseContentTypeListFromResponse($response); |
|
|
|
|
|
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* @depends testCreateContentType |
|
334
|
|
|
* @covers COPY /content/types/<contentTypeId> |
|
335
|
|
|
* |
|
336
|
|
|
* @return string The copied content type href |
|
337
|
|
|
*/ |
|
338
|
|
View Code Duplication |
public function testCopyContentType($sourceContentTypeHref) |
|
339
|
|
|
{ |
|
340
|
|
|
$response = $this->sendHttpRequest( |
|
341
|
|
|
$this->createHttpRequest('COPY', $sourceContentTypeHref, '', 'ContentType+json') |
|
342
|
|
|
); |
|
343
|
|
|
|
|
344
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
345
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
346
|
|
|
|
|
347
|
|
|
$href = $response->getHeader('Location'); |
|
348
|
|
|
$this->addCreatedElement($href); |
|
349
|
|
|
|
|
350
|
|
|
return $href; |
|
351
|
|
|
|
|
352
|
|
|
// @todo test identifier (copy_of_<sourceIdentifier) |
|
353
|
|
|
} |
|
354
|
|
|
|
|
355
|
|
|
/** |
|
356
|
|
|
* @covers POST /content/type/<contentTypeId> |
|
357
|
|
|
* @depends testCopyContentType |
|
358
|
|
|
* |
|
359
|
|
|
* @return string the created content type draft href |
|
360
|
|
|
*/ |
|
361
|
|
View Code Duplication |
public function testCreateContentTypeDraft($contentTypeHref) |
|
362
|
|
|
{ |
|
363
|
|
|
$identifier = uniqid('test'); |
|
364
|
|
|
$content = <<< XML |
|
365
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
366
|
|
|
<ContentTypeUpdate> |
|
367
|
|
|
<names> |
|
368
|
|
|
<value languageCode="eng-GB">$identifier</value> |
|
369
|
|
|
</names> |
|
370
|
|
|
</ContentTypeUpdate> |
|
371
|
|
|
XML; |
|
372
|
|
|
|
|
373
|
|
|
$request = $this->createHttpRequest('POST', $contentTypeHref, 'ContentTypeUpdate+xml', 'ContentTypeInfo+json'); |
|
374
|
|
|
$request->setContent($content); |
|
375
|
|
|
$response = $this->sendHttpRequest( |
|
376
|
|
|
$request |
|
377
|
|
|
); |
|
378
|
|
|
|
|
379
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
380
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
381
|
|
|
|
|
382
|
|
|
$href = $response->getHeader('Location'); |
|
383
|
|
|
$this->addCreatedElement($href); |
|
384
|
|
|
|
|
385
|
|
|
return $href; |
|
386
|
|
|
} |
|
387
|
|
|
|
|
388
|
|
|
/** |
|
389
|
|
|
* @depends testCreateContentTypeDraft |
|
390
|
|
|
* @covers GET /content/types/<contentTypeId>/draft |
|
391
|
|
|
*/ |
|
392
|
|
|
public function testLoadContentTypeDraft($contentTypeDraftHref) |
|
393
|
|
|
{ |
|
394
|
|
|
$response = $this->sendHttpRequest( |
|
395
|
|
|
$this->createHttpRequest('GET', $contentTypeDraftHref) |
|
396
|
|
|
); |
|
397
|
|
|
|
|
398
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* @depends testCreateContentTypeDraft |
|
403
|
|
|
* @covers PATCH /content/types/<contentTypeId>/draft |
|
404
|
|
|
*/ |
|
405
|
|
|
public function testUpdateContentTypeDraft($contentTypeDraftHref) |
|
406
|
|
|
{ |
|
407
|
|
|
$content = <<< XML |
|
408
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
409
|
|
|
<ContentTypeUpdate> |
|
410
|
|
|
<names> |
|
411
|
|
|
<value languageCode="eng-GB">testUpdateContentTypeDraft</value> |
|
412
|
|
|
</names> |
|
413
|
|
|
</ContentTypeUpdate> |
|
414
|
|
|
XML; |
|
415
|
|
|
|
|
416
|
|
|
$request = $this->createHttpRequest('PATCH', $contentTypeDraftHref, 'ContentTypeUpdate+xml', 'ContentTypeInfo+json'); |
|
417
|
|
|
$request->setContent($content); |
|
418
|
|
|
$response = $this->sendHttpRequest( |
|
419
|
|
|
$request |
|
420
|
|
|
); |
|
421
|
|
|
|
|
422
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
423
|
|
|
} |
|
424
|
|
|
|
|
425
|
|
|
/** |
|
426
|
|
|
* @covers POST /content/types/<contentTypeId>/draft/fielddefinitions |
|
427
|
|
|
* @depends testCreateContentTypeDraft |
|
428
|
|
|
* |
|
429
|
|
|
* @return string The content type draft field definition href |
|
430
|
|
|
*/ |
|
431
|
|
View Code Duplication |
public function testAddContentTypeDraftFieldDefinition($contentTypeDraftHref) |
|
432
|
|
|
{ |
|
433
|
|
|
$body = <<< XML |
|
434
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
435
|
|
|
<FieldDefinition> |
|
436
|
|
|
<identifier>secondtext</identifier> |
|
437
|
|
|
<fieldType>ezstring</fieldType> |
|
438
|
|
|
<fieldGroup>content</fieldGroup> |
|
439
|
|
|
<position>1</position> |
|
440
|
|
|
<isTranslatable>true</isTranslatable> |
|
441
|
|
|
<isRequired>true</isRequired> |
|
442
|
|
|
<isInfoCollector>false</isInfoCollector> |
|
443
|
|
|
<defaultValue>Second text</defaultValue> |
|
444
|
|
|
<isSearchable>true</isSearchable> |
|
445
|
|
|
<names> |
|
446
|
|
|
<value languageCode="eng-GB">Second text</value> |
|
447
|
|
|
</names> |
|
448
|
|
|
</FieldDefinition> |
|
449
|
|
|
XML; |
|
450
|
|
|
|
|
451
|
|
|
$request = $this->createHttpRequest( |
|
452
|
|
|
'POST', |
|
453
|
|
|
"$contentTypeDraftHref/fieldDefinitions", |
|
454
|
|
|
'FieldDefinitionCreate+xml', |
|
455
|
|
|
'FieldDefinition+json' |
|
456
|
|
|
); |
|
457
|
|
|
$request->setContent($body); |
|
458
|
|
|
$response = $this->sendHttpRequest($request); |
|
459
|
|
|
|
|
460
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
461
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
462
|
|
|
|
|
463
|
|
|
return $response->getHeader('Location'); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
/** |
|
467
|
|
|
* @depends testCreateContentType |
|
468
|
|
|
* @covers GET /content/types/<contentTypeId>/fieldDefinitions |
|
469
|
|
|
* |
|
470
|
|
|
* @return string the href of the first field definition in the list |
|
471
|
|
|
*/ |
|
472
|
|
|
public function testContentTypeLoadFieldDefinitionList($contentTypeHref) |
|
473
|
|
|
{ |
|
474
|
|
|
$response = $this->sendHttpRequest( |
|
475
|
|
|
$this->createHttpRequest('GET', "$contentTypeHref/fieldDefinitions", '', 'FieldDefinitionList+json') |
|
476
|
|
|
); |
|
477
|
|
|
|
|
478
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
479
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
480
|
|
|
$response, |
|
481
|
|
|
['content-type-' . $this->extractLastIdFromHref($contentTypeHref)] |
|
482
|
|
|
); |
|
483
|
|
|
|
|
484
|
|
|
$data = json_decode($response->getContent(), true); |
|
485
|
|
|
|
|
486
|
|
|
return $data['FieldDefinitions']['FieldDefinition'][0]['_href']; |
|
487
|
|
|
} |
|
488
|
|
|
|
|
489
|
|
|
/** |
|
490
|
|
|
* @depends testAddContentTypeDraftFieldDefinition |
|
491
|
|
|
* @covers GET /content/types/<contentTypeId>/fieldDefinitions/<fieldDefinitionId> |
|
492
|
|
|
*/ |
|
493
|
|
View Code Duplication |
public function testLoadContentTypeFieldDefinition($fieldDefinitionHref) |
|
494
|
|
|
{ |
|
495
|
|
|
$response = $this->sendHttpRequest( |
|
496
|
|
|
$this->createHttpRequest('GET', $fieldDefinitionHref) |
|
497
|
|
|
); |
|
498
|
|
|
|
|
499
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
500
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
501
|
|
|
$response, |
|
502
|
|
|
['content-type-' . $this->extractLastIdFromHref($contentTypeHref)] |
|
|
|
|
|
|
503
|
|
|
); |
|
504
|
|
|
|
|
505
|
|
|
// @todo Cache test. Needs the contentTypeId |
|
506
|
|
|
} |
|
507
|
|
|
|
|
508
|
|
|
/** |
|
509
|
|
|
* @depends testAddContentTypeDraftFieldDefinition |
|
510
|
|
|
* @covers PATCH /content/types/<contentTypeId>/fieldDefinitions/<fieldDefinitionId> |
|
511
|
|
|
* |
|
512
|
|
|
* @todo the spec says PUT... |
|
513
|
|
|
*/ |
|
514
|
|
|
public function testUpdateContentTypeDraftFieldDefinition($fieldDefinitionHref) |
|
515
|
|
|
{ |
|
516
|
|
|
$body = <<< XML |
|
517
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
518
|
|
|
<FieldDefinitionUpdate> |
|
519
|
|
|
<identifier>updated_secondtext</identifier> |
|
520
|
|
|
<names> |
|
521
|
|
|
<value languageCode="eng-GB">Updated second text</value> |
|
522
|
|
|
</names> |
|
523
|
|
|
<defaultValue>Updated default value</defaultValue> |
|
524
|
|
|
</FieldDefinitionUpdate> |
|
525
|
|
|
XML; |
|
526
|
|
|
|
|
527
|
|
|
$request = $this->createHttpRequest( |
|
528
|
|
|
'PATCH', |
|
529
|
|
|
$fieldDefinitionHref, |
|
530
|
|
|
'FieldDefinitionUpdate+xml', |
|
531
|
|
|
'FieldDefinition+json' |
|
532
|
|
|
); |
|
533
|
|
|
$request->setContent($body); |
|
534
|
|
|
|
|
535
|
|
|
$response = $this->sendHttpRequest($request); |
|
536
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
537
|
|
|
} |
|
538
|
|
|
|
|
539
|
|
|
/** |
|
540
|
|
|
* @covers DELETE /content/types/<contentTypeId>/draft/fieldDefinitions/<fieldDefinitionId> |
|
541
|
|
|
* @depends testAddContentTypeDraftFieldDefinition |
|
542
|
|
|
*/ |
|
543
|
|
|
public function deleteContentTypeDraftFieldDefinition($fieldDefinitionHref) |
|
544
|
|
|
{ |
|
545
|
|
|
$response = $this->sendHttpRequest( |
|
546
|
|
|
$this->createHttpRequest('DELETE', $fieldDefinitionHref) |
|
547
|
|
|
); |
|
548
|
|
|
|
|
549
|
|
|
self::testLoadContentTypeFieldDefinition($response, 204); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
/** |
|
553
|
|
|
* @covers DELETE /content/types/<contentTypeId>/draft |
|
554
|
|
|
* @depends testCreateContentTypeDraft |
|
555
|
|
|
*/ |
|
556
|
|
|
public function testDeleteContentTypeDraft($contentTypeDraftHref) |
|
557
|
|
|
{ |
|
558
|
|
|
$response = $this->sendHttpRequest( |
|
559
|
|
|
$this->createHttpRequest('DELETE', $contentTypeDraftHref) |
|
560
|
|
|
); |
|
561
|
|
|
|
|
562
|
|
|
self::assertHttpResponseCodeEquals($response, 204); |
|
563
|
|
|
} |
|
564
|
|
|
|
|
565
|
|
|
/** |
|
566
|
|
|
* @depends testCreateContentType |
|
567
|
|
|
* @covers PUBLISH /content/types/<contentTypeId>/draft |
|
568
|
|
|
*/ |
|
569
|
|
|
public function testPublishContentTypeDraft($contentTypeHref) |
|
570
|
|
|
{ |
|
571
|
|
|
// we need to create a content type draft first since we deleted the previous one in testDeleteContentTypeDraft |
|
572
|
|
|
$contentTypeDraftHref = $this->testCreateContentTypeDraft($contentTypeHref); |
|
573
|
|
|
|
|
574
|
|
|
$response = $this->sendHttpRequest( |
|
575
|
|
|
$this->createHttpRequest('PUBLISH', $contentTypeDraftHref) |
|
576
|
|
|
); |
|
577
|
|
|
|
|
578
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
579
|
|
|
} |
|
580
|
|
|
|
|
581
|
|
|
/** |
|
582
|
|
|
* @depends testCreateContentType |
|
583
|
|
|
* @covers GET /content/types/<contentTypeId>/groups |
|
584
|
|
|
*/ |
|
585
|
|
View Code Duplication |
public function testLoadGroupsOfContentType($contentTypeHref) |
|
586
|
|
|
{ |
|
587
|
|
|
$response = $this->sendHttpRequest( |
|
588
|
|
|
$this->createHttpRequest('GET', "$contentTypeHref/groups", '', 'ContentTypeGroupRefList+json') |
|
589
|
|
|
); |
|
590
|
|
|
|
|
591
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
592
|
|
|
|
|
593
|
|
|
$this->assertHttpResponseHasCacheTags( |
|
594
|
|
|
$response, |
|
595
|
|
|
[ |
|
596
|
|
|
'content-type-' . $this->extractLastIdFromHref($contentTypeHref), |
|
597
|
|
|
] |
|
598
|
|
|
); |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
/** |
|
602
|
|
|
* @depends testCreateContentType |
|
603
|
|
|
* @covers POST /content/types/<contentTypeId>/groups |
|
604
|
|
|
* |
|
605
|
|
|
* @return string the content type href |
|
606
|
|
|
*/ |
|
607
|
|
|
public function testLinkContentTypeToGroup($contentTypeHref) |
|
608
|
|
|
{ |
|
609
|
|
|
// @todo Spec example is invalid, missing parameter name |
|
610
|
|
|
$request = $this->createHttpRequest('POST', "$contentTypeHref/groups?group=/api/ezp/v2/content/typegroups/1"); |
|
611
|
|
|
$response = $this->sendHttpRequest($request); |
|
612
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
613
|
|
|
|
|
614
|
|
|
return $contentTypeHref; |
|
615
|
|
|
} |
|
616
|
|
|
|
|
617
|
|
|
/** |
|
618
|
|
|
* @depends testLinkContentTypeToGroup |
|
619
|
|
|
* @covers DELETE /content/types/{contentTypeId}/groups/{contentTypeGroupId} |
|
620
|
|
|
*/ |
|
621
|
|
|
public function testUnlinkContentTypeFromGroup($contentTypeHref) |
|
622
|
|
|
{ |
|
623
|
|
|
$response = $this->sendHttpRequest( |
|
624
|
|
|
$this->createHttpRequest('DELETE', "$contentTypeHref/groups/1") |
|
625
|
|
|
); |
|
626
|
|
|
|
|
627
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
628
|
|
|
} |
|
629
|
|
|
|
|
630
|
|
|
/** |
|
631
|
|
|
* @depends testCreateContentType |
|
632
|
|
|
*/ |
|
633
|
|
|
public function testDeleteContentType($contentTypeHref) |
|
634
|
|
|
{ |
|
635
|
|
|
$response = $this->sendHttpRequest( |
|
636
|
|
|
$this->createHttpRequest('DELETE', $contentTypeHref) |
|
637
|
|
|
); |
|
638
|
|
|
|
|
639
|
|
|
self::assertHttpResponseCodeEquals($response, 204); |
|
640
|
|
|
} |
|
641
|
|
|
|
|
642
|
|
|
/** |
|
643
|
|
|
* @depends testCreateContentTypeGroup |
|
644
|
|
|
* @covers DELETE /content/typegroups/<contentTypeGroupId> |
|
645
|
|
|
*/ |
|
646
|
|
|
public function testDeleteContentTypeGroupNotEmpty($contentTypeGroupHref) |
|
647
|
|
|
{ |
|
648
|
|
|
$response = $this->sendHttpRequest( |
|
649
|
|
|
$this->createHttpRequest('DELETE', $contentTypeGroupHref) |
|
650
|
|
|
); |
|
651
|
|
|
|
|
652
|
|
|
self::assertHttpResponseCodeEquals($response, 403); |
|
653
|
|
|
} |
|
654
|
|
|
|
|
655
|
|
|
/** |
|
656
|
|
|
* @param $response |
|
657
|
|
|
* @return ContentTypeGroupList |
|
658
|
|
|
*/ |
|
659
|
|
|
private function parseContentTypeGroupListFromResponse($response): ContentTypeGroupList |
|
660
|
|
|
{ |
|
661
|
|
|
$struct = json_decode($response->getContent(), true); |
|
662
|
|
|
$contentTypeGroupList = new ContentTypeGroupList( |
|
663
|
|
|
array_map( |
|
664
|
|
|
function (array $row) { |
|
665
|
|
|
return new ContentTypeGroup( |
|
666
|
|
|
[ |
|
667
|
|
|
'id' => $row['id'], |
|
668
|
|
|
] |
|
669
|
|
|
); |
|
670
|
|
|
}, |
|
671
|
|
|
$struct['ContentTypeGroupList']['ContentTypeGroup'] |
|
672
|
|
|
), |
|
673
|
|
|
'' |
|
674
|
|
|
); |
|
675
|
|
|
return $contentTypeGroupList; |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
/** |
|
679
|
|
|
* @param $response |
|
680
|
|
|
* @return ContentTypeInfoList |
|
681
|
|
|
*/ |
|
682
|
|
|
private function parseContentTypeInfoListFromResponse($response): ContentTypeInfoList |
|
683
|
|
|
{ |
|
684
|
|
|
$struct = json_decode($response->getContent(), true); |
|
685
|
|
|
$contentTypeInfoList = new ContentTypeInfoList( |
|
686
|
|
|
array_map( |
|
687
|
|
|
function (array $row) { |
|
688
|
|
|
return new ContentType( |
|
689
|
|
|
[ |
|
690
|
|
|
'id' => $row['id'], |
|
691
|
|
|
'identifier' => $row['identifier'], |
|
692
|
|
|
'fieldDefinitions' => [] |
|
693
|
|
|
] |
|
694
|
|
|
); |
|
695
|
|
|
}, |
|
696
|
|
|
$struct['ContentTypeInfoList']['ContentType'] |
|
697
|
|
|
), |
|
698
|
|
|
'' |
|
699
|
|
|
); |
|
700
|
|
|
return $contentTypeInfoList; |
|
701
|
|
|
} |
|
702
|
|
|
|
|
703
|
|
|
/** |
|
704
|
|
|
* @param Response $response |
|
705
|
|
|
* @return ContentTypeGroup |
|
706
|
|
|
*/ |
|
707
|
|
View Code Duplication |
private function parseContentTypeGroupFromResponse(Response $response) |
|
708
|
|
|
{ |
|
709
|
|
|
$struct = json_decode($response->getContent(), true); |
|
710
|
|
|
|
|
711
|
|
|
return new ContentTypeGroup( |
|
712
|
|
|
[ |
|
713
|
|
|
'id' => $struct['ContentTypeGroup']['id'], |
|
714
|
|
|
'identifier' => $struct['ContentTypeGroup']['identifier'] |
|
715
|
|
|
] |
|
716
|
|
|
); |
|
717
|
|
|
} |
|
718
|
|
|
|
|
719
|
|
|
/** |
|
720
|
|
|
* @param Response $response |
|
721
|
|
|
* @return ContentType |
|
722
|
|
|
*/ |
|
723
|
|
View Code Duplication |
private function parseContentTypeFromResponse(Response $response) |
|
724
|
|
|
{ |
|
725
|
|
|
$struct = json_decode($response->getContent(), true); |
|
726
|
|
|
|
|
727
|
|
|
return new ContentType( |
|
728
|
|
|
[ |
|
729
|
|
|
'id' => $struct['ContentType']['id'], |
|
730
|
|
|
'identifier' => $struct['ContentType']['identifier'], |
|
731
|
|
|
'fieldDefinitions' => [] |
|
732
|
|
|
] |
|
733
|
|
|
); |
|
734
|
|
|
} |
|
735
|
|
|
|
|
736
|
|
|
private function parseContentTypeListFromRespose($response) |
|
|
|
|
|
|
737
|
|
|
{ |
|
738
|
|
|
} |
|
739
|
|
|
} |
|
740
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: