|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Bundle\EzPublishRestBundle\Tests\Functional\TestCase as RESTFunctionalTestCase; |
|
10
|
|
|
use SimpleXMLElement; |
|
11
|
|
|
|
|
12
|
|
|
class SortClauseTest extends RESTFunctionalTestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testFieldSortClause() |
|
15
|
|
|
{ |
|
16
|
|
|
$string = $this->addTestSuffix(__FUNCTION__); |
|
17
|
|
|
$mainTestFolderContent = $this->createFolder($string, '/api/ezp/v2/content/locations/1/2'); |
|
18
|
|
|
|
|
19
|
|
|
$response = $this->sendHttpRequest( |
|
20
|
|
|
$this->createHttpRequest('GET', $mainTestFolderContent['_href'], '', 'Content+json') |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
self::assertHttpResponseCodeEquals($response, 200); |
|
24
|
|
|
|
|
25
|
|
|
$mainFolderContent = json_decode($response->getContent(), true); |
|
26
|
|
|
|
|
27
|
|
|
if (!isset($mainFolderContent['Content']['MainLocation']['_href'])) { |
|
28
|
|
|
self::fail("Incomplete response (no main location):\n" . $response->getContent() . "\n"); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$mainFolderLocationHref = $mainFolderContent['Content']['MainLocation']['_href']; |
|
32
|
|
|
|
|
33
|
|
|
$locationArray = explode('/', $mainFolderLocationHref); |
|
34
|
|
|
$mainFolderLocationId = array_pop($locationArray); |
|
35
|
|
|
|
|
36
|
|
|
$foldersForSorting = [ |
|
37
|
|
|
'AAA', |
|
38
|
|
|
'BBB', |
|
39
|
|
|
'CCC', |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
$foldersNames = []; |
|
43
|
|
|
|
|
44
|
|
|
foreach ($foldersForSorting as $folder) { |
|
45
|
|
|
$folderContent = $this->createFolder($folder, $mainFolderLocationHref); |
|
46
|
|
|
$foldersNames[$folder] = $folderContent['Name']; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
$body = <<< XML |
|
50
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
|
51
|
|
|
<ViewInput> |
|
52
|
|
|
<identifier>TestView</identifier> |
|
53
|
|
|
<LocationQuery> |
|
54
|
|
|
<Filter> |
|
55
|
|
|
<ParentLocationIdCriterion>{$mainFolderLocationId}</ParentLocationIdCriterion> |
|
56
|
|
|
</Filter> |
|
57
|
|
|
<limit>10</limit> |
|
58
|
|
|
<offset>0</offset> |
|
59
|
|
|
<SortClauses> |
|
60
|
|
|
<Field identifier="folder/name">descending</Field> |
|
61
|
|
|
</SortClauses> |
|
62
|
|
|
<FacetBuilders> |
|
63
|
|
|
<contentTypeFacetBuilder/> |
|
64
|
|
|
</FacetBuilders> |
|
65
|
|
|
</LocationQuery> |
|
66
|
|
|
</ViewInput> |
|
67
|
|
|
XML; |
|
68
|
|
|
$request = $this->createHttpRequest('POST', '/api/ezp/v2/content/views', 'ViewInput+xml; version=1.1', 'View+xml'); |
|
69
|
|
|
$request->setContent($body); |
|
70
|
|
|
|
|
71
|
|
|
$response = $this->sendHttpRequest( |
|
72
|
|
|
$request |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$xml = new SimpleXMLElement($response->getContent()); |
|
76
|
|
|
|
|
77
|
|
|
$searchHits = []; |
|
78
|
|
|
foreach ($xml->xpath('//Name') as $searchHit) { |
|
79
|
|
|
$searchHits[] = (string) $searchHit[0]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
self::assertCount(3, $searchHits); |
|
83
|
|
|
self::assertEquals($foldersNames['CCC'], $searchHits[0]); |
|
84
|
|
|
self::assertEquals($foldersNames['BBB'], $searchHits[1]); |
|
85
|
|
|
self::assertEquals($foldersNames['AAA'], $searchHits[2]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|