Code Duplication    Length = 17-68 lines in 6 locations

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

@@ 378-411 (lines=34) @@
375
     *
376
     * @return string The content type draft field definition href
377
     */
378
    public function testAddContentTypeDraftFieldDefinition($contentTypeDraftHref)
379
    {
380
        $body = <<< XML
381
<?xml version="1.0" encoding="UTF-8"?>
382
<FieldDefinition>
383
      <identifier>secondtext</identifier>
384
      <fieldType>ezstring</fieldType>
385
      <fieldGroup>content</fieldGroup>
386
      <position>1</position>
387
      <isTranslatable>true</isTranslatable>
388
      <isRequired>true</isRequired>
389
      <isInfoCollector>false</isInfoCollector>
390
      <defaultValue>Second text</defaultValue>
391
      <isSearchable>true</isSearchable>
392
      <names>
393
        <value languageCode="eng-GB">Second text</value>
394
      </names>
395
    </FieldDefinition>
396
XML;
397
398
        $request = $this->createHttpRequest(
399
            'POST',
400
            "$contentTypeDraftHref/fieldDefinitions",
401
            'FieldDefinitionCreate+xml',
402
            'FieldDefinition+json',
403
            $body
404
        );
405
        $response = $this->sendHttpRequest($request);
406
407
        self::assertHttpResponseCodeEquals($response, 201);
408
        self::assertHttpResponseHasHeader($response, 'Location');
409
410
        return $response->getHeader('Location')[0];
411
    }
412
413
    /**
414
     * @depends testCreateContentType

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

@@ 83-99 (lines=17) @@
80
    /**
81
     * Covers MOVE /content/trash/{trashItemId} Destination:/content/locations/{locationPath}.
82
     */
83
    public function testRestoreTrashItemWithDestination()
84
    {
85
        $trashItemHref = $this->createTrashItem('testRestoreTrashItemWithDestination');
86
87
        $request = $this->createHttpRequest(
88
            'MOVE',
89
            $trashItemHref,
90
            '',
91
            '',
92
            '',
93
            ['Destination' => '/api/ezp/v2/content/locations/1/2']
94
        );
95
        $response = $this->sendHttpRequest($request);
96
97
        self::assertHttpResponseCodeEquals($response, 201);
98
        self::assertHttpResponseHasHeader($response, 'Location');
99
    }
100
101
    /**
102
     * Covers DELETE /content/trash.
@@ 153-170 (lines=18) @@
150
     *
151
     * @return string
152
     */
153
    private function sendLocationToTrash(string $contentHref): string
154
    {
155
        $trashRequest = $this->createHttpRequest(
156
            'MOVE',
157
            $contentHref,
158
            '',
159
            '',
160
            '',
161
            ['Destination' => '/api/ezp/v2/content/trash']
162
        );
163
        $response = $this->sendHttpRequest($trashRequest);
164
165
        self::assertHttpResponseCodeEquals($response, 201);
166
167
        $trashHref = $response->getHeader('Location')[0];
168
169
        return $trashHref;
170
    }
171
}
172

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

@@ 118-134 (lines=17) @@
115
     *
116
     * @return string the created location's href
117
     */
118
    public function testCopySubtree($locationHref)
119
    {
120
        $request = $this->createHttpRequest(
121
            'COPY',
122
            $locationHref,
123
            '',
124
            '',
125
            '',
126
            ['Destination' => '/api/ezp/v2/content/locations/1/43']
127
        );
128
        $response = $this->sendHttpRequest($request);
129
130
        self::assertHttpResponseCodeEquals($response, 201);
131
        self::assertHttpResponseHasHeader($response, 'Location');
132
133
        return $response->getHeader('Location')[0];
134
    }
