Code Duplication    Length = 20-42 lines in 16 locations

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 6 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}
@@ 696-724 (lines=29) @@
693
     *
694
     * @return string The href of the published role
695
     */
696
    private function createAndPublishRole($identifier)
697
    {
698
        $xml = <<< XML
699
<?xml version="1.0" encoding="UTF-8"?>
700
<RoleInput>
701
  <identifier>$identifier</identifier>
702
  <mainLanguageCode>eng-GB</mainLanguageCode>
703
  <names>
704
    <value languageCode="eng-GB">$identifier</value>
705
  </names>
706
  <descriptions>
707
    <value languageCode="eng-GB">$identifier description</value>
708
  </descriptions>
709
</RoleInput>
710
XML;
711
        $request = $this->createHttpRequest(
712
            'POST',
713
            '/api/ezp/v2/user/roles',
714
            'RoleInput+xml',
715
            'RoleDraft+json'
716
        );
717
        $request->setContent($xml);
718
        $response = $this->sendHttpRequest($request);
719
720
        self::assertHttpResponseCodeEquals($response, 201);
721
        self::assertHttpResponseHasHeader($response, 'Location');
722
723
        return $response->getHeader('Location');
724
    }
725
}
726

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/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/ContentTest.php 1 location

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

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

@@ 29-49 (lines=21) @@
26
    /**
27
     * @covers POST /content/typegroups
28
     */
29
    public function testCreateContentTypeGroup()
30
    {
31
        $identifier = uniqid('test');
32
        $body = <<< XML
33
<?xml version="1.0" encoding="UTF-8"?>
34
<ContentTypeGroupInput>
35
  <identifier>$identifier</identifier>
36
</ContentTypeGroupInput>
37
XML;
38
        $request = $this->createHttpRequest('POST', '/api/ezp/v2/content/typegroups', 'ContentTypeGroupInput+xml', 'ContentTypeGroup+json');
39
        $request->setContent($body);
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
     * @depends testCreateContentTypeGroup
@@ 361-386 (lines=26) @@
358
     *
359
     * @return string the created content type draft href
360
     */
361
    public function testCreateContentTypeDraft($contentTypeHref)
362
    {
363
        $identifier = uniqid('test');
364
        $content = <<< XML
365
<?xml version="1.0" encoding="UTF-8"?>
366
<ContentTypeUpdate>
367
  <names>
368
    <value languageCode="eng-GB">$identifier</value>
369
  </names>
370
</ContentTypeUpdate>
371
XML;
372
373
        $request = $this->createHttpRequest('POST', $contentTypeHref, 'ContentTypeUpdate+xml', 'ContentTypeInfo+json');
374
        $request->setContent($content);
375
        $response = $this->sendHttpRequest(
376
            $request
377
        );
378
379
        self::assertHttpResponseCodeEquals($response, 201);
380
        self::assertHttpResponseHasHeader($response, 'Location');
381
382
        $href = $response->getHeader('Location');
383
        $this->addCreatedElement($href);
384
385
        return $href;
386
    }
387
388
    /**
389
     * @depends testCreateContentTypeDraft
@@ 431-464 (lines=34) @@
428
     *
429
     * @return string The content type draft field definition href
430
     */
431
    public function testAddContentTypeDraftFieldDefinition($contentTypeDraftHref)
432
    {
433
        $body = <<< XML
434
<?xml version="1.0" encoding="UTF-8"?>
435
<FieldDefinition>
436
      <identifier>secondtext</identifier>
437
      <fieldType>ezstring</fieldType>
438
      <fieldGroup>content</fieldGroup>
439
      <position>1</position>
440
      <isTranslatable>true</isTranslatable>
441
      <isRequired>true</isRequired>
442
      <isInfoCollector>false</isInfoCollector>
443
      <defaultValue>Second text</defaultValue>
444
      <isSearchable>true</isSearchable>
445
      <names>
446
        <value languageCode="eng-GB">Second text</value>
447
      </names>
448
    </FieldDefinition>
449
XML;
450
451
        $request = $this->createHttpRequest(
452
            'POST',
453
            "$contentTypeDraftHref/fieldDefinitions",
454
            'FieldDefinitionCreate+xml',
455
            'FieldDefinition+json'
456
        );
457
        $request->setContent($body);
458
        $response = $this->sendHttpRequest($request);
459
460
        self::assertHttpResponseCodeEquals($response, 201);
461
        self::assertHttpResponseHasHeader($response, 'Location');
462
463
        return $response->getHeader('Location');
464
    }
465
466
    /**
467
     * @depends testCreateContentType

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

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