Code Duplication    Length = 25-35 lines in 14 locations

eZ/Bundle/EzPublishRestBundle/Tests/Functional/ContentTypeTest.php 2 locations

@@ 18-42 (lines=25) @@
15
    /**
16
     * Covers POST /content/typegroups.
17
     */
18
    public function testCreateContentTypeGroup()
19
    {
20
        $body = <<< XML
21
<?xml version="1.0" encoding="UTF-8"?>
22
<ContentTypeGroupInput>
23
  <identifier>testCreateContentTypeGroup</identifier>
24
</ContentTypeGroupInput>
25
XML;
26
        $request = $this->createHttpRequest(
27
            'POST',
28
            '/api/ezp/v2/content/typegroups',
29
            'ContentTypeGroupInput+xml',
30
            'ContentTypeGroup+json',
31
            $body
32
        );
33
        $response = $this->sendHttpRequest($request);
34
35
        self::assertHttpResponseCodeEquals($response, 201);
36
        self::assertHttpResponseHasHeader($response, 'Location');
37
38
        $href = $response->getHeader('Location')[0];
39
        $this->addCreatedElement($href);
40
41
        return $href;
42
    }
43
44
    /**
45
     * @depends testCreateContentTypeGroup
@@ 303-330 (lines=28) @@
300
     *
301
     * @return string the created content type draft href
302
     */
303
    public function testCreateContentTypeDraft($contentTypeHref)
304
    {
305
        $content = <<< XML
306
<?xml version="1.0" encoding="UTF-8"?>
307
<ContentTypeUpdate>
308
  <names>
309
    <value languageCode="eng-GB">testCreateContentTypeDraft</value>
310
  </names>
311
</ContentTypeUpdate>
312
XML;
313
314
        $request = $this->createHttpRequest(
315
            'POST',
316
            $contentTypeHref,
317
            'ContentTypeUpdate+xml',
318
            'ContentTypeInfo+json',
319
            $content
320
        );
321
        $response = $this->sendHttpRequest($request);
322
323
        self::assertHttpResponseCodeEquals($response, 201);
324
        self::assertHttpResponseHasHeader($response, 'Location');
325
326
        $href = $response->getHeader('Location')[0];
327
        $this->addCreatedElement($href);
328
329
        return $href;
330
    }
331
332
    /**
333
     * @depends testCreateContentTypeDraft

eZ/Bundle/EzPublishRestBundle/Tests/Functional/ObjectStateTest.php 3 locations

@@ 20-53 (lines=34) @@
17
     *
18
     * @return string Object state group href
19
     */
20
    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.
@@ 61-95 (lines=35) @@
58
     * @return string Object state href
59
     * @depends testCreateObjectStateGroup
60
     */
61
    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}.
@@ 154-178 (lines=25) @@
151
     *
152
     * @return string The created folder content href
153
     */
154
    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.

eZ/Bundle/EzPublishRestBundle/Tests/Functional/RoleTest.php 6 locations

@@ 23-54 (lines=32) @@
20
     *
21
     * @return string The created role href
22
     */
23
    public function testCreateRole()
24
    {
25
        $xml = <<< XML
26
<?xml version="1.0" encoding="UTF-8"?>
27
<RoleInput>
28
  <identifier>testCreateRole</identifier>
29
  <mainLanguageCode>eng-GB</mainLanguageCode>
30
  <names>
31
    <value languageCode="eng-GB">testCreateRole</value>
32
  </names>
33
  <descriptions>
34
    <value languageCode="eng-GB">testCreateRole description</value>
35
  </descriptions>
36
</RoleInput>
37
XML;
38
        $request = $this->createHttpRequest(
39
            'POST',
40
            '/api/ezp/v2/user/roles',
41
            'RoleInput+xml',
42
            'Role+json',
43
            $xml
44
        );
45
        $response = $this->sendHttpRequest($request);
46
47
        self::assertHttpResponseCodeEquals($response, 201);
48
        self::assertHttpResponseHasHeader($response, 'Location');
49
50
        $href = $response->getHeader('Location')[0];
51
        $this->addCreatedElement($href);
52
53
        return $href;
54
    }
55
56
    /**
57
     * Covers POST /user/roles.
@@ 63-94 (lines=32) @@
60
     *
61
     * @return string The created role draft href
62
     */
63
    public function testCreateRoleWithDraft()
