Code Duplication    Length = 20-55 lines in 17 locations

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

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

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
        );
42
        $request->setContent($body);
43
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
     * 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
        );
84
        $request->setContent($body);
85
86
        $response = $this->sendHttpRequest($request);
87
88
        self::assertHttpResponseCodeEquals($response, 201);
89
        self::assertHttpResponseHasHeader($response, 'Location');
90
91
        $href = $response->getHeader('Location');
92
        $this->addCreatedElement($href);
93
94
        return $href;
95
    }
96
97
    /**
98
     * Covers GET /content/objectstategroups/{objectStateGroupId}.
@@ 154-173 (lines=20) @@
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('PATCH', "$folderHref/objectstates", 'ContentObjectStates+xml', 'ContentObjectStates+json');
167
        $request->setContent($xml);
168
        $response = $this->sendHttpRequest($request);
169
170
        self::assertHttpResponseCodeEquals($response, 200);
171
172
        return $folderHref;
173
    }
174
175
    /**
176
     * Covers GET /content/objects/{contentId}/objectstates.

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

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

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

@@ 32-51 (lines=20) @@
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('POST', '/api/ezp/v2/content/sections', 'SectionInput+xml', 'Section+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
     * @param $sectionHref

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

@@ 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
        );
102
        $request->setContent($xml);
103
104
        $response = $this->sendHttpRequest($request);
105
106
        self::assertHttpResponseCodeEquals($response, 201);
107
        self::assertHttpResponseHasHeader($response, 'Location');
108
109
        $href = $response->getHeader('Location');
110
        $this->addCreatedElement($href);
111
112
        return $href;
113
    }
114
115
    /**
116
     * @depends testCreateUrlAlias
@@ 45-76 (lines=32) @@
42
     * Covers POST /content/urlaliases
43
     * @returns string The created url alias href
44
     */
45
    public function testCreateUrlAlias($locationHref)
46
    {
47
        $text = $this->addTestSuffix(__FUNCTION__);
48
        $xml = <<< XML
49
<?xml version="1.0" encoding="UTF-8"?>
50
<UrlAliasCreate type="LOCATION">
51
  <location href="{$locationHref}" />
52
  <path>/{$text}</path>
53
  <languageCode>eng-GB</languageCode>
54
  <alwaysAvailable>false</alwaysAvailable>
55
  <forward>true</forward>
56
</UrlAliasCreate>
57
XML;
58
59
        $request = $this->createHttpRequest(
60
            'POST',
61
            '/api/ezp/v2/content/urlaliases',
62
            'UrlAliasCreate+xml',
63
            'UrlAlias+json'
64
        );
65
        $request->setContent($xml);
66
67
        $response = $this->sendHttpRequest($request);
68
69
        self::assertHttpResponseCodeEquals($response, 201);
70
        self::assertHttpResponseHasHeader($response, 'Location');
71
72
        $href = $response->getHeader('Location');
73
        $this->addCreatedElement($href);
74
75
        return $href;
76
    }
77
78
    /**
79
     * Covers POST /content/urlaliases.

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

@@ 31-55 (lines=25) @@
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('POST', '/api/ezp/v2/content/urlwildcards', 'UrlWildcardCreate+xml', 'UrlWildcard+json');
44
        $request->setContent($xml);
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
     * @param $urlWildcardHref

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

@@ 21-62 (lines=42) @@
18
     *
19
     * @return string REST content ID
20
     */
21
    public function testCreateContent()
22
    {
23
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/content/objects', 'ContentCreate+xml', 'ContentInfo+json');
24
        $string = $this->addTestSuffix(__FUNCTION__);
25
        $body = <<< XML
26
<?xml version="1.0" encoding="UTF-8"?>
27
<ContentCreate>
28
  <ContentType href="/api/ezp/v2/content/types/1" />
29
  <mainLanguageCode>eng-GB</mainLanguageCode>
30
  <LocationCreate>
31
    <ParentLocation href="/api/ezp/v2/content/locations/1/2" />
32
    <priority>0</priority>
33
    <hidden>false</hidden>
34
    <sortField>PATH</sortField>
35
    <sortOrder>ASC</sortOrder>
36
  </LocationCreate>
37
  <Section href="/api/ezp/v2/content/sections/1" />
38
  <alwaysAvailable>true</alwaysAvailable>
39
  <remoteId>{$string}</remoteId>
40
  <User href="/api/ezp/v2/user/users/14" />
41
  <modificationDate>2012-09-30T12:30:00</modificationDate>
42
  <fields>
43
    <field>
44
      <fieldDefinitionIdentifier>name</fieldDefinitionIdentifier>
45
      <languageCode>eng-GB</languageCode>
46
      <fieldValue>{$string}</fieldValue>
47
    </field>
48
  </fields>
49
</ContentCreate>
50
XML;
51
        $request->setContent($body);
52
53
        $response = $this->sendHttpRequest($request);
54
55
        self::assertHttpResponseCodeEquals($response, 201);
56
        self::assertHttpResponseHasHeader($response, 'Location');
57
58
        $href = $response->getHeader('Location');
59
        $this->addCreatedElement($href);
60
61
        return $href;
62
    }
63
64
    /**
65
     * @depends testCreateContent