Code Duplication    Length = 20-55 lines in 15 locations

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

@@ 20-39 (lines=20) @@
17
    /**
18
     * @covers POST /content/typegroups
19
     */
20
    public function testCreateContentTypeGroup()
21
    {
22
        $body = <<< XML
23
<?xml version="1.0" encoding="UTF-8"?>
24
<ContentTypeGroupInput>
25
  <identifier>testCreateContentTypeGroup</identifier>
26
</ContentTypeGroupInput>
27
XML;
28
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/content/typegroups', 'ContentTypeGroupInput+xml', 'ContentTypeGroup+json');
29
        $request->setContent($body);
30
        $response = $this->sendHttpRequest($request);
31
32
        self::assertHttpResponseCodeEquals($response, 201);
33
        self::assertHttpResponseHasHeader($response, 'Location');
34
35
        $href = $response->getHeader('Location');
36
        $this->addCreatedElement($href);
37
38
        return $href;
39
    }
40
41
    /**
42
     * @depends testCreateContentTypeGroup
@@ 72-126 (lines=55) @@
69
     *
70
     * @todo write test with full workflow (draft, edit, publish)
71
     */
72
    public function testCreateContentType($contentTypeGroupHref)
73
    {
74
        $body = <<< XML
75
<?xml version="1.0" encoding="UTF-8"?>
76
<ContentTypeCreate>
77
  <identifier>testCreateContentType</identifier>
78
  <names>
79
    <value languageCode="eng-GB">testCreateContentType</value>
80
  </names>
81
  <remoteId>testCreateContentType</remoteId>
82
  <urlAliasSchema>&lt;title&gt;</urlAliasSchema>
83
  <nameSchema>&lt;title&gt;</nameSchema>
84
  <isContainer>true</isContainer>
85
  <mainLanguageCode>eng-GB</mainLanguageCode>
86
  <defaultAlwaysAvailable>true</defaultAlwaysAvailable>
87
  <defaultSortField>PATH</defaultSortField>
88
  <defaultSortOrder>ASC</defaultSortOrder>
89
  <FieldDefinitions>
90
    <FieldDefinition>
91
      <identifier>title</identifier>
92
      <fieldType>ezstring</fieldType>
93
      <fieldGroup>content</fieldGroup>
94
      <position>1</position>
95
      <isTranslatable>true</isTranslatable>
96
      <isRequired>true</isRequired>
97
      <isInfoCollector>false</isInfoCollector>
98
      <defaultValue>New Title</defaultValue>
99
      <isSearchable>true</isSearchable>
100
      <names>
101
        <value languageCode="eng-GB">Title</value>
102
      </names>
103
      <descriptions>
104
        <value languageCode="eng-GB">This is the title</value>
105
      </descriptions>
106
    </FieldDefinition>
107
   </FieldDefinitions>
108
</ContentTypeCreate>
109
XML;
110
111
        $request = $this->createHttpRequest(
112
            'POST',
113
            "$contentTypeGroupHref/types?publish=true",
114
            'ContentTypeCreate+xml',
115
            'ContentType+json'
116
        );
117
        $request->setContent($body);
118
        $response = $this->sendHttpRequest($request);
119
120
        self::assertHttpResponseCodeEquals($response, 201);
121
        self::assertHttpResponseHasHeader($response, 'Location');
122
123
        $this->addCreatedElement($response->getHeader('Location'));
124
125
        return $response->getHeader('Location');
126
    }
127
128
    /**
129
     * @depends testCreateContentTypeGroup
@@ 295-319 (lines=25) @@
292
     *
293
     * @return string the created content type draft href
294
     */
295
    public function testCreateContentTypeDraft($contentTypeHref)
