|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the Functional\LocationTest 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
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; |
|
12
|
|
|
|
|
13
|
|
|
class LocationTest extends RESTFunctionalTestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Covers POST /content/objects/{contentId}/locations. |
|
17
|
|
|
* @returns string location href |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testCreateLocation() |
|
20
|
|
|
{ |
|
21
|
|
|
$content = $this->createFolder('testCreateLocation', '/api/ezp/v2/content/locations/1/2'); |
|
22
|
|
|
$contentHref = $content['_href']; |
|
23
|
|
|
|
|
24
|
|
|
$remoteId = $this->addTestSuffix('testCreatelocation'); |
|
25
|
|
|
|
|
26
|
|
|
$body = <<< XML |
|
27
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
28
|
|
|
<LocationCreate> |
|
29
|
|
|
<ParentLocation href="/api/ezp/v2/content/locations/1/43" /> |
|
30
|
|
|
<remoteId>{$remoteId}</remoteId> |
|
31
|
|
|
<priority>0</priority> |
|
32
|
|
|
<hidden>false</hidden> |
|
33
|
|
|
<sortField>PATH</sortField> |
|
34
|
|
|
<sortOrder>ASC</sortOrder> |
|
35
|
|
|
</LocationCreate> |
|
36
|
|
|
XML; |
|
37
|
|
|
$request = $this->createHttpRequest('POST', "$contentHref/locations", 'LocationCreate+xml', 'Location+json'); |
|
38
|
|
|
$request->setContent($body); |
|
39
|
|
|
|
|
40
|
|
|
$response = $this->sendHttpRequest($request); |
|
41
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
42
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
43
|
|
|
|
|
44
|
|
|
$href = $response->getHeader('Location'); |
|
45
|
|
|
|
|
46
|
|
|
return $href; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @depends testCreateLocation |
|
51
|
|
|
* Covers GET /content/locations?remoteId=<locationRemoteId> |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
public function testRedirectLocationByRemoteId($locationHref) |
|
54
|
|
|
{ |
|
55
|
|
|
$response = $this->sendHttpRequest( |
|
56
|
|
|
$this->createHttpRequest('GET', '/api/ezp/v2/content/locations?remoteId=' . $this->addTestSuffix('testCreateLocation')) |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
self::assertHttpResponseCodeEquals($response, 307); |
|
60
|
|
|
self::assertHttpResponseHasHeader($response, 'Location', $locationHref); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @depends testCreateLocation |
|
65
|
|
|
* Covers GET /content/locations?id=<locationId> |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testRedirectLocationById($locationHref) |
|
68
|
|
|
{ |
|
69
|
|
|
$hrefParts = explode('/', $locationHref); |
|
70
|
|
|
$id = array_pop($hrefParts); |
|
71
|
|
|
$response = $this->sendHttpRequest( |
|
72
|
|
|
$this->createHttpRequest('GET', "/api/ezp/v2/content/locations?id=$id") |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
self::assertHttpResponseCodeEquals($response, 307); |
|
76
|
|
|
self::assertHttpResponseHasHeader($response, 'Location', $locationHref); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @depends testCreateLocation |
|
81
|
|
|
* Covers GET /content/locations?urlAlias=<Path/To-Content> |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function testRedirectLocationByURLAlias($locationHref) |
|
84
|
|
|
{ |
|
85
|
|
|
$testUrlAlias = 'firstPart/secondPart/testUrlAlias'; |
|
86
|
|
|
$this->createUrlAlias($locationHref, $testUrlAlias); |
|
87
|
|
|
|
|
88
|
|
|
$response = $this->sendHttpRequest( |
|
89
|
|
|
$this->createHttpRequest('GET', "/api/ezp/v2/content/locations?urlAlias={$testUrlAlias}") |
|
90
|
|
|
); |
|
91
|
|
|
|
|
92
|
|
|
self::assertHttpResponseCodeEquals($response, 307); |
|
93
|
|
|
self::assertHttpResponseHasHeader($response, 'Location', $locationHref); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @depends testCreateLocation |
|
98
|
|
|
* Covers GET /content/locations/{locationPath} |
|
99
|
|
|
*/ |
|
100
|
|
|
public function testLoadLocation($locationHref) |
|
101
|
|
|
{ |
|
102
|
|
|
$response = $this->sendHttpRequest( |
|
103
|
|
|
$this->createHttpRequest('GET', $locationHref) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @depends testCreateLocation |
|
111
|
|
|
* Covers COPY /content/locations/{locationPath} |
|
112
|
|
|
* |
|
113
|
|
|
* @return string the created location's href |
|
114
|
|
|
*/ |
|
115
|
|
|
public function testCopySubtree($locationHref) |
|
116
|
|
|
{ |
|
117
|
|
|
$request = $this->createHttpRequest('COPY', $locationHref); |
|
118
|
|
|
$request->addHeader('Destination: /api/ezp/v2/content/locations/1/43'); |
|
119
|
|
|
$response = $this->sendHttpRequest($request); |
|
120
|
|
|
|
|
121
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
122
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
123
|
|
|
|
|
124
|
|
|
return $response->getHeader('Location'); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Covers MOVE /content/locations/{locationPath}. |
|
129
|
|
|
* @depends testCopySubtree |
|
130
|
|
|
*/ |
|
131
|
|
View Code Duplication |
public function testMoveSubtree($locationHref) |
|
132
|
|
|
{ |
|
133
|
|
|
$request = $this->createHttpRequest('MOVE', $locationHref); |
|
134
|
|
|
$request->addHeader('Destination: /api/ezp/v2/content/locations/1/5'); |
|
135
|
|
|
$response = $this->sendHttpRequest($request); |
|
136
|
|
|
|
|
137
|
|
|
self::assertHttpResponseCodeEquals($response, 201); |
|
138
|
|
|
self::assertHttpResponseHasHeader($response, 'Location'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @depends testCreateLocation |
|
143
|
|
|
* Covers GET /content/objects/{contentId}/locations |
|
144
|
|
|
*/ |
|
145
|
|
|
public function testLoadLocationsForContent($contentHref) |
|
|
|
|
|
|
146
|
|
|
{ |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @depends testCreateLocation |
|
151
|
|
|
* Covers SWAP /content/locations/{locationPath} |
|
152
|
|
|
*/ |
|
153
|
|
|
public function testSwapLocation($locationHref) |
|
|
|
|
|
|
154
|
|
|
{ |
|
155
|
|
|
self::markTestSkipped('@todo Implement'); |
|
156
|
|
|
|
|
157
|
|
|
/*$content = $this->createFolder( __FUNCTION__, "/api/ezp/v2/content/locations/1/2" ); |
|
158
|
|
|
|
|
159
|
|
|
$request = $this->createHttpRequest( 'SWAP', $locationHref ); |
|
160
|
|
|
$request->addHeader( "Destination: $newFolderHref" ); |
|
161
|
|
|
|
|
162
|
|
|
$response = $this->sendHttpRequest( $request ); |
|
163
|
|
|
self::assertHttpResponseCodeEquals( $response, 204 );*/ |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @depends testCreateLocation |
|
168
|
|
|
* Covers GET /content/locations/{locationPath}/children |
|
169
|
|
|
*/ |
|
170
|
|
|
public function testLoadLocationChildren($locationHref) |
|
171
|
|
|
{ |
|
172
|
|
|
$response = $this->sendHttpRequest( |
|
173
|
|
|
$this->createHttpRequest('GET', "$locationHref/children", '', 'LocationList+json') |
|
174
|
|
|
); |
|
175
|
|
|
|
|
176
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
177
|
|
|
self::assertHttpResponseHasHeader($response, 'Content-Type', $this->generateMediaTypeString('LocationList+json')); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Covers PATCH /content/locations/{locationPath}. |
|
182
|
|
|
* @depends testCreateLocation |
|
183
|
|
|
*/ |
|
184
|
|
View Code Duplication |
public function testUpdateLocation($locationHref) |
|
185
|
|
|
{ |
|
186
|
|
|
$body = <<< XML |
|
187
|
|
|
<LocationUpdate> |
|
188
|
|
|
<priority>3</priority> |
|
189
|
|
|
<sortField>PATH</sortField> |
|
190
|
|
|
<sortOrder>ASC</sortOrder> |
|
191
|
|
|
</LocationUpdate> |
|
192
|
|
|
XML; |
|
193
|
|
|
|
|
194
|
|
|
$request = $this->createHttpRequest('PATCH', $locationHref, 'LocationUpdate+xml', 'Location+json'); |
|
195
|
|
|
$request->setContent($body); |
|
196
|
|
|
|
|
197
|
|
|
$response = $this->sendHttpRequest($request); |
|
198
|
|
|
|
|
199
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @depends testCreateLocation |
|
204
|
|
|
* Covers DELETE /content/locations/{path} |
|
205
|
|
|
*/ |
|
206
|
|
|
public function testDeleteSubtree($locationHref) |
|
207
|
|
|
{ |
|
208
|
|
|
$response = $this->sendHttpRequest( |
|
209
|
|
|
$this->createHttpRequest('DELETE', $locationHref) |
|
210
|
|
|
); |
|
211
|
|
|
|
|
212
|
|
|
self::assertHttpResponseCodeEquals($response, 204); |
|
213
|
|
|
} |
|
214
|
|
|
|
|
215
|
|
View Code Duplication |
private function createUrlAlias(string $locationHref, string $urlAlias): string |
|
216
|
|
|
{ |
|
217
|
|
|
$xml = <<< XML |
|
218
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
219
|
|
|
<UrlAliasCreate type="LOCATION"> |
|
220
|
|
|
<location href="{$locationHref}" /> |
|
221
|
|
|
<path>/{$urlAlias}</path> |
|
222
|
|
|
<languageCode>eng-GB</languageCode> |
|
223
|
|
|
<alwaysAvailable>false</alwaysAvailable> |
|
224
|
|
|
<forward>true</forward> |
|
225
|
|
|
</UrlAliasCreate> |
|
226
|
|
|
XML; |
|
227
|
|
|
|
|
228
|
|
|
$request = $this->createHttpRequest( |
|
229
|
|
|
'POST', |
|
230
|
|
|
'/api/ezp/v2/content/urlaliases', |
|
231
|
|
|
'UrlAliasCreate+xml', |
|
232
|
|
|
'UrlAlias+json' |
|
233
|
|
|
); |
|
234
|
|
|
$request->setContent($xml); |
|
235
|
|
|
|
|
236
|
|
|
$response = $this->sendHttpRequest($request); |
|
237
|
|
|
$href = $response->getHeader('Location'); |
|
238
|
|
|
$this->addCreatedElement($href); |
|
239
|
|
|
|
|
240
|
|
|
return $href; |
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.