64
    {
65
        $xml = <<< XML
66
<?xml version="1.0" encoding="UTF-8"?>
67
<RoleInput>
68
  <identifier>testCreateRoleDraft</identifier>
69
  <mainLanguageCode>eng-GB</mainLanguageCode>
70
  <names>
71
    <value languageCode="eng-GB">testCreateRoleDraft</value>
72
  </names>
73
  <descriptions>
74
    <value languageCode="eng-GB">testCreateRoleDraft description</value>
75
  </descriptions>
76
</RoleInput>
77
XML;
78
        $request = $this->createHttpRequest(
79
            'POST',
80
            '/api/ezp/v2/user/roles?publish=false',
81
            'RoleInput+xml',
82
            'RoleDraft+json',
83
            $xml
84
        );
85
        $response = $this->sendHttpRequest($request);
86
87
        self::assertHttpResponseCodeEquals($response, 201);
88
        self::assertHttpResponseHasHeader($response, 'Location');
89
90
        $href = $response->getHeader('Location')[0];
91
        $this->addCreatedElement($href);
92
93
        return $href . '/draft';
94
    }
95
96
    /**
97
     * Covers GET /user/roles.
@@ 127-158 (lines=32) @@
124
     *
125
     * @return string The created role draft href
126
     */
127
    public function testCreateRoleDraft($roleHref)
128
    {
129
        $xml = <<< XML
130
<?xml version="1.0" encoding="UTF-8"?>
131
<RoleInput>
132
  <identifier>testCreateRoleDraft</identifier>
133
  <mainLanguageCode>eng-GB</mainLanguageCode>
134
  <names>
135
    <value languageCode="eng-GB">testCreateRoleDraft</value>
136
  </names>
137
  <descriptions>
138
    <value languageCode="eng-GB">testCreateRoleDraft description</value>
139
  </descriptions>
140
</RoleInput>
141
XML;
142
        $request = $this->createHttpRequest(
143
            'POST',
144
            $roleHref,
145
            'RoleInput+xml',
146
            'RoleDraft+json',
147
            $xml
148
        );
149
        $response = $this->sendHttpRequest($request);
150
151
        self::assertHttpResponseCodeEquals($response, 201);
152
        self::assertHttpResponseHasHeader($response, 'Location');
153
154
        $href = $response->getHeader('Location')[0];
155
        $this->addCreatedElement($href);
156
157
        return $href . '/draft';
158
    }
159
160
    /**
161
     * @depends testCreateRoleDraft
@@ 237-270 (lines=34) @@
234
     *
235
     * @return string The created policy href
236
     */
237
    public function testAddPolicy($roleHref)
238
    {
239
        // @todo Error in Resource URL in spec @ https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst#151213create-policy
240
        $xml = <<< XML
241
<?xml version="1.0" encoding="UTF-8"?>
242
<PolicyCreate>
243
  <module>content</module>
244
  <function>create</function>
245
  <limitations>
246
    <limitation identifier="Class">
247
      <values>
248
        <ref href="2"/>
249
      </values>
250
    </limitation>
251
  </limitations>
252
</PolicyCreate>
253
XML;
254
        $request = $this->createHttpRequest(
255
            'POST',
256
            "$roleHref/policies",
257
            'PolicyCreate+xml',
258
            'Policy+json',
259
            $xml
260
        );
261
        $response = $this->sendHttpRequest($request);
262
263
        self::assertHttpResponseCodeEquals($response, 201);
264
        self::assertHttpResponseHasHeader($response, 'Location');
265
266
        $href = $response->getHeader('Location')[0];
267
        $this->addCreatedElement($href);
268
269
        return $href;
270
    }
271
272
    /**
273
     * Covers POST /user/roles/{roleId}/policies.
@@ 278-310 (lines=33) @@
275
     *
276
     * @return string The created policy href
277
     */
278
    public function testAddPolicyByRoleDraft($roleDraftHref)
279
    {
280
        $xml = <<< XML
281
<?xml version="1.0" encoding="UTF-8"?>
282
<PolicyCreate>
283
  <module>content</module>
284
  <function>create</function>
285
  <limitations>
286
    <limitation identifier="Class">
287
      <values>
288
        <ref href="1"/>
289
      </values>
290
    </limitation>
291
  </limitations>
292
</PolicyCreate>
293
XML;
294
        $request = $this->createHttpRequest(
295
            'POST',
296
            $this->roleDraftHrefToRoleHref($roleDraftHref) . '/policies',
297
            'PolicyCreate+xml',
298
            'Policy+json',
299
            $xml
300
        );
301
        $response = $this->sendHttpRequest($request);
302
303
        self::assertHttpResponseCodeEquals($response, 201);
304
        self::assertHttpResponseHasHeader($response, 'Location');
305
306
        $href = $response->getHeader('Location')[0];
307
        $this->addCreatedElement($href);
308
309
        return $href;
310
    }
311
312
    /**
313
     * Covers GET /user/roles/{roleId}/policies/{policyId}.
@@ 707-738 (lines=32) @@
704
     *
705
     * @return string The href of the published role
706
     */
707
    private function createAndPublishRole($identifier)
