Completed
Push — master ( 696c56...a8c737 )
by André
259:23 queued 232:42
created

ObjectStateTest::testLoadObjectStateGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Functional\ObjectStateTest 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 ObjectStateTest extends RESTFunctionalTestCase
14
{
15
    /**
16
     * Covers POST /content/objectstategroups.
17
     *
18
     * @return string Object state group href
19
     */
20 View Code Duplication
    public function testCreateObjectStateGroup()
21
    {
22
        $body = <<< XML
23
<?xml version="1.0" encoding="UTF-8"?>
24
<ObjectStateGroupCreate>
25
  <identifier>testCreateObjectStateGroup</identifier>
26
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
27
  <names>
28
    <value languageCode="eng-GB">testCreateObjectStateGroup</value>
29
  </names>
30
  <descriptions>
31
    <value languageCode="eng-GB">testCreateObjectStateGroup description</value>
32
  </descriptions>
33
</ObjectStateGroupCreate>
34
XML;
35
36
        $request = $this->createHttpRequest(
37
            'POST',
38
            '/api/ezp/v2/content/objectstategroups',
39
            'ObjectStateGroupCreate+xml',
40
            'ObjectStateGroup+json',
41
            $body
42
        );
43
44
        $response = $this->sendHttpRequest($request);
45
46
        self::assertHttpResponseCodeEquals($response, 201);
47
        self::assertHttpResponseHasHeader($response, 'Location');
48
49
        $href = $response->getHeader('Location')[0];
50
        $this->addCreatedElement($href);
51
52
        return $href;
53
    }
54
55
    /**
56
     * Covers POST /content/objectstategroups/{objectStateGroupId}/objectstates.
57
     *
58
     * @return string Object state href
59
     * @depends testCreateObjectStateGroup
60
     */
61 View Code Duplication
    public function testCreateObjectState($objectStateGroupHref)
62
    {
63
        $body = <<< XML
64
<?xml version="1.0" encoding="UTF-8"?>
65
<ObjectStateCreate>
66
  <identifier>testCreateObjectState</identifier>
67
  <priority>4</priority>
68
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
69
  <names>
70
    <value languageCode="eng-GB">testCreateObjectState</value>
71
  </names>
72
  <descriptions>
73
    <value languageCode="eng-GB">testCreateObjectState description</value>
74
  </descriptions>
75
</ObjectStateCreate>
76
XML;
77
78
        $request = $this->createHttpRequest(
79
            'POST',
80
            "$objectStateGroupHref/objectstates",
81
            'ObjectStateCreate+xml',
82
            'ObjectState+json',
83
            $body
84
        );
85
86
        $response = $this->sendHttpRequest($request);
87
88
        self::assertHttpResponseCodeEquals($response, 201);
89
        self::assertHttpResponseHasHeader($response, 'Location');
90
91
        $href = $response->getHeader('Location')[0];
92
        $this->addCreatedElement($href);
93
94
        return $href;
95
    }
96
97
    /**
98
     * Covers GET /content/objectstategroups/{objectStateGroupId}.
99
     * @depends testCreateObjectStateGroup
100
     */
101
    public function testLoadObjectStateGroup($objectStateGroupHref)
102
    {
103
        $response = $this->sendHttpRequest(
104
            $this->createHttpRequest('GET', $objectStateGroupHref)
105
        );
106
107
        self::assertHttpResponseCodeEquals($response, 200);
108
    }
109
110
    /**
111
     * Covers GET /content/objectstategroups/{objectStateGroupId}/objectstates/{objectStateId}.
112
     * @depends testCreateObjectState
113
     */
114
    public function testLoadObjectState($objectStateHref)
115
    {
116
        $response = $this->sendHttpRequest(
117
            $this->createHttpRequest('GET', $objectStateHref)
118
        );
119
120
        self::assertHttpResponseCodeEquals($response, 200);
121
    }
122
123
    /**
124
     * Covers GET /content/objectstategroups.
125
     */
126
    public function testLoadObjectStateGroups()
127
    {
128
        $response = $this->sendHttpRequest(
129
            $this->createHttpRequest('GET', '/api/ezp/v2/content/objectstategroups')
130
        );
131
132
        self::assertHttpResponseCodeEquals($response, 200);
133
    }
134
135
    /**
136
     * Covers GET /content/objectstategroups/{objectStateGroupId}/objectstates.
137
     * @depends testCreateObjectStateGroup
138
     */
139
    public function testLoadObjectStates($objectStateGroupHref)
140
    {
141
        $response = $this->sendHttpRequest(
142
            $this->createHttpRequest('GET', "$objectStateGroupHref/objectstates")
143
        );
144
145
        self::assertHttpResponseCodeEquals($response, 200);
146
    }
147
148
    /**
149
     * Covers PATCH /content/objects/{contentId}/objectstates.
150
     * @depends testCreateObjectState
151
     *
152
     * @return string The created folder content href
153
     */
154 View Code Duplication
    public function testSetObjectStatesForContent($objectStateHref)
155
    {
156
        $folder = $this->createFolder(__FUNCTION__, '/api/ezp/v2/content/locations/1/2');
157
158
        $xml = <<< XML
159
<?xml version="1.0" encoding="UTF-8"?>
160
<ContentObjectStates>
161
 <ObjectState href="$objectStateHref"/>
162
</ContentObjectStates>
163
XML;
164
165
        $folderHref = $folder['_href'];
166
        $request = $this->createHttpRequest(
167
            'PATCH',
168
            "$folderHref/objectstates",
169
            'ContentObjectStates+xml',
170
            'ContentObjectStates+json',
171
            $xml
172
        );
173
        $response = $this->sendHttpRequest($request);
174
175
        self::assertHttpResponseCodeEquals($response, 200);
176
177
        return $folderHref;
178
    }
179
180
    /**
181
     * Covers GET /content/objects/{contentId}/objectstates.
182
     * @depends testSetObjectStatesForContent
183
     */
184
    public function testGetObjectStatesForContent($contentHref)
185
    {
186
        $response = $this->sendHttpRequest(
187
            $this->createHttpRequest('GET', "$contentHref/objectstates")
188
        );
189
190
        self::assertHttpResponseCodeEquals($response, 200);
191
    }
192
193
    /**
194
     * Covers PATCH /content/objectstategroups/{objectStateGroupId}/objectstates/{objectStateId}.
195
     * @depends testCreateObjectState
196
     */
197 View Code Duplication
    public function testUpdateObjectState($objectStateHref)
198
    {
199
        $body = <<< XML
200
<?xml version="1.0" encoding="UTF-8"?>
201
<ObjectStateUpdate>
202
  <identifier>testUpdateObjectState</identifier>
203
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
204
  <names>
205
    <value languageCode="eng-GB">testUpdateObjectState</value>
206
  </names>
207
  <descriptions>
208
    <value languageCode="eng-GB">testUpdateObjectState description</value>
209
  </descriptions>
210
</ObjectStateUpdate>
211
XML;
212
        $request = $this->createHttpRequest(
213
            'PATCH',
214
            $objectStateHref,
215
            'ObjectStateUpdate+xml',
216
            'ObjectState+json',
217
            $body
218
        );
219
        $response = $this->sendHttpRequest($request);
220
221
        self::assertHttpResponseCodeEquals($response, 200);
222
    }
223
224
    /**
225
     * Covers PATCH /content/objectstategroups/{objectStateGroupId}.
226
     * @depends testCreateObjectStateGroup
227
     */
228 View Code Duplication
    public function testUpdateObjectStateGroup($objectStateGroupHref)
229
    {
230
        $body = <<< XML
231
<?xml version="1.0" encoding="UTF-8"?>
232
<ObjectStateGroupUpdate>
233
  <identifier>testUpdateObjectStateGroup</identifier>
234
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
235
  <names>
236
    <value languageCode="eng-GB">testUpdateObjectStateGroup</value>
237
  </names>
238
  <descriptions>
239
    <value languageCode="eng-GB">testUpdateObjectStateGroup description</value>
240
  </descriptions>
241
</ObjectStateGroupUpdate>
242
XML;
243
        $request = $this->createHttpRequest(
244
            'PATCH',
245
            $objectStateGroupHref,
246
            'ObjectStateGroupUpdate+xml',
247
            'ObjectStateGroup+json',
248
            $body
249
        );
250
        $response = $this->sendHttpRequest($request);
251
252
        self::assertHttpResponseCodeEquals($response, 200);
253
    }
254
255
    /**
256
     * Covers DELETE.
257
     * @depends testCreateObjectState
258
     */
259
    public function testDeleteObjectState($objectStateHref)
260
    {
261
        $response = $this->sendHttpRequest(
262
            $this->createHttpRequest('DELETE', $objectStateHref)
263
        );
264
265
        self::assertHttpResponseCodeEquals($response, 204);
266
    }
267
268
    /**
269
     * Covers DELETE /content/objectstategroups/{objectStateGroupId}.
270
     * @depends testCreateObjectStateGroup
271
     */
272
    public function testDeleteObjectStateGroup($objectStateGroupHref)
273
    {
274
        $response = $this->sendHttpRequest(
275
            $this->createHttpRequest('DELETE', $objectStateGroupHref)
276
        );
277
278
        self::assertHttpResponseCodeEquals($response, 204);
279
    }
280
}
281