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/RoleTest.php 5 locations

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

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