296
    {
297
        $content = <<< XML
298
<?xml version="1.0" encoding="UTF-8"?>
299
<ContentTypeUpdate>
300
  <names>
301
    <value languageCode="eng-GB">testCreateContentTypeDraft</value>
302
  </names>
303
</ContentTypeUpdate>
304
XML;
305
306
        $request = $this->createHttpRequest('POST', $contentTypeHref, 'ContentTypeUpdate+xml', 'ContentTypeInfo+json');
307
        $request->setContent($content);
308
        $response = $this->sendHttpRequest(
309
            $request
310
        );
311
312
        self::assertHttpResponseCodeEquals($response, 201);
313
        self::assertHttpResponseHasHeader($response, 'Location');
314
315
        $href = $response->getHeader('Location');
316
        $this->addCreatedElement($href);
317
318
        return $href;
319
    }
320
321
    /**
322
     * @depends testCreateContentTypeDraft
@@ 364-397 (lines=34) @@
361
     *
362
     * @return string The content type draft field definition href
363
     */
364
    public function testAddContentTypeDraftFieldDefinition($contentTypeDraftHref)
365
    {
366
        $body = <<< XML
367
<?xml version="1.0" encoding="UTF-8"?>
368
<FieldDefinition>
369
      <identifier>secondtext</identifier>
370
      <fieldType>ezstring</fieldType>
371
      <fieldGroup>content</fieldGroup>
372
      <position>1</position>
373
      <isTranslatable>true</isTranslatable>
374
      <isRequired>true</isRequired>
375
      <isInfoCollector>false</isInfoCollector>
376
      <defaultValue>Second text</defaultValue>
377
      <isSearchable>true</isSearchable>
378
      <names>
379
        <value languageCode="eng-GB">Second text</value>
380
      </names>
381
    </FieldDefinition>
382
XML;
383
384
        $request = $this->createHttpRequest(
385
            'POST',
386
            "$contentTypeDraftHref/fieldDefinitions",
387
            'FieldDefinitionCreate+xml',
388
            'FieldDefinition+json'
389
        );
390
        $request->setContent($body);
391
        $response = $this->sendHttpRequest($request);
392
393
        self::assertHttpResponseCodeEquals($response, 201);
394
        self::assertHttpResponseHasHeader($response, 'Location');
395
396
        return $response->getHeader('Location');
397
    }
398
399
    /**
400
     * @depends testCreateContentType

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

@@ 22-55 (lines=34) @@
19
     *
20
     * @return string Object state group href
21
     */
22
    public function testCreateObjectStateGroup()
23
    {
24
        $body = <<< XML
25
<?xml version="1.0" encoding="UTF-8"?>
26
<ObjectStateGroupCreate>
27
  <identifier>testCreateObjectStateGroup</identifier>
28
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
29
  <names>
30
    <value languageCode="eng-GB">testCreateObjectStateGroup</value>
31
  </names>
32
  <descriptions>
33
    <value languageCode="eng-GB">testCreateObjectStateGroup description</value>
34
  </descriptions>
35
</ObjectStateGroupCreate>
36
XML;
37
38
        $request = $this->createHttpRequest(
39
            'POST',
40
            '/api/ezp/v2/content/objectstategroups',
41
            'ObjectStateGroupCreate+xml',
42
            'ObjectStateGroup+json'
43
        );
44
        $request->setContent($body);
45
46
        $response = $this->sendHttpRequest($request);
47
48
        self::assertHttpResponseCodeEquals($response, 201);
49
        self::assertHttpResponseHasHeader($response, 'Location');
50
51
        $href = $response->getHeader('Location');
52
        $this->addCreatedElement($href);
53
54
        return $href;
55
    }
56
57
    /**
58
     * @covers POST /content/objectstategroups/{objectStateGroupId}/objectstates
@@ 63-97 (lines=35) @@
60
     * @return string Object state href
61
     * @depends testCreateObjectStateGroup
62
     */
63
    public function testCreateObjectState($objectStateGroupHref)
