1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
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\Search\Legacy\Tests\Content; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence; |
12
|
|
|
use eZ\Publish\Core\Search\Legacy\Content; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; |
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
17
|
|
|
use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway as LocationGateway; |
18
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper; |
19
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper as ContentMapper; |
20
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler; |
21
|
|
|
use eZ\Publish\SPI\Persistence\Content\Type; |
22
|
|
|
use eZ\Publish\API\Repository\Exceptions\NotFoundException; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Content Search test case for ContentSearchHandler. |
26
|
|
|
*/ |
27
|
|
|
class HandlerContentTest extends AbstractTestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Returns the content search handler to test. |
31
|
|
|
* |
32
|
|
|
* This method returns a fully functional search handler to perform tests |
33
|
|
|
* on. |
34
|
|
|
* |
35
|
|
|
* @param array $fullTextSearchConfiguration |
36
|
|
|
* |
37
|
|
|
* @return \eZ\Publish\Core\Search\Legacy\Content\Handler |
38
|
|
|
*/ |
39
|
|
|
protected function getContentSearchHandler(array $fullTextSearchConfiguration = []) |
40
|
|
|
{ |
41
|
|
|
$transformationProcessor = new Persistence\TransformationProcessor\DefinitionBased( |
42
|
|
|
new Persistence\TransformationProcessor\DefinitionBased\Parser(), |
43
|
|
|
new Persistence\TransformationProcessor\PcreCompiler( |
44
|
|
|
new Persistence\Utf8Converter() |
45
|
|
|
), |
46
|
|
|
glob(__DIR__ . '/../../../../Persistence/Tests/TransformationProcessor/_fixtures/transformations/*.tr') |
47
|
|
|
); |
48
|
|
|
$commaSeparatedCollectionValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Collection( |
49
|
|
|
$this->getDatabaseHandler(), |
50
|
|
|
$transformationProcessor, |
51
|
|
|
',' |
52
|
|
|
); |
53
|
|
|
$hyphenSeparatedCollectionValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Collection( |
54
|
|
|
$this->getDatabaseHandler(), |
55
|
|
|
$transformationProcessor, |
56
|
|
|
'-' |
57
|
|
|
); |
58
|
|
|
$simpleValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Simple( |
59
|
|
|
$this->getDatabaseHandler(), |
60
|
|
|
$transformationProcessor |
61
|
|
|
); |
62
|
|
|
$compositeValueHandler = new Content\Common\Gateway\CriterionHandler\FieldValue\Handler\Composite( |
63
|
|
|
$this->getDatabaseHandler(), |
64
|
|
|
$transformationProcessor |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
return new Content\Handler( |
68
|
|
|
new Content\Gateway\DoctrineDatabase( |
69
|
|
|
$this->getDatabaseHandler(), |
70
|
|
|
new Content\Common\Gateway\CriteriaConverter( |
71
|
|
|
[ |
72
|
|
|
new Content\Common\Gateway\CriterionHandler\ContentId( |
73
|
|
|
$this->getDatabaseHandler() |
74
|
|
|
), |
75
|
|
|
new Content\Common\Gateway\CriterionHandler\LogicalNot( |
76
|
|
|
$this->getDatabaseHandler() |
77
|
|
|
), |
78
|
|
|
new Content\Common\Gateway\CriterionHandler\LogicalAnd( |
79
|
|
|
$this->getDatabaseHandler() |
80
|
|
|
), |
81
|
|
|
new Content\Common\Gateway\CriterionHandler\LogicalOr( |
82
|
|
|
$this->getDatabaseHandler() |
83
|
|
|
), |
84
|
|
|
new Content\Gateway\CriterionHandler\Subtree( |
85
|
|
|
$this->getDatabaseHandler() |
86
|
|
|
), |
87
|
|
|
new Content\Common\Gateway\CriterionHandler\ContentTypeId( |
88
|
|
|
$this->getDatabaseHandler() |
89
|
|
|
), |
90
|
|
|
new Content\Common\Gateway\CriterionHandler\ContentTypeIdentifier( |
91
|
|
|
$this->getDatabaseHandler(), |
92
|
|
|
$this->getContentTypeHandler() |
93
|
|
|
), |
94
|
|
|
new Content\Common\Gateway\CriterionHandler\ContentTypeGroupId( |
95
|
|
|
$this->getDatabaseHandler() |
96
|
|
|
), |
97
|
|
|
new Content\Common\Gateway\CriterionHandler\DateMetadata( |
98
|
|
|
$this->getDatabaseHandler() |
99
|
|
|
), |
100
|
|
|
new Content\Gateway\CriterionHandler\LocationId( |
101
|
|
|
$this->getDatabaseHandler() |
102
|
|
|
), |
103
|
|
|
new Content\Gateway\CriterionHandler\ParentLocationId( |
104
|
|
|
$this->getDatabaseHandler() |
105
|
|
|
), |
106
|
|
|
new Content\Common\Gateway\CriterionHandler\RemoteId( |
107
|
|
|
$this->getDatabaseHandler() |
108
|
|
|
), |
109
|
|
|
new Content\Gateway\CriterionHandler\LocationRemoteId( |
110
|
|
|
$this->getDatabaseHandler() |
111
|
|
|
), |
112
|
|
|
new Content\Common\Gateway\CriterionHandler\SectionId( |
113
|
|
|
$this->getDatabaseHandler() |
114
|
|
|
), |
115
|
|
|
new Content\Common\Gateway\CriterionHandler\FullText( |
116
|
|
|
$this->getDatabaseHandler(), |
117
|
|
|
$transformationProcessor, |
118
|
|
|
$this->getLanguageMaskGenerator(), |
119
|
|
|
$fullTextSearchConfiguration |
120
|
|
|
), |
121
|
|
|
new Content\Common\Gateway\CriterionHandler\Field( |
122
|
|
|
$this->getDatabaseHandler(), |
123
|
|
|
$this->getContentTypeHandler(), |
124
|
|
|
$this->getLanguageHandler(), |
125
|
|
|
$this->getConverterRegistry(), |
126
|
|
|
new Content\Common\Gateway\CriterionHandler\FieldValue\Converter( |
127
|
|
|
new Content\Common\Gateway\CriterionHandler\FieldValue\HandlerRegistry( |
128
|
|
|
[ |
129
|
|
|
'ezboolean' => $simpleValueHandler, |
130
|
|
|
'ezcountry' => $commaSeparatedCollectionValueHandler, |
131
|
|
|
'ezdate' => $simpleValueHandler, |
132
|
|
|
'ezdatetime' => $simpleValueHandler, |
133
|
|
|
'ezemail' => $simpleValueHandler, |
134
|
|
|
'ezinteger' => $simpleValueHandler, |
135
|
|
|
'ezobjectrelation' => $simpleValueHandler, |
136
|
|
|
'ezobjectrelationlist' => $commaSeparatedCollectionValueHandler, |
137
|
|
|
'ezselection' => $hyphenSeparatedCollectionValueHandler, |
138
|
|
|
'eztime' => $simpleValueHandler, |
139
|
|
|
] |
140
|
|
|
), |
141
|
|
|
$compositeValueHandler |
142
|
|
|
), |
143
|
|
|
$transformationProcessor |
144
|
|
|
), |
145
|
|
|
new Content\Common\Gateway\CriterionHandler\ObjectStateId( |
146
|
|
|
$this->getDatabaseHandler() |
147
|
|
|
), |
148
|
|
|
new Content\Common\Gateway\CriterionHandler\LanguageCode( |
149
|
|
|
$this->getDatabaseHandler(), |
150
|
|
|
$this->getLanguageMaskGenerator() |
151
|
|
|
), |
152
|
|
|
new Content\Gateway\CriterionHandler\Visibility( |
153
|
|
|
$this->getDatabaseHandler() |
154
|
|
|
), |
155
|
|
|
new Content\Common\Gateway\CriterionHandler\MatchAll( |
156
|
|
|
$this->getDatabaseHandler() |
157
|
|
|
), |
158
|
|
|
new Content\Common\Gateway\CriterionHandler\UserMetadata( |
159
|
|
|
$this->getDatabaseHandler() |
160
|
|
|
), |
161
|
|
|
new Content\Common\Gateway\CriterionHandler\FieldRelation( |
162
|
|
|
$this->getDatabaseHandler(), |
163
|
|
|
$this->getContentTypeHandler(), |
164
|
|
|
$this->getLanguageHandler() |
165
|
|
|
), |
166
|
|
|
] |
167
|
|
|
), |
168
|
|
|
new Content\Common\Gateway\SortClauseConverter( |
169
|
|
|
[ |
170
|
|
|
new Content\Common\Gateway\SortClauseHandler\ContentId($this->getDatabaseHandler()), |
171
|
|
|
] |
172
|
|
|
), |
173
|
|
|
$this->getLanguageHandler() |
174
|
|
|
), |
175
|
|
|
$this->createMock(LocationGateway::class), |
176
|
|
|
new Content\WordIndexer\Gateway\DoctrineDatabase( |
177
|
|
|
$this->getDatabaseHandler(), |
178
|
|
|
$this->getContentTypeHandler(), |
179
|
|
|
$this->getDefinitionBasedTransformationProcessor(), |
180
|
|
|
new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseHandler()), |
181
|
|
|
$this->getLanguageMaskGenerator(), |
182
|
|
|
$this->getFullTextSearchConfiguration() |
183
|
|
|
), |
184
|
|
|
$this->getContentMapperMock(), |
185
|
|
|
$this->createMock(LocationMapper::class), |
186
|
|
|
$this->getLanguageHandler(), |
187
|
|
|
$this->getFullTextMapper($this->getContentTypeHandler()) |
|
|
|
|
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Returns a content mapper mock. |
193
|
|
|
* |
194
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper |
195
|
|
|
*/ |
196
|
|
|
protected function getContentMapperMock() |
197
|
|
|
{ |
198
|
|
|
$mapperMock = $this->getMockBuilder(ContentMapper::class) |
199
|
|
|
->setConstructorArgs( |
200
|
|
|
[ |
201
|
|
|
$this->getConverterRegistry(), |
202
|
|
|
$this->getLanguageHandler(), |
203
|
|
|
] |
204
|
|
|
) |
205
|
|
|
->setMethods(['extractContentInfoFromRows']) |
206
|
|
|
->getMock(); |
207
|
|
|
$mapperMock->expects($this->any()) |
208
|
|
|
->method('extractContentInfoFromRows') |
209
|
|
|
->with($this->isType('array')) |
210
|
|
|
->will( |
211
|
|
|
$this->returnCallback( |
212
|
|
|
function ($rows) { |
213
|
|
|
$contentInfoObjs = []; |
214
|
|
|
foreach ($rows as $row) { |
215
|
|
|
$contentId = (int)$row['id']; |
216
|
|
|
if (!isset($contentInfoObjs[$contentId])) { |
217
|
|
|
$contentInfoObjs[$contentId] = new ContentInfo(); |
218
|
|
|
$contentInfoObjs[$contentId]->id = $contentId; |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return array_values($contentInfoObjs); |
223
|
|
|
} |
224
|
|
|
) |
225
|
|
|
); |
226
|
|
|
|
227
|
|
|
return $mapperMock; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns a content field handler mock. |
232
|
|
|
* |
233
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler |
234
|
|
|
*/ |
235
|
|
|
protected function getContentFieldHandlerMock() |
236
|
|
|
{ |
237
|
|
|
return $this->getMockBuilder(FieldHandler::class) |
238
|
|
|
->disableOriginalConstructor() |
239
|
|
|
->setMethods(['loadExternalFieldData']) |
240
|
|
|
->getMock(); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Bug #80. |
245
|
|
|
*/ |
246
|
|
|
public function testFindWithoutOffsetLimit() |
247
|
|
|
{ |
248
|
|
|
$locator = $this->getContentSearchHandler(); |
249
|
|
|
|
250
|
|
|
$result = $locator->findContent( |
251
|
|
|
new Query( |
252
|
|
|
[ |
253
|
|
|
'filter' => new Criterion\ContentId(10), |
254
|
|
|
] |
255
|
|
|
) |
256
|
|
|
); |
257
|
|
|
|
258
|
|
|
$this->assertEquals( |
259
|
|
|
1, |
260
|
|
|
$result->totalCount |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Bug #81, bug #82. |
266
|
|
|
*/ |
267
|
|
View Code Duplication |
public function testFindWithZeroLimit() |
268
|
|
|
{ |
269
|
|
|
$locator = $this->getContentSearchHandler(); |
270
|
|
|
|
271
|
|
|
$result = $locator->findContent( |
272
|
|
|
new Query( |
273
|
|
|
[ |
274
|
|
|
'filter' => new Criterion\ContentId(10), |
275
|
|
|
'offset' => 0, |
276
|
|
|
'limit' => 0, |
277
|
|
|
] |
278
|
|
|
) |
279
|
|
|
); |
280
|
|
|
|
281
|
|
|
$this->assertEquals( |
282
|
|
|
1, |
283
|
|
|
$result->totalCount |
284
|
|
|
); |
285
|
|
|
$this->assertEquals( |
286
|
|
|
[], |
287
|
|
|
$result->searchHits |
288
|
|
|
); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* Issue with PHP_MAX_INT limit overflow in databases. |
293
|
|
|
*/ |
294
|
|
View Code Duplication |
public function testFindWithNullLimit() |
295
|
|
|
{ |
296
|
|
|
$locator = $this->getContentSearchHandler(); |
297
|
|
|
|
298
|
|
|
$result = $locator->findContent( |
299
|
|
|
new Query( |
300
|
|
|
[ |
301
|
|
|
'filter' => new Criterion\ContentId(10), |
302
|
|
|
'offset' => 0, |
303
|
|
|
'limit' => null, |
304
|
|
|
] |
305
|
|
|
) |
306
|
|
|
); |
307
|
|
|
|
308
|
|
|
$this->assertEquals( |
309
|
|
|
1, |
310
|
|
|
$result->totalCount |
311
|
|
|
); |
312
|
|
|
$this->assertEquals( |
313
|
|
|
1, |
314
|
|
|
count($result->searchHits) |
315
|
|
|
); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* Issue with offsetting to the nonexistent results produces \ezcQueryInvalidParameterException exception. |
320
|
|
|
*/ |
321
|
|
View Code Duplication |
public function testFindWithOffsetToNonexistent() |
322
|
|
|
{ |
323
|
|
|
$locator = $this->getContentSearchHandler(); |
324
|
|
|
|
325
|
|
|
$result = $locator->findContent( |
326
|
|
|
new Query( |
327
|
|
|
[ |
328
|
|
|
'filter' => new Criterion\ContentId(10), |
329
|
|
|
'offset' => 1000, |
330
|
|
|
'limit' => null, |
331
|
|
|
] |
332
|
|
|
) |
333
|
|
|
); |
334
|
|
|
|
335
|
|
|
$this->assertEquals( |
336
|
|
|
1, |
337
|
|
|
$result->totalCount |
338
|
|
|
); |
339
|
|
|
$this->assertEquals( |
340
|
|
|
0, |
341
|
|
|
count($result->searchHits) |
342
|
|
|
); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
public function testFindSingle() |
346
|
|
|
{ |
347
|
|
|
$locator = $this->getContentSearchHandler(); |
348
|
|
|
|
349
|
|
|
$contentInfo = $locator->findSingle(new Criterion\ContentId(10)); |
350
|
|
|
|
351
|
|
|
$this->assertEquals(10, $contentInfo->id); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
356
|
|
|
*/ |
357
|
|
|
public function testFindSingleWithNonSearchableField() |
358
|
|
|
{ |
359
|
|
|
$locator = $this->getContentSearchHandler(); |
360
|
|
|
$locator->findSingle( |
361
|
|
|
new Criterion\Field( |
362
|
|
|
'tag_cloud_url', |
363
|
|
|
Criterion\Operator::EQ, |
364
|
|
|
'http://nimbus.com' |
365
|
|
|
) |
366
|
|
|
); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
371
|
|
|
*/ |
372
|
|
View Code Duplication |
public function testFindContentWithNonSearchableField() |
373
|
|
|
{ |
374
|
|
|
$locator = $this->getContentSearchHandler(); |
375
|
|
|
$locator->findContent( |
376
|
|
|
new Query( |
377
|
|
|
[ |
378
|
|
|
'filter' => new Criterion\Field( |
379
|
|
|
'tag_cloud_url', |
380
|
|
|
Criterion\Operator::EQ, |
381
|
|
|
'http://nimbus.com' |
382
|
|
|
), |
383
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
384
|
|
|
] |
385
|
|
|
) |
386
|
|
|
); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
391
|
|
|
*/ |
392
|
|
|
public function testFindSingleTooMany() |
393
|
|
|
{ |
394
|
|
|
$locator = $this->getContentSearchHandler(); |
395
|
|
|
$locator->findSingle(new Criterion\ContentId([4, 10, 12, 23])); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
400
|
|
|
*/ |
401
|
|
|
public function testFindSingleZero() |
402
|
|
|
{ |
403
|
|
|
$this->expectException(NotFoundException::class); |
404
|
|
|
|
405
|
|
|
$locator = $this->getContentSearchHandler(); |
406
|
|
|
$locator->findSingle(new Criterion\ContentId(0)); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
public function testContentIdFilter() |
410
|
|
|
{ |
411
|
|
|
$this->assertSearchResults( |
412
|
|
|
[4, 10], |
413
|
|
|
$this->getContentSearchHandler()->findContent( |
414
|
|
|
new Query( |
415
|
|
|
[ |
416
|
|
|
'filter' => new Criterion\ContentId( |
417
|
|
|
[1, 4, 10] |
418
|
|
|
), |
419
|
|
|
'limit' => 10, |
420
|
|
|
] |
421
|
|
|
) |
422
|
|
|
) |
423
|
|
|
); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
public function testContentIdFilterCount() |
427
|
|
|
{ |
428
|
|
|
$locator = $this->getContentSearchHandler(); |
429
|
|
|
|
430
|
|
|
$result = $locator->findContent( |
431
|
|
|
new Query( |
432
|
|
|
[ |
433
|
|
|
'filter' => new Criterion\ContentId( |
434
|
|
|
[1, 4, 10] |
435
|
|
|
), |
436
|
|
|
'limit' => 10, |
437
|
|
|
] |
438
|
|
|
) |
439
|
|
|
); |
440
|
|
|
|
441
|
|
|
$this->assertSame(2, $result->totalCount); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function testContentAndCombinatorFilter() |
445
|
|
|
{ |
446
|
|
|
$this->assertSearchResults( |
447
|
|
|
[4], |
448
|
|
|
$this->getContentSearchHandler()->findContent( |
449
|
|
|
new Query( |
450
|
|
|
[ |
451
|
|
|
'filter' => new Criterion\LogicalAnd( |
452
|
|
|
[ |
453
|
|
|
new Criterion\ContentId( |
454
|
|
|
[1, 4, 10] |
455
|
|
|
), |
456
|
|
|
new Criterion\ContentId( |
457
|
|
|
[4, 12] |
458
|
|
|
), |
459
|
|
|
] |
460
|
|
|
), |
461
|
|
|
'limit' => 10, |
462
|
|
|
] |
463
|
|
|
) |
464
|
|
|
) |
465
|
|
|
); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
public function testContentOrCombinatorFilter() |
469
|
|
|
{ |
470
|
|
|
$locator = $this->getContentSearchHandler(); |
471
|
|
|
|
472
|
|
|
$result = $locator->findContent( |
473
|
|
|
new Query( |
474
|
|
|
[ |
475
|
|
|
'filter' => new Criterion\LogicalOr( |
476
|
|
|
[ |
477
|
|
|
new Criterion\ContentId( |
478
|
|
|
[1, 4, 10] |
479
|
|
|
), |
480
|
|
|
new Criterion\ContentId( |
481
|
|
|
[4, 12] |
482
|
|
|
), |
483
|
|
|
] |
484
|
|
|
), |
485
|
|
|
'limit' => 10, |
486
|
|
|
] |
487
|
|
|
) |
488
|
|
|
); |
489
|
|
|
|
490
|
|
|
$expectedContentIds = [4, 10, 12]; |
491
|
|
|
|
492
|
|
|
$this->assertEquals( |
493
|
|
|
count($expectedContentIds), |
494
|
|
|
count($result->searchHits) |
495
|
|
|
); |
496
|
|
|
foreach ($result->searchHits as $hit) { |
497
|
|
|
$this->assertContains( |
498
|
|
|
$hit->valueObject->id, |
|
|
|
|
499
|
|
|
$expectedContentIds |
500
|
|
|
); |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
public function testContentNotCombinatorFilter() |
505
|
|
|
{ |
506
|
|
|
$this->assertSearchResults( |
507
|
|
|
[4], |
508
|
|
|
$this->getContentSearchHandler()->findContent( |
509
|
|
|
new Query( |
510
|
|
|
[ |
511
|
|
|
'filter' => new Criterion\LogicalAnd( |
512
|
|
|
[ |
513
|
|
|
new Criterion\ContentId( |
514
|
|
|
[1, 4, 10] |
515
|
|
|
), |
516
|
|
|
new Criterion\LogicalNot( |
517
|
|
|
new Criterion\ContentId( |
518
|
|
|
[10, 12] |
519
|
|
|
) |
520
|
|
|
), |
521
|
|
|
] |
522
|
|
|
), |
523
|
|
|
'limit' => 10, |
524
|
|
|
] |
525
|
|
|
) |
526
|
|
|
) |
527
|
|
|
); |
528
|
|
|
} |
529
|
|
|
|
530
|
|
View Code Duplication |
public function testContentSubtreeFilterIn() |
531
|
|
|
{ |
532
|
|
|
$this->assertSearchResults( |
533
|
|
|
[67, 68, 69, 70, 71, 72, 73, 74], |
534
|
|
|
$this->getContentSearchHandler()->findContent( |
535
|
|
|
new Query( |
536
|
|
|
[ |
537
|
|
|
'filter' => new Criterion\Subtree( |
538
|
|
|
['/1/2/69/'] |
539
|
|
|
), |
540
|
|
|
'limit' => 10, |
541
|
|
|
] |
542
|
|
|
) |
543
|
|
|
) |
544
|
|
|
); |
545
|
|
|
} |
546
|
|
|
|
547
|
|
View Code Duplication |
public function testContentSubtreeFilterEq() |
548
|
|
|
{ |
549
|
|
|
$this->assertSearchResults( |
550
|
|
|
[67, 68, 69, 70, 71, 72, 73, 74], |
551
|
|
|
$this->getContentSearchHandler()->findContent( |
552
|
|
|
new Query( |
553
|
|
|
[ |
554
|
|
|
'filter' => new Criterion\Subtree('/1/2/69/'), |
555
|
|
|
'limit' => 10, |
556
|
|
|
] |
557
|
|
|
) |
558
|
|
|
) |
559
|
|
|
); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
View Code Duplication |
public function testContentTypeIdFilter() |
563
|
|
|
{ |
564
|
|
|
$this->assertSearchResults( |
565
|
|
|
[10, 14, 226], |
566
|
|
|
$this->getContentSearchHandler()->findContent( |
567
|
|
|
new Query( |
568
|
|
|
[ |
569
|
|
|
'filter' => new Criterion\ContentTypeId(4), |
570
|
|
|
'limit' => 10, |
571
|
|
|
] |
572
|
|
|
) |
573
|
|
|
) |
574
|
|
|
); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
public function testContentTypeIdentifierFilter() |
578
|
|
|
{ |
579
|
|
|
$this->assertSearchResults( |
580
|
|
|
[41, 45, 49, 50, 51], |
581
|
|
|
$this->getContentSearchHandler()->findContent( |
582
|
|
|
new Query( |
583
|
|
|
[ |
584
|
|
|
'filter' => new Criterion\ContentTypeIdentifier('folder'), |
585
|
|
|
'limit' => 5, |
586
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
587
|
|
|
] |
588
|
|
|
) |
589
|
|
|
) |
590
|
|
|
); |
591
|
|
|
} |
592
|
|
|
|
593
|
|
View Code Duplication |
public function testContentTypeGroupFilter() |
594
|
|
|
{ |
595
|
|
|
$this->assertSearchResults( |
596
|
|
|
[4, 10, 11, 12, 13, 14, 42, 225, 226], |
597
|
|
|
$this->getContentSearchHandler()->findContent( |
598
|
|
|
new Query( |
599
|
|
|
[ |
600
|
|
|
'filter' => new Criterion\ContentTypeGroupId(2), |
601
|
|
|
'limit' => 10, |
602
|
|
|
] |
603
|
|
|
) |
604
|
|
|
) |
605
|
|
|
); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
public function testDateMetadataFilterModifiedGreater() |
609
|
|
|
{ |
610
|
|
|
$this->assertSearchResults( |
611
|
|
|
[11, 225, 226], |
612
|
|
|
$this->getContentSearchHandler()->findContent( |
613
|
|
|
new Query( |
614
|
|
|
[ |
615
|
|
|
'filter' => new Criterion\DateMetadata( |
616
|
|
|
Criterion\DateMetadata::MODIFIED, |
617
|
|
|
Criterion\Operator::GT, |
618
|
|
|
1311154214 |
619
|
|
|
), |
620
|
|
|
'limit' => 10, |
621
|
|
|
] |
622
|
|
|
) |
623
|
|
|
) |
624
|
|
|
); |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
public function testDateMetadataFilterModifiedGreaterOrEqual() |
628
|
|
|
{ |
629
|
|
|
$this->assertSearchResults( |
630
|
|
|
[11, 14, 225, 226], |
631
|
|
|
$this->getContentSearchHandler()->findContent( |
632
|
|
|
new Query( |
633
|
|
|
[ |
634
|
|
|
'filter' => new Criterion\DateMetadata( |
635
|
|
|
Criterion\DateMetadata::MODIFIED, |
636
|
|
|
Criterion\Operator::GTE, |
637
|
|
|
1311154214 |
638
|
|
|
), |
639
|
|
|
'limit' => 10, |
640
|
|
|
] |
641
|
|
|
) |
642
|
|
|
) |
643
|
|
|
); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
public function testDateMetadataFilterModifiedIn() |
647
|
|
|
{ |
648
|
|
|
$this->assertSearchResults( |
649
|
|
|
[11, 14, 225, 226], |
650
|
|
|
$this->getContentSearchHandler()->findContent( |
651
|
|
|
new Query( |
652
|
|
|
[ |
653
|
|
|
'filter' => new Criterion\DateMetadata( |
654
|
|
|
Criterion\DateMetadata::MODIFIED, |
655
|
|
|
Criterion\Operator::IN, |
656
|
|
|
[1311154214, 1311154215] |
657
|
|
|
), |
658
|
|
|
'limit' => 10, |
659
|
|
|
] |
660
|
|
|
) |
661
|
|
|
) |
662
|
|
|
); |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
public function testDateMetadataFilterModifiedBetween() |
666
|
|
|
{ |
667
|
|
|
$this->assertSearchResults( |
668
|
|
|
[11, 14, 225, 226], |
669
|
|
|
$this->getContentSearchHandler()->findContent( |
670
|
|
|
new Query( |
671
|
|
|
[ |
672
|
|
|
'filter' => new Criterion\DateMetadata( |
673
|
|
|
Criterion\DateMetadata::MODIFIED, |
674
|
|
|
Criterion\Operator::BETWEEN, |
675
|
|
|
[1311154213, 1311154215] |
676
|
|
|
), |
677
|
|
|
'limit' => 10, |
678
|
|
|
] |
679
|
|
|
) |
680
|
|
|
) |
681
|
|
|
); |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
public function testDateMetadataFilterCreatedBetween() |
685
|
|
|
{ |
686
|
|
|
$this->assertSearchResults( |
687
|
|
|
[66, 131, 225], |
688
|
|
|
$this->getContentSearchHandler()->findContent( |
689
|
|
|
new Query( |
690
|
|
|
[ |
691
|
|
|
'filter' => new Criterion\DateMetadata( |
692
|
|
|
Criterion\DateMetadata::CREATED, |
693
|
|
|
Criterion\Operator::BETWEEN, |
694
|
|
|
[1299780749, 1311154215] |
695
|
|
|
), |
696
|
|
|
'limit' => 10, |
697
|
|
|
] |
698
|
|
|
) |
699
|
|
|
) |
700
|
|
|
); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
public function testLocationIdFilter() |
704
|
|
|
{ |
705
|
|
|
$this->assertSearchResults( |
706
|
|
|
[4, 65], |
707
|
|
|
$this->getContentSearchHandler()->findContent( |
708
|
|
|
new Query( |
709
|
|
|
[ |
710
|
|
|
'filter' => new Criterion\LocationId([1, 2, 5]), |
711
|
|
|
'limit' => 10, |
712
|
|
|
] |
713
|
|
|
) |
714
|
|
|
) |
715
|
|
|
); |
716
|
|
|
} |
717
|
|
|
|
718
|
|
|
public function testParentLocationIdFilter() |
719
|
|
|
{ |
720
|
|
|
$this->assertSearchResults( |
721
|
|
|
[4, 41, 45, 56, 65], |
722
|
|
|
$this->getContentSearchHandler()->findContent( |
723
|
|
|
new Query( |
724
|
|
|
[ |
725
|
|
|
'filter' => new Criterion\ParentLocationId([1]), |
726
|
|
|
'limit' => 10, |
727
|
|
|
] |
728
|
|
|
) |
729
|
|
|
) |
730
|
|
|
); |
731
|
|
|
} |
732
|
|
|
|
733
|
|
|
public function testRemoteIdFilter() |
734
|
|
|
{ |
735
|
|
|
$this->assertSearchResults( |
736
|
|
|
[4, 10], |
737
|
|
|
$this->getContentSearchHandler()->findContent( |
738
|
|
|
new Query( |
739
|
|
|
[ |
740
|
|
|
'filter' => new Criterion\RemoteId( |
741
|
|
|
['f5c88a2209584891056f987fd965b0ba', 'faaeb9be3bd98ed09f606fc16d144eca'] |
742
|
|
|
), |
743
|
|
|
'limit' => 10, |
744
|
|
|
] |
745
|
|
|
) |
746
|
|
|
) |
747
|
|
|
); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
public function testLocationRemoteIdFilter() |
751
|
|
|
{ |
752
|
|
|
$this->assertSearchResults( |
753
|
|
|
[4, 65], |
754
|
|
|
$this->getContentSearchHandler()->findContent( |
755
|
|
|
new Query( |
756
|
|
|
[ |
757
|
|
|
'filter' => new Criterion\LocationRemoteId( |
758
|
|
|
['3f6d92f8044aed134f32153517850f5a', 'f3e90596361e31d496d4026eb624c983'] |
759
|
|
|
), |
760
|
|
|
'limit' => 10, |
761
|
|
|
] |
762
|
|
|
) |
763
|
|
|
) |
764
|
|
|
); |
765
|
|
|
} |
766
|
|
|
|
767
|
|
View Code Duplication |
public function testSectionFilter() |
768
|
|
|
{ |
769
|
|
|
$this->assertSearchResults( |
770
|
|
|
[4, 10, 11, 12, 13, 14, 42, 226], |
771
|
|
|
$this->getContentSearchHandler()->findContent( |
772
|
|
|
new Query( |
773
|
|
|
[ |
774
|
|
|
'filter' => new Criterion\SectionId([2]), |
775
|
|
|
'limit' => 10, |
776
|
|
|
] |
777
|
|
|
) |
778
|
|
|
) |
779
|
|
|
); |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
public function testStatusFilter() |
783
|
|
|
{ |
784
|
|
|
$this->assertSearchResults( |
785
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
786
|
|
|
$searchResult = $this->getContentSearchHandler()->findContent( |
787
|
|
|
new Query( |
788
|
|
|
[ |
789
|
|
|
// Status criterion is gone, but this will also match all published |
790
|
|
|
'filter' => new Criterion\LogicalNot( |
791
|
|
|
new Criterion\ContentId( |
792
|
|
|
[0] |
793
|
|
|
) |
794
|
|
|
), |
795
|
|
|
'limit' => 10, |
796
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
797
|
|
|
] |
798
|
|
|
) |
799
|
|
|
) |
800
|
|
|
); |
801
|
|
|
|
802
|
|
|
$this->assertEquals( |
803
|
|
|
185, |
804
|
|
|
$searchResult->totalCount |
805
|
|
|
); |
806
|
|
|
} |
807
|
|
|
|
808
|
|
|
public function testFieldFilter() |
809
|
|
|
{ |
810
|
|
|
$this->assertSearchResults( |
811
|
|
|
[11], |
812
|
|
|
$this->getContentSearchHandler()->findContent( |
813
|
|
|
new Query( |
814
|
|
|
[ |
815
|
|
|
'filter' => new Criterion\Field( |
816
|
|
|
'name', |
817
|
|
|
Criterion\Operator::EQ, |
818
|
|
|
'members' |
819
|
|
|
), |
820
|
|
|
'limit' => 10, |
821
|
|
|
] |
822
|
|
|
) |
823
|
|
|
) |
824
|
|
|
); |
825
|
|
|
} |
826
|
|
|
|
827
|
|
View Code Duplication |
public function testFieldFilterIn() |
828
|
|
|
{ |
829
|
|
|
$this->assertSearchResults( |
830
|
|
|
[11, 42], |
831
|
|
|
$this->getContentSearchHandler()->findContent( |
832
|
|
|
new Query( |
833
|
|
|
[ |
834
|
|
|
'filter' => new Criterion\Field( |
835
|
|
|
'name', |
836
|
|
|
Criterion\Operator::IN, |
837
|
|
|
['members', 'anonymous users'] |
838
|
|
|
), |
839
|
|
|
'limit' => 10, |
840
|
|
|
] |
841
|
|
|
) |
842
|
|
|
) |
843
|
|
|
); |
844
|
|
|
} |
845
|
|
|
|
846
|
|
|
public function testFieldFilterContainsPartial() |
847
|
|
|
{ |
848
|
|
|
$this->assertSearchResults( |
849
|
|
|
[42], |
850
|
|
|
$this->getContentSearchHandler()->findContent( |
851
|
|
|
new Query( |
852
|
|
|
[ |
853
|
|
|
'filter' => new Criterion\Field( |
854
|
|
|
'name', |
855
|
|
|
Criterion\Operator::CONTAINS, |
856
|
|
|
'nonymous use' |
857
|
|
|
), |
858
|
|
|
'limit' => 10, |
859
|
|
|
] |
860
|
|
|
) |
861
|
|
|
) |
862
|
|
|
); |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
public function testFieldFilterContainsSimple() |
866
|
|
|
{ |
867
|
|
|
$this->assertSearchResults( |
868
|
|
|
[77], |
869
|
|
|
$this->getContentSearchHandler()->findContent( |
870
|
|
|
new Query( |
871
|
|
|
[ |
872
|
|
|
'filter' => new Criterion\Field( |
873
|
|
|
'publish_date', |
874
|
|
|
Criterion\Operator::CONTAINS, |
875
|
|
|
1174643880 |
876
|
|
|
), |
877
|
|
|
'limit' => 10, |
878
|
|
|
] |
879
|
|
|
) |
880
|
|
|
) |
881
|
|
|
); |
882
|
|
|
} |
883
|
|
|
|
884
|
|
|
public function testFieldFilterContainsSimpleNoMatch() |
885
|
|
|
{ |
886
|
|
|
$this->assertSearchResults( |
887
|
|
|
[], |
888
|
|
|
$this->getContentSearchHandler()->findContent( |
889
|
|
|
new Query( |
890
|
|
|
[ |
891
|
|
|
'filter' => new Criterion\Field( |
892
|
|
|
'publish_date', |
893
|
|
|
Criterion\Operator::CONTAINS, |
894
|
|
|
1174643 |
895
|
|
|
), |
896
|
|
|
'limit' => 10, |
897
|
|
|
] |
898
|
|
|
) |
899
|
|
|
) |
900
|
|
|
); |
901
|
|
|
} |
902
|
|
|
|
903
|
|
View Code Duplication |
public function testFieldFilterBetween() |
904
|
|
|
{ |
905
|
|
|
$this->assertSearchResults( |
906
|
|
|
[69, 71, 72], |
907
|
|
|
$this->getContentSearchHandler()->findContent( |
908
|
|
|
new Query( |
909
|
|
|
[ |
910
|
|
|
'filter' => new Criterion\Field( |
911
|
|
|
'price', |
912
|
|
|
Criterion\Operator::BETWEEN, |
913
|
|
|
[10000, 1000000] |
914
|
|
|
), |
915
|
|
|
'limit' => 10, |
916
|
|
|
] |
917
|
|
|
) |
918
|
|
|
) |
919
|
|
|
); |
920
|
|
|
} |
921
|
|
|
|
922
|
|
View Code Duplication |
public function testFieldFilterOr() |
923
|
|
|
{ |
924
|
|
|
$this->assertSearchResults( |
925
|
|
|
[11, 69, 71, 72], |
926
|
|
|
$this->getContentSearchHandler()->findContent( |
927
|
|
|
new Query( |
928
|
|
|
[ |
929
|
|
|
'filter' => new Criterion\LogicalOr( |
930
|
|
|
[ |
931
|
|
|
new Criterion\Field( |
932
|
|
|
'name', |
933
|
|
|
Criterion\Operator::EQ, |
934
|
|
|
'members' |
935
|
|
|
), |
936
|
|
|
new Criterion\Field( |
937
|
|
|
'price', |
938
|
|
|
Criterion\Operator::BETWEEN, |
939
|
|
|
[10000, 1000000] |
940
|
|
|
), |
941
|
|
|
] |
942
|
|
|
), |
943
|
|
|
'limit' => 10, |
944
|
|
|
] |
945
|
|
|
) |
946
|
|
|
) |
947
|
|
|
); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
View Code Duplication |
public function testFullTextFilter() |
951
|
|
|
{ |
952
|
|
|
$this->assertSearchResults( |
953
|
|
|
[191], |
954
|
|
|
$this->getContentSearchHandler()->findContent( |
955
|
|
|
new Query( |
956
|
|
|
[ |
957
|
|
|
'filter' => new Criterion\FullText('applied webpage'), |
958
|
|
|
'limit' => 10, |
959
|
|
|
] |
960
|
|
|
) |
961
|
|
|
) |
962
|
|
|
); |
963
|
|
|
} |
964
|
|
|
|
965
|
|
View Code Duplication |
public function testFullTextWildcardFilter() |
966
|
|
|
{ |
967
|
|
|
$this->assertSearchResults( |
968
|
|
|
[191], |
969
|
|
|
$this->getContentSearchHandler()->findContent( |
970
|
|
|
new Query( |
971
|
|
|
[ |
972
|
|
|
'filter' => new Criterion\FullText('applie*'), |
973
|
|
|
'limit' => 10, |
974
|
|
|
] |
975
|
|
|
) |
976
|
|
|
) |
977
|
|
|
); |
978
|
|
|
} |
979
|
|
|
|
980
|
|
View Code Duplication |
public function testFullTextDisabledWildcardFilter() |
981
|
|
|
{ |
982
|
|
|
$this->assertSearchResults( |
983
|
|
|
[], |
984
|
|
|
$this->getContentSearchHandler( |
985
|
|
|
['enableWildcards' => false] |
986
|
|
|
)->findContent( |
987
|
|
|
new Query( |
988
|
|
|
[ |
989
|
|
|
'filter' => new Criterion\FullText('applie*'), |
990
|
|
|
'limit' => 10, |
991
|
|
|
] |
992
|
|
|
) |
993
|
|
|
) |
994
|
|
|
); |
995
|
|
|
} |
996
|
|
|
|
997
|
|
View Code Duplication |
public function testFullTextFilterStopwordRemoval() |
998
|
|
|
{ |
999
|
|
|
$handler = $this->getContentSearchHandler( |
1000
|
|
|
[ |
1001
|
|
|
'stopWordThresholdFactor' => 0.1, |
1002
|
|
|
] |
1003
|
|
|
); |
1004
|
|
|
|
1005
|
|
|
$this->assertSearchResults( |
1006
|
|
|
[], |
1007
|
|
|
$handler->findContent( |
1008
|
|
|
new Query( |
1009
|
|
|
[ |
1010
|
|
|
'filter' => new Criterion\FullText('the'), |
1011
|
|
|
'limit' => 10, |
1012
|
|
|
] |
1013
|
|
|
) |
1014
|
|
|
) |
1015
|
|
|
); |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
View Code Duplication |
public function testFullTextFilterNoStopwordRemoval() |
1019
|
|
|
{ |
1020
|
|
|
$handler = $this->getContentSearchHandler( |
1021
|
|
|
[ |
1022
|
|
|
'stopWordThresholdFactor' => 1, |
1023
|
|
|
] |
1024
|
|
|
); |
1025
|
|
|
|
1026
|
|
|
$result = $handler->findContent( |
1027
|
|
|
new Query( |
1028
|
|
|
[ |
1029
|
|
|
'filter' => new Criterion\FullText( |
1030
|
|
|
'the' |
1031
|
|
|
), |
1032
|
|
|
'limit' => 10, |
1033
|
|
|
] |
1034
|
|
|
) |
1035
|
|
|
); |
1036
|
|
|
|
1037
|
|
|
$this->assertEquals( |
1038
|
|
|
10, |
1039
|
|
|
count( |
1040
|
|
|
array_map( |
1041
|
|
|
function ($hit) { |
1042
|
|
|
return $hit->valueObject->id; |
1043
|
|
|
}, |
1044
|
|
|
$result->searchHits |
1045
|
|
|
) |
1046
|
|
|
) |
1047
|
|
|
); |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/** |
1051
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
1052
|
|
|
*/ |
1053
|
|
|
public function testFullTextFilterInvalidStopwordThreshold() |
1054
|
|
|
{ |
1055
|
|
|
$this->getContentSearchHandler( |
1056
|
|
|
[ |
1057
|
|
|
'stopWordThresholdFactor' => 2, |
1058
|
|
|
] |
1059
|
|
|
); |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
public function testObjectStateIdFilter() |
1063
|
|
|
{ |
1064
|
|
|
$this->assertSearchResults( |
1065
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1066
|
|
|
$this->getContentSearchHandler()->findContent( |
1067
|
|
|
new Query( |
1068
|
|
|
[ |
1069
|
|
|
'filter' => new Criterion\ObjectStateId(1), |
1070
|
|
|
'limit' => 10, |
1071
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1072
|
|
|
] |
1073
|
|
|
) |
1074
|
|
|
) |
1075
|
|
|
); |
1076
|
|
|
} |
1077
|
|
|
|
1078
|
|
|
public function testObjectStateIdFilterIn() |
1079
|
|
|
{ |
1080
|
|
|
$this->assertSearchResults( |
1081
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1082
|
|
|
$this->getContentSearchHandler()->findContent( |
1083
|
|
|
new Query( |
1084
|
|
|
[ |
1085
|
|
|
'filter' => new Criterion\ObjectStateId([1, 2]), |
1086
|
|
|
'limit' => 10, |
1087
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1088
|
|
|
] |
1089
|
|
|
) |
1090
|
|
|
) |
1091
|
|
|
); |
1092
|
|
|
} |
1093
|
|
|
|
1094
|
|
|
public function testLanguageCodeFilter() |
1095
|
|
|
{ |
1096
|
|
|
$this->assertSearchResults( |
1097
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1098
|
|
|
$this->getContentSearchHandler()->findContent( |
1099
|
|
|
new Query( |
1100
|
|
|
[ |
1101
|
|
|
'filter' => new Criterion\LanguageCode('eng-US'), |
1102
|
|
|
'limit' => 10, |
1103
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1104
|
|
|
] |
1105
|
|
|
) |
1106
|
|
|
) |
1107
|
|
|
); |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
|
public function testLanguageCodeFilterIn() |
1111
|
|
|
{ |
1112
|
|
|
$this->assertSearchResults( |
1113
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1114
|
|
|
$this->getContentSearchHandler()->findContent( |
1115
|
|
|
new Query( |
1116
|
|
|
[ |
1117
|
|
|
'filter' => new Criterion\LanguageCode(['eng-US', 'eng-GB']), |
1118
|
|
|
'limit' => 10, |
1119
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1120
|
|
|
] |
1121
|
|
|
) |
1122
|
|
|
) |
1123
|
|
|
); |
1124
|
|
|
} |
1125
|
|
|
|
1126
|
|
View Code Duplication |
public function testLanguageCodeFilterWithAlwaysAvailable() |
1127
|
|
|
{ |
1128
|
|
|
$this->assertSearchResults( |
1129
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49, 50, 51, 56, 57, 65, 68, 70, 74, 76, 80], |
1130
|
|
|
$this->getContentSearchHandler()->findContent( |
1131
|
|
|
new Query( |
1132
|
|
|
[ |
1133
|
|
|
'filter' => new Criterion\LanguageCode('eng-GB', true), |
1134
|
|
|
'limit' => 20, |
1135
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1136
|
|
|
] |
1137
|
|
|
) |
1138
|
|
|
) |
1139
|
|
|
); |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
public function testVisibilityFilter() |
1143
|
|
|
{ |
1144
|
|
|
$this->assertSearchResults( |
1145
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1146
|
|
|
$this->getContentSearchHandler()->findContent( |
1147
|
|
|
new Query( |
1148
|
|
|
[ |
1149
|
|
|
'filter' => new Criterion\Visibility( |
1150
|
|
|
Criterion\Visibility::VISIBLE |
1151
|
|
|
), |
1152
|
|
|
'limit' => 10, |
1153
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1154
|
|
|
] |
1155
|
|
|
) |
1156
|
|
|
) |
1157
|
|
|
); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
View Code Duplication |
public function testUserMetadataFilterOwnerWrongUserId() |
1161
|
|
|
{ |
1162
|
|
|
$this->assertSearchResults( |
1163
|
|
|
[], |
1164
|
|
|
$this->getContentSearchHandler()->findContent( |
1165
|
|
|
new Query( |
1166
|
|
|
[ |
1167
|
|
|
'filter' => new Criterion\UserMetadata( |
1168
|
|
|
Criterion\UserMetadata::OWNER, |
1169
|
|
|
Criterion\Operator::EQ, |
1170
|
|
|
2 |
1171
|
|
|
), |
1172
|
|
|
] |
1173
|
|
|
) |
1174
|
|
|
) |
1175
|
|
|
); |
1176
|
|
|
} |
1177
|
|
|
|
1178
|
|
View Code Duplication |
public function testUserMetadataFilterOwnerAdministrator() |
1179
|
|
|
{ |
1180
|
|
|
$this->assertSearchResults( |
1181
|
|
|
[4, 10, 11, 12, 13, 14, 41, 42, 45, 49], |
1182
|
|
|
$this->getContentSearchHandler()->findContent( |
1183
|
|
|
new Query( |
1184
|
|
|
[ |
1185
|
|
|
'filter' => new Criterion\UserMetadata( |
1186
|
|
|
Criterion\UserMetadata::OWNER, |
1187
|
|
|
Criterion\Operator::EQ, |
1188
|
|
|
14 |
1189
|
|
|
), |
1190
|
|
|
'limit' => 10, |
1191
|
|
|
'sortClauses' => [new SortClause\ContentId()], |
1192
|
|
|
] |
1193
|
|
|
) |
1194
|
|
|
) |
1195
|
|
|
); |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
View Code Duplication |
public function testUserMetadataFilterOwnerEqAMember() |
1199
|
|
|
{ |
1200
|
|
|
$this->assertSearchResults( |
1201
|
|
|
[223], |
1202
|
|
|
$this->getContentSearchHandler()->findContent( |
1203
|
|
|
new Query( |
1204
|
|
|
[ |
1205
|
|
|
'filter' => new Criterion\UserMetadata( |
1206
|
|
|
Criterion\UserMetadata::OWNER, |
1207
|
|
|
Criterion\Operator::EQ, |
1208
|
|
|
226 |
1209
|
|
|
), |
1210
|
|
|
] |
1211
|
|
|
) |
1212
|
|
|
) |
1213
|
|
|
); |
1214
|
|
|
} |
1215
|
|
|
|
1216
|
|
View Code Duplication |
public function testUserMetadataFilterOwnerInAMember() |
1217
|
|
|
{ |
1218
|
|
|
$this->assertSearchResults( |
1219
|
|
|
[223], |
1220
|
|
|
$this->getContentSearchHandler()->findContent( |
1221
|
|
|
new Query( |
1222
|
|
|
[ |
1223
|
|
|
'filter' => new Criterion\UserMetadata( |
1224
|
|
|
Criterion\UserMetadata::OWNER, |
1225
|
|
|
Criterion\Operator::IN, |
1226
|
|
|
[226] |
1227
|
|
|
), |
1228
|
|
|
] |
1229
|
|
|
) |
1230
|
|
|
) |
1231
|
|
|
); |
1232
|
|
|
} |
1233
|
|
|
|
1234
|
|
View Code Duplication |
public function testUserMetadataFilterCreatorEqAMember() |
1235
|
|
|
{ |
1236
|
|
|
$this->assertSearchResults( |
1237
|
|
|
[223], |
1238
|
|
|
$this->getContentSearchHandler()->findContent( |
1239
|
|
|
new Query( |
1240
|
|
|
[ |
1241
|
|
|
'filter' => new Criterion\UserMetadata( |
1242
|
|
|
Criterion\UserMetadata::MODIFIER, |
1243
|
|
|
Criterion\Operator::EQ, |
1244
|
|
|
226 |
1245
|
|
|
), |
1246
|
|
|
] |
1247
|
|
|
) |
1248
|
|
|
) |
1249
|
|
|
); |
1250
|
|
|
} |
1251
|
|
|
|
1252
|
|
View Code Duplication |
public function testUserMetadataFilterCreatorInAMember() |
1253
|
|
|
{ |
1254
|
|
|
$this->assertSearchResults( |
1255
|
|
|
[223], |
1256
|
|
|
$this->getContentSearchHandler()->findContent( |
1257
|
|
|
new Query( |
1258
|
|
|
[ |
1259
|
|
|
'filter' => new Criterion\UserMetadata( |
1260
|
|
|
Criterion\UserMetadata::MODIFIER, |
1261
|
|
|
Criterion\Operator::IN, |
1262
|
|
|
[226] |
1263
|
|
|
), |
1264
|
|
|
] |
1265
|
|
|
) |
1266
|
|
|
) |
1267
|
|
|
); |
1268
|
|
|
} |
1269
|
|
|
|
1270
|
|
View Code Duplication |
public function testUserMetadataFilterEqGroupMember() |
1271
|
|
|
{ |
1272
|
|
|
$this->assertSearchResults( |
1273
|
|
|
[223], |
1274
|
|
|
$this->getContentSearchHandler()->findContent( |
1275
|
|
|
new Query( |
1276
|
|
|
[ |
1277
|
|
|
'filter' => new Criterion\UserMetadata( |
1278
|
|
|
Criterion\UserMetadata::GROUP, |
1279
|
|
|
Criterion\Operator::EQ, |
1280
|
|
|
11 |
1281
|
|
|
), |
1282
|
|
|
] |
1283
|
|
|
) |
1284
|
|
|
) |
1285
|
|
|
); |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
View Code Duplication |
public function testUserMetadataFilterInGroupMember() |
1289
|
|
|
{ |
1290
|
|
|
$this->assertSearchResults( |
1291
|
|
|
[223], |
1292
|
|
|
$this->getContentSearchHandler()->findContent( |
1293
|
|
|
new Query( |
1294
|
|
|
[ |
1295
|
|
|
'filter' => new Criterion\UserMetadata( |
1296
|
|
|
Criterion\UserMetadata::GROUP, |
1297
|
|
|
Criterion\Operator::IN, |
1298
|
|
|
[11] |
1299
|
|
|
), |
1300
|
|
|
] |
1301
|
|
|
) |
1302
|
|
|
) |
1303
|
|
|
); |
1304
|
|
|
} |
1305
|
|
|
|
1306
|
|
View Code Duplication |
public function testUserMetadataFilterEqGroupMemberNoMatch() |
1307
|
|
|
{ |
1308
|
|
|
$this->assertSearchResults( |
1309
|
|
|
[], |
1310
|
|
|
$this->getContentSearchHandler()->findContent( |
1311
|
|
|
new Query( |
1312
|
|
|
[ |
1313
|
|
|
'filter' => new Criterion\UserMetadata( |
1314
|
|
|
Criterion\UserMetadata::GROUP, |
1315
|
|
|
Criterion\Operator::EQ, |
1316
|
|
|
13 |
1317
|
|
|
), |
1318
|
|
|
] |
1319
|
|
|
) |
1320
|
|
|
) |
1321
|
|
|
); |
1322
|
|
|
} |
1323
|
|
|
|
1324
|
|
View Code Duplication |
public function testUserMetadataFilterInGroupMemberNoMatch() |
1325
|
|
|
{ |
1326
|
|
|
$this->assertSearchResults( |
1327
|
|
|
[], |
1328
|
|
|
$this->getContentSearchHandler()->findContent( |
1329
|
|
|
new Query( |
1330
|
|
|
[ |
1331
|
|
|
'filter' => new Criterion\UserMetadata( |
1332
|
|
|
Criterion\UserMetadata::GROUP, |
1333
|
|
|
Criterion\Operator::IN, |
1334
|
|
|
[13] |
1335
|
|
|
), |
1336
|
|
|
] |
1337
|
|
|
) |
1338
|
|
|
) |
1339
|
|
|
); |
1340
|
|
|
} |
1341
|
|
|
|
1342
|
|
|
public function testFieldRelationFilterContainsSingle() |
1343
|
|
|
{ |
1344
|
|
|
$this->assertSearchResults( |
1345
|
|
|
[67], |
1346
|
|
|
$this->getContentSearchHandler()->findContent( |
1347
|
|
|
new Query( |
1348
|
|
|
[ |
1349
|
|
|
'filter' => new Criterion\FieldRelation( |
1350
|
|
|
'billboard', |
1351
|
|
|
Criterion\Operator::CONTAINS, |
1352
|
|
|
[60] |
1353
|
|
|
), |
1354
|
|
|
] |
1355
|
|
|
) |
1356
|
|
|
) |
1357
|
|
|
); |
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
View Code Duplication |
public function testFieldRelationFilterContainsSingleNoMatch() |
1361
|
|
|
{ |
1362
|
|
|
$this->assertSearchResults( |
1363
|
|
|
[], |
1364
|
|
|
$this->getContentSearchHandler()->findContent( |
1365
|
|
|
new Query( |
1366
|
|
|
[ |
1367
|
|
|
'filter' => new Criterion\FieldRelation( |
1368
|
|
|
'billboard', |
1369
|
|
|
Criterion\Operator::CONTAINS, |
1370
|
|
|
[4] |
1371
|
|
|
), |
1372
|
|
|
] |
1373
|
|
|
) |
1374
|
|
|
) |
1375
|
|
|
); |
1376
|
|
|
} |
1377
|
|
|
|
1378
|
|
|
public function testFieldRelationFilterContainsArray() |
1379
|
|
|
{ |
1380
|
|
|
$this->assertSearchResults( |
1381
|
|
|
[67], |
1382
|
|
|
$this->getContentSearchHandler()->findContent( |
1383
|
|
|
new Query( |
1384
|
|
|
[ |
1385
|
|
|
'filter' => new Criterion\FieldRelation( |
1386
|
|
|
'billboard', |
1387
|
|
|
Criterion\Operator::CONTAINS, |
1388
|
|
|
[60, 75] |
1389
|
|
|
), |
1390
|
|
|
] |
1391
|
|
|
) |
1392
|
|
|
) |
1393
|
|
|
); |
1394
|
|
|
} |
1395
|
|
|
|
1396
|
|
|
public function testFieldRelationFilterContainsArrayNotMatch() |
1397
|
|
|
{ |
1398
|
|
|
$this->assertSearchResults( |
1399
|
|
|
[], |
1400
|
|
|
$this->getContentSearchHandler()->findContent( |
1401
|
|
|
new Query( |
1402
|
|
|
[ |
1403
|
|
|
'filter' => new Criterion\FieldRelation( |
1404
|
|
|
'billboard', |
1405
|
|
|
Criterion\Operator::CONTAINS, |
1406
|
|
|
[60, 64] |
1407
|
|
|
), |
1408
|
|
|
] |
1409
|
|
|
) |
1410
|
|
|
) |
1411
|
|
|
); |
1412
|
|
|
} |
1413
|
|
|
|
1414
|
|
|
public function testFieldRelationFilterInArray() |
1415
|
|
|
{ |
1416
|
|
|
$this->assertSearchResults( |
1417
|
|
|
[67, 75], |
1418
|
|
|
$this->getContentSearchHandler()->findContent( |
1419
|
|
|
new Query( |
1420
|
|
|
[ |
1421
|
|
|
'filter' => new Criterion\FieldRelation( |
1422
|
|
|
'billboard', |
1423
|
|
|
Criterion\Operator::IN, |
1424
|
|
|
[60, 64] |
1425
|
|
|
), |
1426
|
|
|
] |
1427
|
|
|
) |
1428
|
|
|
) |
1429
|
|
|
); |
1430
|
|
|
} |
1431
|
|
|
|
1432
|
|
|
public function testFieldRelationFilterInArrayNotMatch() |
1433
|
|
|
{ |
1434
|
|
|
$this->assertSearchResults( |
1435
|
|
|
[], |
1436
|
|
|
$this->getContentSearchHandler()->findContent( |
1437
|
|
|
new Query( |
1438
|
|
|
[ |
1439
|
|
|
'filter' => new Criterion\FieldRelation( |
1440
|
|
|
'billboard', |
1441
|
|
|
Criterion\Operator::IN, |
1442
|
|
|
[4, 10] |
1443
|
|
|
), |
1444
|
|
|
] |
1445
|
|
|
) |
1446
|
|
|
) |
1447
|
|
|
); |
1448
|
|
|
} |
1449
|
|
|
|
1450
|
|
|
public function testGetNonExistingFieldDefinition(): void |
1451
|
|
|
{ |
1452
|
|
|
$this->expectException(NotFoundException::class); |
1453
|
|
|
|
1454
|
|
|
$this->getContentTypeHandler()->getFieldDefinition(0, Type::STATUS_DEFINED); |
1455
|
|
|
} |
1456
|
|
|
} |
1457
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.