708
    {
709
        $xml = <<< XML
710
<?xml version="1.0" encoding="UTF-8"?>
711
<RoleInput>
712
  <identifier>$identifier</identifier>
713
  <mainLanguageCode>eng-GB</mainLanguageCode>
714
  <names>
715
    <value languageCode="eng-GB">$identifier</value>
716
  </names>
717
  <descriptions>
718
    <value languageCode="eng-GB">$identifier description</value>
719
  </descriptions>
720
</RoleInput>
721
XML;
722
        $request = $this->createHttpRequest(
723
            'POST',
724
            '/api/ezp/v2/user/roles',
725
            'RoleInput+xml',
726
            'RoleDraft+json',
727
            $xml
728
        );
729
        $response = $this->sendHttpRequest($request);
730
731
        self::assertHttpResponseCodeEquals($response, 201);
732
        self::assertHttpResponseHasHeader($response, 'Location');
733
        $href = $response->getHeader('Location')[0];
734
735
        $this->addCreatedElement($href);
736
737
        return $href;
738
    }
739
}
740

eZ/Bundle/EzPublishRestBundle/Tests/Functional/SectionTest.php 1 location

@@ 32-56 (lines=25) @@
29
     *
30
     * @return string The created section href
31
     */
32
    public function testCreateSection()
33
    {
34
        $xml = <<< XML
35
<SectionInput>
36
  <identifier>testCreateSection</identifier>
37
  <name>testCreateSection</name>
38
</SectionInput>
39
XML;
40
        $request = $this->createHttpRequest(
41
            'POST',
42
            '/api/ezp/v2/content/sections',
43
            'SectionInput+xml',
44
            'Section+json',
45
            $xml
46
        );
47
        $response = $this->sendHttpRequest($request);
48
49
        self::assertHttpResponseCodeEquals($response, 201);
50
        self::assertHttpResponseHasHeader($response, 'Location');
51
52
        $href = $response->getHeader('Location')[0];
53
        $this->addCreatedElement($href);
54
55
        return $href;
56
    }
57
58
    /**
59
     * @param $sectionHref

eZ/Bundle/EzPublishRestBundle/Tests/Functional/UrlAliasTest.php 1 location

@@ 82-113 (lines=32) @@
79
     * Covers POST /content/urlaliases.
80
     * @returns string The created url alias href
81
     */
82
    public function testCreateGlobalUrlAlias()
83
    {
84
        $text = $this->addTestSuffix(__FUNCTION__);
85
        $xml = <<< XML
86
<?xml version="1.0" encoding="UTF-8"?>
87
<UrlAliasCreate type="RESOURCE">
88
  <resource>module:/content/search</resource>
89
  <path>/$text</path>
90
  <languageCode>eng-GB</languageCode>
91
  <alwaysAvailable>false</alwaysAvailable>
92
  <forward>true</forward>
93
</UrlAliasCreate>
94
XML;
95
96
        $request = $this->createHttpRequest(
97
            'POST',
98
            '/api/ezp/v2/content/urlaliases',
99
            'UrlAliasCreate+xml',
100
            'UrlAlias+json',
101
            $xml
102
        );
103
104
        $response = $this->sendHttpRequest($request);
105
106
        self::assertHttpResponseCodeEquals($response, 201);
107
        self::assertHttpResponseHasHeader($response, 'Location');
108
109
        $href = $response->getHeader('Location')[0];
110
        $this->addCreatedElement($href);
111
112
        return $href;
113
    }
114
115
    /**
116
     * @depends testCreateUrlAlias

eZ/Bundle/EzPublishRestBundle/Tests/Functional/UrlWildcardTest.php 1 location

@@ 31-59 (lines=29) @@
28
     * @returns string The created URL wildcard href
29
     * Covers POST /content/urlwildcards
30
     */
31
    public function testCreateUrlWildcard()
32
    {
33
        $text = $this->addTestSuffix(__FUNCTION__);
34
        $xml = <<< XML
35
<?xml version="1.0" encoding="UTF-8"?>
36
<UrlWildcardCreate>
37
  <sourceUrl>/{$text}/*</sourceUrl>
38
  <destinationUrl>/destination/url/{1}</destinationUrl>
39
  <forward>true</forward>
40
</UrlWildcardCreate>
41
XML;
42
43
        $request = $this->createHttpRequest(
44
            'POST',
45
            '/api/ezp/v2/content/urlwildcards',
46
            'UrlWildcardCreate+xml',
47
            'UrlWildcard+json',
48
            $xml
49
        );
50
        $response = $this->sendHttpRequest($request);
51
52
        self::assertHttpResponseCodeEquals($response, 201);
53
        self::assertHttpResponseHasHeader($response, 'Location');
54
55
        $href = $response->getHeader('Location')[0];
56
        $this->addCreatedElement($href);
57
58
        return $href;
59
    }
60
61
    /**
62
     * @param $urlWildcardHref