1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the Functional\ViewTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Bundle\EzPublishRestBundle\Tests\Functional; |
10
|
|
|
|
11
|
|
|
use stdClass; |
12
|
|
|
|
13
|
|
|
class ViewTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @var array */ |
16
|
|
|
private static $createdContentRemoteIds = []; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Covers POST /views. |
20
|
|
|
* |
21
|
|
|
* @dataProvider providerForTestViewRequest |
22
|
|
|
* |
23
|
|
|
* @param string $body |
24
|
|
|
* @param string $format |
25
|
|
|
* @param int $expectedResultsCount |
26
|
|
|
* @param \stdClass[] $contentDataList list of items containing name and remoteId properties |
27
|
|
|
*/ |
28
|
|
|
public function testViewRequest($body, $format, $expectedResultsCount, array $contentDataList) |
29
|
|
|
{ |
30
|
|
|
$this->createTestContentItems($contentDataList); |
31
|
|
|
|
32
|
|
|
// search for Content |
33
|
|
|
$request = $this->createHttpRequest( |
34
|
|
|
'POST', |
35
|
|
|
'/api/ezp/v2/views', |
36
|
|
|
"ViewInput+{$format}", |
37
|
|
|
'View+json' |
38
|
|
|
); |
39
|
|
|
$request->setContent($body); |
40
|
|
|
$response = $this->sendHttpRequest($request); |
41
|
|
|
$responseData = json_decode($response->getContent(), true); |
42
|
|
|
|
43
|
|
|
if (isset($responseData['ErrorMessage'])) { |
44
|
|
|
self::fail(var_export($responseData, true)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
self::assertEquals($expectedResultsCount, $responseData['View']['Result']['count']); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Data provider for testViewRequestWithOrStatement. |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function providerForTestViewRequest() |
56
|
|
|
{ |
57
|
|
|
$foo = new stdClass(); |
58
|
|
|
$foo->name = uniqid('View test content foo'); |
59
|
|
|
$foo->remoteId = md5($foo->name); |
60
|
|
|
|
61
|
|
|
$bar = new stdClass(); |
62
|
|
|
$bar->name = uniqid('View test content bar'); |
63
|
|
|
$bar->remoteId = md5($bar->name); |
64
|
|
|
|
65
|
|
|
return [ |
66
|
|
|
[ |
67
|
|
|
<<< XML |
68
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
69
|
|
|
<ViewInput> |
70
|
|
|
<identifier>TitleView</identifier> |
71
|
|
|
<Query> |
72
|
|
|
<Filter> |
73
|
|
|
<OR> |
74
|
|
|
<ContentRemoteIdCriterion>{$foo->remoteId}</ContentRemoteIdCriterion> |
75
|
|
|
<ContentRemoteIdCriterion>{$bar->remoteId}</ContentRemoteIdCriterion> |
76
|
|
|
</OR> |
77
|
|
|
</Filter> |
78
|
|
|
<limit>10</limit> |
79
|
|
|
<offset>0</offset> |
80
|
|
|
</Query> |
81
|
|
|
</ViewInput> |
82
|
|
|
XML, |
83
|
|
|
'xml', |
84
|
|
|
2, |
85
|
|
|
[$foo, $bar], |
86
|
|
|
], |
87
|
|
|
[ |
88
|
|
|
<<< JSON |
89
|
|
|
{ |
90
|
|
|
"ViewInput": { |
91
|
|
|
"identifier": "TitleView", |
92
|
|
|
"Query": { |
93
|
|
|
"Filter": { |
94
|
|
|
"OR": { |
95
|
|
|
"ContentRemoteIdCriterion": [ |
96
|
|
|
"{$foo->remoteId}", |
97
|
|
|
"{$bar->remoteId}" |
98
|
|
|
] |
99
|
|
|
} |
100
|
|
|
}, |
101
|
|
|
"limit": "10", |
102
|
|
|
"offset": "0" |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
JSON, |
107
|
|
|
'json', |
108
|
|
|
2, |
109
|
|
|
[$foo, $bar], |
110
|
|
|
], |
111
|
|
|
[ |
112
|
|
|
<<< XML |
113
|
|
|
<?xml version="1.0" encoding="UTF-8"?> |
114
|
|
|
<ViewInput> |
115
|
|
|
<identifier>TitleView</identifier> |
116
|
|
|
<Query> |
117
|
|
|
<Filter> |
118
|
|
|
<AND> |
119
|
|
|
<OR> |
120
|
|
|
<ContentRemoteIdCriterion>{$foo->remoteId}</ContentRemoteIdCriterion> |
121
|
|
|
<ContentRemoteIdCriterion>{$bar->remoteId}</ContentRemoteIdCriterion> |
122
|
|
|
</OR> |
123
|
|
|
<ContentRemoteIdCriterion>{$foo->remoteId}</ContentRemoteIdCriterion> |
124
|
|
|
</AND> |
125
|
|
|
</Filter> |
126
|
|
|
<limit>10</limit> |
127
|
|
|
<offset>0</offset> |
128
|
|
|
</Query> |
129
|
|
|
</ViewInput> |
130
|
|
|
XML, |
131
|
|
|
'xml', |
132
|
|
|
1, |
133
|
|
|
[$foo, $bar], |
134
|
|
|
], |
135
|
|
|
[ |
136
|
|
|
<<< JSON |
137
|
|
|
{ |
138
|
|
|
"ViewInput": { |
139
|
|
|
"identifier": "TitleView", |
140
|
|
|
"public": true, |
141
|
|
|
"Query": { |
142
|
|
|
"Filter": { |
143
|
|
|
"OR": [ |
144
|
|
|
{ |
145
|
|
|
"ContentRemoteIdCriterion": "{$foo->remoteId}" |
146
|
|
|
}, |
147
|
|
|
{ |
148
|
|
|
"ContentRemoteIdCriterion": "{$bar->remoteId}" |
149
|
|
|
} |
150
|
|
|
] |
151
|
|
|
}, |
152
|
|
|
"FacetBuilders": {}, |
153
|
|
|
"SortClauses": {}, |
154
|
|
|
"limit": 1000, |
155
|
|
|
"offset": 0 |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
JSON, |
160
|
|
|
'json', |
161
|
|
|
2, |
162
|
|
|
[$foo, $bar], |
163
|
|
|
], |
164
|
|
|
]; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param \stdClass[] $contentDataList |
169
|
|
|
*/ |
170
|
|
|
private function createTestContentItems(array $contentDataList) |
171
|
|
|
{ |
172
|
|
|
foreach ($contentDataList as $contentData) { |
173
|
|
|
// skip creating already created items |
174
|
|
|
if (in_array($contentData->remoteId, self::$createdContentRemoteIds)) { |
175
|
|
|
continue; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
$this->createFolder( |
179
|
|
|
$contentData->name, |
180
|
|
|
'/api/ezp/v2/content/locations/1/2', |
181
|
|
|
$contentData->remoteId |
182
|
|
|
); |
183
|
|
|
self::$createdContentRemoteIds[] = $contentData->remoteId; |
|
|
|
|
184
|
|
|
} |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
|