135
136
    /**
137
     * Covers MOVE /content/locations/{locationPath}.

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

@@ 88-155 (lines=68) @@
85
        self::assertEquals($expectedCount, $jsonResponse->View->Result->count);
86
    }
87
88
    private function createTestContentType(): string
89
    {
90
        $body = <<< XML
91
<?xml version="1.0" encoding="UTF-8"?>
92
<ContentTypeCreate>
93
  <identifier>tags-test</identifier>
94
  <names>
95
    <value languageCode="eng-GB">testContentQueryWithTags</value>
96
  </names>
97
  <remoteId>testContentQueryWithTags</remoteId>
98
  <urlAliasSchema>&lt;title&gt;</urlAliasSchema>
99
  <nameSchema>&lt;title&gt;</nameSchema>
100
  <isContainer>true</isContainer>
101
  <mainLanguageCode>eng-GB</mainLanguageCode>
102
  <defaultAlwaysAvailable>true</defaultAlwaysAvailable>
103
  <defaultSortField>PATH</defaultSortField>
104
  <defaultSortOrder>ASC</defaultSortOrder>
105
  <FieldDefinitions>
106
    <FieldDefinition>
107
      <identifier>title</identifier>
108
      <fieldType>ezstring</fieldType>
109
      <fieldGroup>content</fieldGroup>
110
      <position>1</position>
111
      <isTranslatable>true</isTranslatable>
112
      <isRequired>true</isRequired>
113
      <isInfoCollector>false</isInfoCollector>
114
      <defaultValue>New Title</defaultValue>
115
      <isSearchable>true</isSearchable>
116
      <names>
117
        <value languageCode="eng-GB">Title</value>
118
      </names>
119
      <descriptions>
120
        <value languageCode="eng-GB">This is the title</value>
121
      </descriptions>
122
    </FieldDefinition>
123
    <FieldDefinition>
124
      <identifier>tags</identifier>
125
      <fieldType>ezkeyword</fieldType>
126
      <fieldGroup>content</fieldGroup>
127
      <position>2</position>
128
      <isTranslatable>true</isTranslatable>
129
      <isRequired>true</isRequired>
130
      <isInfoCollector>false</isInfoCollector>
131
      <isSearchable>true</isSearchable>
132
      <names>
133
        <value languageCode="eng-GB">Tags</value>
134
      </names>
135
      <descriptions>
136
        <value languageCode="eng-GB">Those are searchable tags</value>
137
      </descriptions>
138
    </FieldDefinition>
139
   </FieldDefinitions>
140
</ContentTypeCreate>
141
XML;
142
143
        $request = $this->createHttpRequest(
144
            'POST',
145
            '/api/ezp/v2/content/typegroups/1/types?publish=true',
146
            'ContentTypeCreate+xml',
147
            'ContentType+json',
148
            $body
149
        );
150
        $response = $this->sendHttpRequest($request);
151
152
        self::assertHttpResponseHasHeader($response, 'Location');
153
154
        return $response->getHeader('Location')[0];
155
    }
156
157
    private function createTestContentWithTags(string $name, array $tags): string
158
    {
@@ 321-370 (lines=50) @@
318
     * This is just to assure that field with same name but without legacy search engine implementation
319
     * does not block search in different content type.
320
     */
321
    private function createContentWithUrlField(): string
322
    {
323
        $body = <<< XML
324
<?xml version="1.0" encoding="UTF-8"?>
325
<ContentTypeCreate>
326
  <identifier>rich-text-test</identifier>
327
  <names>
328
    <value languageCode="eng-GB">urlContentType</value>
329
  </names>
330
  <remoteId>testUrlContentType</remoteId>
331
  <urlAliasSchema>&lt;title&gt;</urlAliasSchema>
332
  <nameSchema>&lt;title&gt;</nameSchema>
333
  <isContainer>true</isContainer>
334
  <mainLanguageCode>eng-GB</mainLanguageCode>
335
  <defaultAlwaysAvailable>true</defaultAlwaysAvailable>
336
  <defaultSortField>PATH</defaultSortField>
337
  <defaultSortOrder>ASC</defaultSortOrder>
338
  <FieldDefinitions>
339
    <FieldDefinition>
340
      <identifier>title</identifier>
341
      <fieldType>ezurl</fieldType>
342
      <fieldGroup>content</fieldGroup>
343
      <position>1</position>
344
      <isTranslatable>true</isTranslatable>
345
      <isRequired>true</isRequired>
346
      <isInfoCollector>false</isInfoCollector>
347
      <names>
348
        <value languageCode="eng-GB">Title</value>
349
      </names>
350
      <descriptions>
351
        <value languageCode="eng-GB">This is the title but in url type</value>
352
      </descriptions>
353
    </FieldDefinition>
354
   </FieldDefinitions>
355
</ContentTypeCreate>
356
XML;
357
358
        $request = $this->createHttpRequest(
359
            'POST',
360
            '/api/ezp/v2/content/typegroups/1/types?publish=true',
361
            'ContentTypeCreate+xml',
362
            'ContentType+json',
363
            $body
364
        );
365
366
        $response = $this->sendHttpRequest($request);
367
        self::assertHttpResponseHasHeader($response, 'Location');
368
369
        return $response->getHeader('Location')[0];
370
    }
371
}
372