64
    {
65
        $body = <<< XML
66
<?xml version="1.0" encoding="UTF-8"?>
67
<ObjectStateCreate>
68
  <identifier>testCreateObjectState</identifier>
69
  <priority>4</priority>
70
  <defaultLanguageCode>eng-GB</defaultLanguageCode>
71
  <names>
72
    <value languageCode="eng-GB">testCreateObjectState</value>
73
  </names>
74
  <descriptions>
75
    <value languageCode="eng-GB">testCreateObjectState description</value>
76
  </descriptions>
77
</ObjectStateCreate>
78
XML;
79
80
        $request = $this->createHttpRequest(
81
            'POST',
82
            "$objectStateGroupHref/objectstates",
83
            'ObjectStateCreate+xml',
84
            'ObjectState+json'
85
        );
86
        $request->setContent($body);
87
88
        $response = $this->sendHttpRequest($request);
89
90
        self::assertHttpResponseCodeEquals($response, 201);
91
        self::assertHttpResponseHasHeader($response, 'Location');
92
93
        $href = $response->getHeader('Location');
94
        $this->addCreatedElement($href);
95
96
        return $href;
97
    }
98
99
    /**
100
     * @covers GET /content/objectstategroups/{objectStateGroupId}
@@ 156-175 (lines=20) @@
153
     *
154
     * @return string The created folder content href
155
     */
156
    public function testSetObjectStatesForContent($objectStateHref)
157
    {
158
        $folder = $this->createFolder(__FUNCTION__, '/api/ezp/v2/content/locations/1/2');
159
160
        $xml = <<< XML
161
<?xml version="1.0" encoding="UTF-8"?>
162
<ContentObjectStates>
163
 <ObjectState href="$objectStateHref"/>
164
</ContentObjectStates>
165
XML;
166
167
        $folderHref = $folder['_href'];
168
        $request = $this->createHttpRequest('PATCH', "$folderHref/objectstates", 'ContentObjectStates+xml', 'ContentObjectStates+json');
169
        $request->setContent($xml);
170
        $response = $this->sendHttpRequest($request);
171
172
        self::assertHttpResponseCodeEquals($response, 200);
173
174
        return $folderHref;
175
    }
176
177
    /**
178
     * @covers GET /content/objects/{contentId}/objectstates

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

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

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

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

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

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

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

@@ 25-51 (lines=27) @@
22
     *
23
     * @return string The created role href
24
     */
25
    public function testCreateRole()
26
    {
27
        $xml = <<< XML
28
<?xml version="1.0" encoding="UTF-8"?>
29
<RoleInput>
30
  <identifier>testCreateRole</identifier>
31
  <mainLanguageCode>eng-GB</mainLanguageCode>
32
  <names>
33
    <value languageCode="eng-GB">testCreateRole</value>
34
  </names>
35
  <descriptions>
36
    <value languageCode="eng-GB">testCreateRole description</value>
37
  </descriptions>
38
</RoleInput>
39
XML;
40
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/user/roles', 'RoleInput+xml', 'Role+json');
41
        $request->setContent($xml);
42
        $response = $this->sendHttpRequest($request);
43
44
        self::assertHttpResponseCodeEquals($response, 201);
45
        self::assertHttpResponseHasHeader($response, 'Location');
46
47
        $href = $response->getHeader('Location');
48
        $this->addCreatedElement($href);
49
50
        return $href;
51
    }
52
53
    /**
54
     * @covers POST /user/roles
@@ 60-91 (lines=32) @@
57
     *
58
     * @return string The created role draft href
59
     */
60
    public function testCreateRoleWithDraft()
61
    {
62
        $xml = <<< XML
63
<?xml version="1.0" encoding="UTF-8"?>
64
<RoleInput>
65
  <identifier>testCreateRoleDraft</identifier>
66
  <mainLanguageCode>eng-GB</mainLanguageCode>
67
  <names>
68
    <value languageCode="eng-GB">testCreateRoleDraft</value>
69
  </names>
70
  <descriptions>
71
    <value languageCode="eng-GB">testCreateRoleDraft description</value>
72
  </descriptions>
73
</RoleInput>
74
XML;
75
        $request = $this->createHttpRequest(
76
            'POST',
77
            '/api/ezp/v2/user/roles?publish=false',
78
            'RoleInput+xml',
79
            'RoleDraft+json'
80
        );
81
        $request->setContent($xml);
82
        $response = $this->sendHttpRequest($request);
83
84
        self::assertHttpResponseCodeEquals($response, 201);
85
        self::assertHttpResponseHasHeader($response, 'Location');
86
87
        $href = $response->getHeader('Location');
88
        $this->addCreatedElement($href);
89
90
        return $href . '/draft';
91
    }
