|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the SessionInputTest 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\Publish\Core\REST\Server\Tests\Input\Parser; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
|
12
|
|
|
use eZ\Publish\Core\REST\Server\Input\Parser\ContentQuery as QueryParser; |
|
13
|
|
|
|
|
14
|
|
|
class QueryParserTest extends BaseTest |
|
15
|
|
|
{ |
|
16
|
|
|
public function testParseEmptyQuery() |
|
17
|
|
|
{ |
|
18
|
|
|
$inputArray = array( |
|
19
|
|
|
'Filter' => [], |
|
20
|
|
|
'Criteria' => [], |
|
21
|
|
|
'Query' => [], |
|
22
|
|
|
); |
|
23
|
|
|
|
|
24
|
|
|
$parsingDispatcher = $this->getParsingDispatcherMock(); |
|
25
|
|
|
$parser = $this->getParser(); |
|
26
|
|
|
|
|
27
|
|
|
$result = $parser->parse($inputArray, $parsingDispatcher); |
|
28
|
|
|
|
|
29
|
|
|
$expectedQuery = new Query(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals($expectedQuery, $result); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
View Code Duplication |
public function testDispatchOneFilter() |
|
35
|
|
|
{ |
|
36
|
|
|
$inputArray = array( |
|
37
|
|
|
'Filter' => ['ContentTypeIdentifierCriterion' => 'article'], |
|
38
|
|
|
'Criteria' => [], |
|
39
|
|
|
'Query' => [], |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
|
|
$parsingDispatcher = $this->getParsingDispatcherMock(); |
|
43
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('parse') |
|
46
|
|
|
->with(['ContentTypeIdentifierCriterion' => 'article']) |
|
47
|
|
|
->will($this->returnValue(new Query\Criterion\ContentTypeIdentifier('article'))); |
|
48
|
|
|
|
|
49
|
|
|
$parser = $this->getParser(); |
|
50
|
|
|
|
|
51
|
|
|
$result = $parser->parse($inputArray, $parsingDispatcher); |
|
52
|
|
|
|
|
53
|
|
|
$expectedQuery = new Query(); |
|
54
|
|
|
$expectedQuery->filter = new Query\Criterion\ContentTypeIdentifier('article'); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertEquals($expectedQuery, $result); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
public function testDispatchMoreThanOneFilter() |
|
60
|
|
|
{ |
|
61
|
|
|
$inputArray = array( |
|
62
|
|
|
'Filter' => ['ContentTypeIdentifierCriterion' => 'article', 'ParentLocationIdCriterion' => 762], |
|
63
|
|
|
'Criteria' => [], |
|
64
|
|
|
'Query' => [], |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
$parsingDispatcher = $this->getParsingDispatcherMock(); |
|
68
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
69
|
|
|
->expects($this->at(0)) |
|
70
|
|
|
->method('parse') |
|
71
|
|
|
->with(['ContentTypeIdentifierCriterion' => 'article']) |
|
72
|
|
|
->will($this->returnValue(new Query\Criterion\ContentTypeIdentifier('article'))); |
|
73
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
74
|
|
|
->expects($this->at(1)) |
|
75
|
|
|
->method('parse') |
|
76
|
|
|
->with(['ParentLocationIdCriterion' => 762]) |
|
77
|
|
|
->will($this->returnValue(new Query\Criterion\ParentLocationId(762))); |
|
78
|
|
|
|
|
79
|
|
|
$parser = $this->getParser(); |
|
80
|
|
|
|
|
81
|
|
|
$result = $parser->parse($inputArray, $parsingDispatcher); |
|
82
|
|
|
|
|
83
|
|
|
$expectedQuery = new Query(); |
|
84
|
|
|
$expectedQuery->filter = new Query\Criterion\LogicalAnd([ |
|
85
|
|
|
new Query\Criterion\ContentTypeIdentifier('article'), |
|
86
|
|
|
new Query\Criterion\ParentLocationId(762), |
|
87
|
|
|
]); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertEquals($expectedQuery, $result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
public function testDispatchOneQueryItem() |
|
93
|
|
|
{ |
|
94
|
|
|
$inputArray = array( |
|
95
|
|
|
'Query' => ['ContentTypeIdentifierCriterion' => 'article'], |
|
96
|
|
|
'Criteria' => [], |
|
97
|
|
|
'Filter' => [], |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$parsingDispatcher = $this->getParsingDispatcherMock(); |
|
101
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
102
|
|
|
->expects($this->once()) |
|
103
|
|
|
->method('parse') |
|
104
|
|
|
->with(['ContentTypeIdentifierCriterion' => 'article']) |
|
105
|
|
|
->will($this->returnValue(new Query\Criterion\ContentTypeIdentifier('article'))); |
|
106
|
|
|
|
|
107
|
|
|
$parser = $this->getParser(); |
|
108
|
|
|
|
|
109
|
|
|
$result = $parser->parse($inputArray, $parsingDispatcher); |
|
110
|
|
|
|
|
111
|
|
|
$expectedQuery = new Query(); |
|
112
|
|
|
$expectedQuery->query = new Query\Criterion\ContentTypeIdentifier('article'); |
|
113
|
|
|
|
|
114
|
|
|
$this->assertEquals($expectedQuery, $result); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
View Code Duplication |
public function testDispatchMoreThanOneQueryItem() |
|
118
|
|
|
{ |
|
119
|
|
|
$inputArray = array( |
|
120
|
|
|
'Query' => ['ContentTypeIdentifierCriterion' => 'article', 'ParentLocationIdCriterion' => 762], |
|
121
|
|
|
'Criteria' => [], |
|
122
|
|
|
'Filter' => [], |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
$parsingDispatcher = $this->getParsingDispatcherMock(); |
|
126
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
127
|
|
|
->expects($this->at(0)) |
|
128
|
|
|
->method('parse') |
|
129
|
|
|
->with(['ContentTypeIdentifierCriterion' => 'article']) |
|
130
|
|
|
->will($this->returnValue(new Query\Criterion\ContentTypeIdentifier('article'))); |
|
131
|
|
|
$parsingDispatcher |
|
|
|
|
|
|
132
|
|
|
->expects($this->at(1)) |
|
133
|
|
|
->method('parse') |
|
134
|
|
|
->with(['ParentLocationIdCriterion' => 762]) |
|
135
|
|
|
->will($this->returnValue(new Query\Criterion\ParentLocationId(762))); |
|
136
|
|
|
|
|
137
|
|
|
$parser = $this->getParser(); |
|
138
|
|
|
|
|
139
|
|
|
$result = $parser->parse($inputArray, $parsingDispatcher); |
|
140
|
|
|
|
|
141
|
|
|
$expectedQuery = new Query(); |
|
142
|
|
|
$expectedQuery->query = new Query\Criterion\LogicalAnd([ |
|
143
|
|
|
new Query\Criterion\ContentTypeIdentifier('article'), |
|
144
|
|
|
new Query\Criterion\ParentLocationId(762), |
|
145
|
|
|
]); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertEquals($expectedQuery, $result); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Returns the session input parser. |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function internalGetParser() |
|
154
|
|
|
{ |
|
155
|
|
|
return new QueryParser(); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.