This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Unit\Filter; |
||
15 | |||
16 | use Sonata\AdminBundle\Form\Type\Filter\ChoiceType; |
||
17 | use Sonata\DoctrinePHPCRAdminBundle\Filter\ChoiceFilter; |
||
18 | |||
19 | class ChoiceFilterTest extends BaseTestCase |
||
20 | { |
||
21 | protected function setUp(): void |
||
22 | { |
||
23 | parent::setUp(); |
||
24 | $this->filter = new ChoiceFilter(); |
||
25 | } |
||
26 | |||
27 | public function testFilterNullData(): void |
||
28 | { |
||
29 | $res = $this->filter->filter($this->proxyQuery, null, 'somefield', null); |
||
30 | $this->assertNull($res); |
||
31 | $this->assertFalse($this->filter->isActive()); |
||
32 | } |
||
33 | |||
34 | public function testFilterEmptyArrayData(): void |
||
35 | { |
||
36 | $res = $this->filter->filter($this->proxyQuery, null, 'somefield', []); |
||
37 | $this->assertNull($res); |
||
38 | $this->assertFalse($this->filter->isActive()); |
||
39 | } |
||
40 | |||
41 | public function testFilterEmptyArrayDataSpecifiedType(): void |
||
42 | { |
||
43 | $res = $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => ChoiceType::TYPE_EQUAL]); |
||
0 ignored issues
–
show
|
|||
44 | $this->assertNull($res); |
||
45 | $this->assertFalse($this->filter->isActive()); |
||
46 | } |
||
47 | |||
48 | public function getMeaninglessValues() |
||
49 | { |
||
50 | return [ |
||
51 | [' '], |
||
52 | [null], |
||
53 | [false], |
||
54 | [[]], |
||
55 | [['', ' ']], |
||
56 | ]; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @dataProvider getMeaninglessValues |
||
61 | */ |
||
62 | public function testFilterEmptyArrayDataWithMeaninglessValue($value): void |
||
63 | { |
||
64 | $this->filter->filter($this->proxyQuery, null, 'somefield', ['type' => ChoiceType::TYPE_EQUAL, 'value' => $value]); |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...\ChoiceType::TYPE_EQUAL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use ContainsOperatorType::TYPE_EQUAL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
65 | $this->assertFalse($this->filter->isActive()); |
||
66 | } |
||
67 | |||
68 | public function getFilters() |
||
69 | { |
||
70 | return [ |
||
71 | ['eq', ChoiceType::TYPE_EQUAL], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...\ChoiceType::TYPE_EQUAL has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use ContainsOperatorType::TYPE_EQUAL instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
72 | ['textSearch', ChoiceType::TYPE_NOT_CONTAINS, '* -somevalue'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...Type::TYPE_NOT_CONTAINS has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use ContainsOperatorType::TYPE_NOT_CONTAINS instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
73 | ['like', ChoiceType::TYPE_CONTAINS, '%somevalue%'], |
||
0 ignored issues
–
show
The constant
Sonata\AdminBundle\Form\...oiceType::TYPE_CONTAINS has been deprecated with message: since sonata-project/admin-bundle 3.57, to be removed with 4.0: Use ContainsOperatorType::TYPE_CONTAINS instead
This class constant has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.
Loading history...
|
|||
74 | ]; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @dataProvider getFilters |
||
79 | */ |
||
80 | public function testFilterSwitch($operatorMethod, $choiceType, $expectedValue = 'somevalue'): void |
||
81 | { |
||
82 | $this->proxyQuery->expects($this->once()) |
||
83 | ->method('getQueryBuilder') |
||
84 | ->willReturn($this->qb); |
||
85 | |||
86 | $this->filter->filter( |
||
87 | $this->proxyQuery, |
||
88 | null, |
||
89 | 'somefield', |
||
90 | ['type' => $choiceType, 'value' => 'somevalue'] |
||
91 | ); |
||
92 | $this->assertTrue($this->filter->isActive()); |
||
93 | } |
||
94 | |||
95 | public function getFiltersMultiple() |
||
96 | { |
||
97 | return [ |
||
98 | [[ |
||
99 | 'choiceType' => ChoiceType::TYPE_NOT_CONTAINS, |
||
100 | 'value' => 'somevalue', |
||
101 | 'qbNodeCount' => 6, |
||
102 | 'assertPaths' => [ |
||
103 | 'where.constraint.constraint[0].constraint.operand_dynamic' => [ |
||
104 | 'getAlias' => 'a', |
||
105 | 'getField' => 'somefield', |
||
106 | ], |
||
107 | 'where.constraint.constraint[0].constraint.operand_static' => [ |
||
108 | 'getValue' => '%somevalue%', |
||
109 | ], |
||
110 | ], |
||
111 | ]], |
||
112 | [[ |
||
113 | 'choiceType' => ChoiceType::TYPE_NOT_CONTAINS, |
||
114 | 'value' => ['somevalue', 'somevalue'], |
||
115 | 'qbNodeCount' => 10, |
||
116 | 'assertPaths' => [ |
||
117 | 'where.constraint.constraint.constraint.operand_dynamic' => [ |
||
118 | 'getAlias' => 'a', |
||
119 | 'getField' => 'somefield', |
||
120 | ], |
||
121 | 'where.constraint.constraint.constraint.operand_static' => [ |
||
122 | 'getValue' => '%somevalue%', |
||
123 | ], |
||
124 | 'where.constraint.constraint[1].constraint.operand_dynamic' => [ |
||
125 | 'getAlias' => 'a', |
||
126 | 'getField' => 'somefield', |
||
127 | ], |
||
128 | 'where.constraint.constraint[1].constraint.operand_static' => [ |
||
129 | 'getValue' => '%somevalue%', |
||
130 | ], |
||
131 | ], |
||
132 | ]], |
||
133 | [[ |
||
134 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
135 | 'value' => 'somevalue', |
||
136 | 'qbNodeCount' => 5, |
||
137 | 'assertPaths' => [ |
||
138 | 'where.constraint.constraint.operand_dynamic' => [ |
||
139 | 'getAlias' => 'a', |
||
140 | 'getField' => 'somefield', |
||
141 | ], |
||
142 | 'where.constraint.constraint.operand_static' => [ |
||
143 | 'getValue' => '%somevalue%', |
||
144 | ], |
||
145 | 'where.constraint.constraint.operand_static' => [ |
||
146 | 'getValue' => '%somevalue%', |
||
147 | ], |
||
148 | ], |
||
149 | ]], |
||
150 | [[ |
||
151 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
152 | 'value' => ['somevalue', 'somevalue'], |
||
153 | 'qbNodeCount' => 8, |
||
154 | 'assertPaths' => [ |
||
155 | 'where.constraint.constraint.operand_dynamic' => [ |
||
156 | 'getAlias' => 'a', |
||
157 | 'getField' => 'somefield', |
||
158 | ], |
||
159 | 'where.constraint.constraint.operand_static' => [ |
||
160 | 'getValue' => '%somevalue%', |
||
161 | ], |
||
162 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
163 | 'getAlias' => 'a', |
||
164 | 'getField' => 'somefield', |
||
165 | ], |
||
166 | 'where.constraint.constraint[1].operand_static' => [ |
||
167 | 'getValue' => '%somevalue%', |
||
168 | ], |
||
169 | ], |
||
170 | ]], |
||
171 | [[ |
||
172 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
173 | 'value' => 'somevalue', |
||
174 | 'qbNodeCount' => 5, |
||
175 | 'assertPaths' => [ |
||
176 | 'where.constraint.constraint.operand_dynamic' => [ |
||
177 | 'getAlias' => 'a', |
||
178 | 'getField' => 'somefield', |
||
179 | ], |
||
180 | 'where.constraint.constraint.operand_static' => [ |
||
181 | 'getValue' => '%somevalue%', |
||
182 | ], |
||
183 | 'where.constraint.constraint.operand_static' => [ |
||
184 | 'getValue' => '%somevalue%', |
||
185 | ], |
||
186 | ], |
||
187 | ]], |
||
188 | [[ |
||
189 | 'choiceType' => ChoiceType::TYPE_CONTAINS, |
||
190 | 'value' => ['somevalue', 'somevalue'], |
||
191 | 'qbNodeCount' => 8, |
||
192 | 'assertPaths' => [ |
||
193 | 'where.constraint.constraint.operand_dynamic' => [ |
||
194 | 'getAlias' => 'a', |
||
195 | 'getField' => 'somefield', |
||
196 | ], |
||
197 | 'where.constraint.constraint.operand_static' => [ |
||
198 | 'getValue' => '%somevalue%', |
||
199 | ], |
||
200 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
201 | 'getAlias' => 'a', |
||
202 | 'getField' => 'somefield', |
||
203 | ], |
||
204 | 'where.constraint.constraint[1].operand_static' => [ |
||
205 | 'getValue' => '%somevalue%', |
||
206 | ], |
||
207 | ], |
||
208 | ]], |
||
209 | [[ |
||
210 | 'choiceType' => ChoiceType::TYPE_EQUAL, |
||
211 | 'value' => 'somevalue', |
||
212 | 'qbNodeCount' => 5, |
||
213 | 'assertPaths' => [ |
||
214 | 'where.constraint.constraint.operand_dynamic' => [ |
||
215 | 'getAlias' => 'a', |
||
216 | 'getField' => 'somefield', |
||
217 | ], |
||
218 | 'where.constraint.constraint.operand_static' => [ |
||
219 | 'getValue' => 'somevalue', |
||
220 | ], |
||
221 | 'where.constraint.constraint.operand_static' => [ |
||
222 | 'getValue' => 'somevalue', |
||
223 | ], |
||
224 | ], |
||
225 | ]], |
||
226 | [[ |
||
227 | 'choiceType' => ChoiceType::TYPE_EQUAL, |
||
228 | 'value' => ['somevalue', 'somevalue'], |
||
229 | 'qbNodeCount' => 8, |
||
230 | 'assertPaths' => [ |
||
231 | 'where.constraint.constraint.operand_dynamic' => [ |
||
232 | 'getAlias' => 'a', |
||
233 | 'getField' => 'somefield', |
||
234 | ], |
||
235 | 'where.constraint.constraint.operand_static' => [ |
||
236 | 'getValue' => 'somevalue', |
||
237 | ], |
||
238 | 'where.constraint.constraint[1].operand_dynamic' => [ |
||
239 | 'getAlias' => 'a', |
||
240 | 'getField' => 'somefield', |
||
241 | ], |
||
242 | 'where.constraint.constraint[1].operand_static' => [ |
||
243 | 'getValue' => 'somevalue', |
||
244 | ], |
||
245 | ], |
||
246 | ]], |
||
247 | ]; |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * @dataProvider getFiltersMultiple |
||
252 | */ |
||
253 | public function testFilterMultipleSwitch($options): void |
||
254 | { |
||
255 | $options = array_merge([ |
||
256 | 'choiceType' => null, |
||
257 | 'value' => null, |
||
258 | 'assertPaths' => [], |
||
259 | 'qbNodeCount' => 0, |
||
260 | ], $options); |
||
261 | |||
262 | $this->proxyQuery->expects($this->once()) |
||
263 | ->method('getQueryBuilder') |
||
264 | ->willReturn($this->qb); |
||
265 | |||
266 | $this->filter->filter( |
||
267 | $this->proxyQuery, |
||
268 | null, |
||
269 | 'somefield', |
||
270 | ['type' => $options['choiceType'], 'value' => $options['value']] |
||
271 | ); |
||
272 | |||
273 | foreach ($options['assertPaths'] as $path => $methodAssertions) { |
||
274 | $node = $this->qbTester->getNode($path); |
||
275 | foreach ($methodAssertions as $methodName => $expectedValue) { |
||
276 | $res = $node->$methodName(); |
||
277 | $this->assertSame($expectedValue, $res); |
||
278 | } |
||
279 | } |
||
280 | |||
281 | $this->assertTrue($this->filter->isActive()); |
||
282 | $this->assertSame($options['qbNodeCount'], \count($this->qbTester->getAllNodes())); |
||
283 | } |
||
284 | } |
||
285 |
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.