92
93
    /**
94
     * @covers GET /user/roles
@@ 124-155 (lines=32) @@
121
     *
122
     * @return string The created role draft href
123
     */
124
    public function testCreateRoleDraft($roleHref)
125
    {
126
        $xml = <<< XML
127
<?xml version="1.0" encoding="UTF-8"?>
128
<RoleInput>
129
  <identifier>testCreateRoleDraft</identifier>
130
  <mainLanguageCode>eng-GB</mainLanguageCode>
131
  <names>
132
    <value languageCode="eng-GB">testCreateRoleDraft</value>
133
  </names>
134
  <descriptions>
135
    <value languageCode="eng-GB">testCreateRoleDraft description</value>
136
  </descriptions>
137
</RoleInput>
138
XML;
139
        $request = $this->createHttpRequest(
140
            'POST',
141
            $roleHref,
142
            'RoleInput+xml',
143
            'RoleDraft+json'
144
        );
145
        $request->setContent($xml);
146
        $response = $this->sendHttpRequest($request);
147
148
        self::assertHttpResponseCodeEquals($response, 201);
149
        self::assertHttpResponseHasHeader($response, 'Location');
150
151
        $href = $response->getHeader('Location');
152
        $this->addCreatedElement($href);
153
154
        return $href . '/draft';
155
    }
156
157
    /**
158
     * @depends testCreateRoleDraft
@@ 231-259 (lines=29) @@
228
     *
229
     * @return string The created policy href
230
     */
231
    public function testAddPolicy($roleHref)
232
    {
233
        // @todo Error in Resource URL in spec @ https://github.com/ezsystems/ezpublish-kernel/blob/master/doc/specifications/rest/REST-API-V2.rst#151213create-policy
234
        $xml = <<< XML
235
<?xml version="1.0" encoding="UTF-8"?>
236
<PolicyCreate>
237
  <module>content</module>
238
  <function>create</function>
239
  <limitations>
240
    <limitation identifier="Class">
241
      <values>
242
        <ref href="2"/>
243
      </values>
244
    </limitation>
245
  </limitations>
246
</PolicyCreate>
247
XML;
248
        $request = $this->createHttpRequest('POST', "$roleHref/policies", 'PolicyCreate+xml', 'Policy+json');
249
        $request->setContent($xml);
250
251
        $response = $this->sendHttpRequest($request);
252
        self::assertHttpResponseCodeEquals($response, 201);
253
        self::assertHttpResponseHasHeader($response, 'Location');
254
255
        $href = $response->getHeader('Location');
256
        $this->addCreatedElement($href);
257
258
        return $href;
259
    }
260
261
    /**
262
     * @covers POST /user/roles/{roleId}/policies
@@ 267-299 (lines=33) @@
264
     *
265
     * @return string The created policy href
266
     */
267
    public function testAddPolicyByRoleDraft($roleDraftHref)
268
    {
269
        $xml = <<< XML
270
<?xml version="1.0" encoding="UTF-8"?>
271
<PolicyCreate>
272
  <module>content</module>
273
  <function>create</function>
274
  <limitations>
275
    <limitation identifier="Class">
276
      <values>
277
        <ref href="1"/>
278
      </values>
279
    </limitation>
280
  </limitations>
281
</PolicyCreate>
282
XML;
283
        $request = $this->createHttpRequest(
284
            'POST',
285
            $this->roleDraftHrefToRoleHref($roleDraftHref) . '/policies',
286
            'PolicyCreate+xml',
287
            'Policy+json'
288
        );
289
        $request->setContent($xml);
290
291
        $response = $this->sendHttpRequest($request);
292
        self::assertHttpResponseCodeEquals($response, 201);
293
        self::assertHttpResponseHasHeader($response, 'Location');
294
295
        $href = $response->getHeader('Location');
296
        $this->addCreatedElement($href);
297
298
        return $href;
299
    }
300
301
    /**
302
     * @covers GET /user/roles/{roleId}/policies/{policyId}