Completed
Push — ezp30878_cant_add_image_with_p... ( e19ea7...263f1b )
by
unknown
20:16
created

testFindWithOffsetToNonexistent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 17
loc 17
rs 9.7
c 0
b 0
f 0
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\Location;
10
11
use eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase;
12
use eZ\Publish\Core\Persistence;
13
use eZ\Publish\Core\Search\Legacy\Content;
14
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
15
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter;
16
use eZ\Publish\SPI\Persistence\Content\Location as SPILocation;
17
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
18
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
19
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
20
use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\CriterionHandler as LocationCriterionHandler;
21
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler as CommonCriterionHandler;
22
use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\SortClauseHandler as LocationSortClauseHandler;
23
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler as CommonSortClauseHandler;
24
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
25
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry;
26
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway;
27
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper as ContentTypeMapper;
28
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
29
30
/**
31
 * Location Search test case for ContentSearchHandler.
32
 */
33
class HandlerLocationTest extends LanguageAwareTestCase
34
{
35
    protected static $setUp = false;
36
37
    /**
38
     * Only set up once for these read only tests on a large fixture.
39
     *
40
     * Skipping the reset-up, since setting up for these tests takes quite some
41
     * time, which is not required to spent, since we are only reading from the
42
     * database anyways.
43
     */
44 View Code Duplication
    public function setUp()
45
    {
46
        if (!self::$setUp) {
47
            parent::setUp();
48
            $this->insertDatabaseFixture(__DIR__ . '/../_fixtures/full_dump.php');
49
            self::$setUp = $this->handler;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->handler of type object<eZ\Publish\Core\P...tabase\DatabaseHandler> is incompatible with the declared type boolean of property $setUp.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
        } else {
51
            $this->handler = self::$setUp;
0 ignored issues
show
Documentation Bug introduced by
It seems like self::$setUp of type boolean is incompatible with the declared type object<eZ\Publish\Core\P...tabase\DatabaseHandler> of property $handler.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        }
53
    }
54
55
    /**
56
     * Assert that the elements are.
57
     */
58 View Code Duplication
    protected function assertSearchResults($expectedIds, $searchResult)
59
    {
60
        $ids = array_map(
61
            function ($hit) {
62
                return $hit->valueObject->id;
63
            },
64
            $searchResult->searchHits
65
        );
66
67
        sort($ids);
68
69
        $this->assertEquals($expectedIds, $ids);
70
    }
71
72
    /**
73
     * Returns the location search handler to test.
74
     *
75
     * This method returns a fully functional search handler to perform tests on.
76
     *
77
     * @param array $fullTextSearchConfiguration
78
     *
79
     * @return \eZ\Publish\Core\Search\Legacy\Content\Handler
80
     */
81
    protected function getContentSearchHandler(array $fullTextSearchConfiguration = [])
82
    {
83
        $transformationProcessor = new Persistence\TransformationProcessor\DefinitionBased(
84
            new Persistence\TransformationProcessor\DefinitionBased\Parser(),
85
            new Persistence\TransformationProcessor\PcreCompiler(
86
                new Persistence\Utf8Converter()
87
            ),
88
            glob(__DIR__ . '/../../../../Persistence/Tests/TransformationProcessor/_fixtures/transformations/*.tr')
89
        );
90
        $commaSeparatedCollectionValueHandler = new CommonCriterionHandler\FieldValue\Handler\Collection(
91
            $this->getDatabaseHandler(),
92
            $transformationProcessor,
93
            ','
94
        );
95
        $hyphenSeparatedCollectionValueHandler = new CommonCriterionHandler\FieldValue\Handler\Collection(
96
            $this->getDatabaseHandler(),
97
            $transformationProcessor,
98
            '-'
99
        );
100
        $simpleValueHandler = new CommonCriterionHandler\FieldValue\Handler\Simple(
101
            $this->getDatabaseHandler(),
102
            $transformationProcessor
103
        );
104
        $compositeValueHandler = new CommonCriterionHandler\FieldValue\Handler\Composite(
105
            $this->getDatabaseHandler(),
106
            $transformationProcessor
107
        );
108
109
        return new Content\Handler(
110
            $this->getMock('eZ\\Publish\\Core\\Search\\Legacy\\Content\\Gateway'),
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
111
            new Content\Location\Gateway\DoctrineDatabase(
112
                $this->getDatabaseHandler(),
113
                new CriteriaConverter(
114
                    [
115
                        new LocationCriterionHandler\LocationId($this->getDatabaseHandler()),
116
                        new LocationCriterionHandler\ParentLocationId($this->getDatabaseHandler()),
117
                        new LocationCriterionHandler\LocationRemoteId($this->getDatabaseHandler()),
118
                        new LocationCriterionHandler\Subtree($this->getDatabaseHandler()),
119
                        new LocationCriterionHandler\Visibility($this->getDatabaseHandler()),
120
                        new LocationCriterionHandler\Location\Depth($this->getDatabaseHandler()),
121
                        new LocationCriterionHandler\Location\Priority($this->getDatabaseHandler()),
122
                        new LocationCriterionHandler\Location\IsMainLocation($this->getDatabaseHandler()),
123
                        new CommonCriterionHandler\ContentId($this->getDatabaseHandler()),
124
                        new CommonCriterionHandler\ContentTypeGroupId($this->getDatabaseHandler()),
125
                        new CommonCriterionHandler\ContentTypeId($this->getDatabaseHandler()),
126
                        new CommonCriterionHandler\ContentTypeIdentifier(
127
                            $this->getDatabaseHandler(),
128
                            $this->getContentTypeHandler()
129
                        ),
130
                        new CommonCriterionHandler\DateMetadata($this->getDatabaseHandler()),
131
                        new CommonCriterionHandler\Field(
132
                            $this->getDatabaseHandler(),
133
                            $this->getContentTypeHandler(),
134
                            $this->getLanguageHandler(),
135
                            $this->getConverterRegistry(),
136
                            new CommonCriterionHandler\FieldValue\Converter(
137
                                new CommonCriterionHandler\FieldValue\HandlerRegistry(
138
                                    [
139
                                        'ezboolean' => $simpleValueHandler,
140
                                        'ezcountry' => $commaSeparatedCollectionValueHandler,
141
                                        'ezdate' => $simpleValueHandler,
142
                                        'ezdatetime' => $simpleValueHandler,
143
                                        'ezemail' => $simpleValueHandler,
144
                                        'ezinteger' => $simpleValueHandler,
145
                                        'ezobjectrelation' => $simpleValueHandler,
146
                                        'ezobjectrelationlist' => $commaSeparatedCollectionValueHandler,
147
                                        'ezselection' => $hyphenSeparatedCollectionValueHandler,
148
                                        'eztime' => $simpleValueHandler,
149
                                    ]
150
                                ),
151
                                $compositeValueHandler
152
                            ),
153
                            $transformationProcessor
154
                        ),
155
                        new CommonCriterionHandler\FullText(
156
                            $this->getDatabaseHandler(),
157
                            $transformationProcessor,
158
                            $fullTextSearchConfiguration
159
                        ),
160
                        new CommonCriterionHandler\LanguageCode(
161
                            $this->getDatabaseHandler(),
162
                            $this->getLanguageMaskGenerator()
163
                        ),
164
                        new CommonCriterionHandler\LogicalAnd($this->getDatabaseHandler()),
165
                        new CommonCriterionHandler\LogicalNot($this->getDatabaseHandler()),
166
                        new CommonCriterionHandler\LogicalOr($this->getDatabaseHandler()),
167
                        new CommonCriterionHandler\MapLocationDistance(
168
                            $this->getDatabaseHandler(),
169
                            $this->getContentTypeHandler(),
170
                            $this->getLanguageHandler()
171
                        ),
172
                        new CommonCriterionHandler\MatchAll($this->getDatabaseHandler()),
173
                        new CommonCriterionHandler\ObjectStateId($this->getDatabaseHandler()),
174
                        new CommonCriterionHandler\FieldRelation(
175
                            $this->getDatabaseHandler(),
176
                            $this->getContentTypeHandler(),
177
                            $this->getLanguageHandler()
178
                        ),
179
                        new CommonCriterionHandler\RemoteId($this->getDatabaseHandler()),
180
                        new CommonCriterionHandler\SectionId($this->getDatabaseHandler()),
181
                        new CommonCriterionHandler\UserMetadata($this->getDatabaseHandler()),
182
                    ]
183
                ),
184
                new SortClauseConverter(
185
                    [
186
                        new LocationSortClauseHandler\Location\Id($this->getDatabaseHandler()),
187
                        new CommonSortClauseHandler\ContentId($this->getDatabaseHandler()),
188
                    ]
189
                ),
190
                $this->getLanguageHandler()
191
            ),
192
            new Content\WordIndexer\Gateway\DoctrineDatabase(
193
                $this->getDatabaseHandler(),
194
                $this->getContentTypeHandler(),
195
                $transformationProcessor,
196
                new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseHandler()),
197
                $this->getFullTextSearchConfiguration()
198
            ),
199
            $this->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Mapper')->disableOriginalConstructor()->getMock(),
200
            $this->getLocationMapperMock(),
201
            $this->getLanguageHandler(),
202
            $this->getFullTextMapper($this->getContentTypeHandler())
203
        );
204
    }
205
206
    protected $contentTypeHandler;
207
208 View Code Duplication
    protected function getContentTypeHandler()
209
    {
210
        if (!isset($this->contentTypeHandler)) {
211
            $this->contentTypeHandler = new ContentTypeHandler(
212
                new ContentTypeGateway(
213
                    $this->getDatabaseHandler(),
214
                    $this->getLanguageMaskGenerator()
215
                ),
216
                new ContentTypeMapper($this->getConverterRegistry()),
217
                $this->getMock('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Type\\Update\\Handler')
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
218
            );
219
        }
220
221
        return $this->contentTypeHandler;
222
    }
223
224
    protected $fieldRegistry;
225
226 View Code Duplication
    protected function getConverterRegistry()
227
    {
228
        if (!isset($this->fieldRegistry)) {
229
            $this->fieldRegistry = new ConverterRegistry(
230
                [
231
                    'ezdatetime' => new Converter\DateAndTimeConverter(),
232
                    'ezinteger' => new Converter\IntegerConverter(),
233
                    'ezstring' => new Converter\TextLineConverter(),
234
                    'ezprice' => new Converter\IntegerConverter(),
235
                    'ezurl' => new Converter\UrlConverter(),
236
                    'ezrichtext' => new Converter\RichTextConverter(),
237
                    'ezboolean' => new Converter\CheckboxConverter(),
238
                    'ezkeyword' => new Converter\KeywordConverter(),
239
                ]
240
            );
241
        }
242
243
        return $this->fieldRegistry;
244
    }
245
246
    /**
247
     * Returns a location mapper mock.
248
     *
249
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
250
     */
251 View Code Duplication
    protected function getLocationMapperMock()
252
    {
253
        $mapperMock = $this->getMock(
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\Core\Base\Tes...5CompatTrait::getMock() has been deprecated with message: Since PHPUnit 5.4, marked as deprecated here to make it clear when working on 6.7/5.4 branches
{@inheritdoc}

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
254
            'eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Mapper',
255
            ['createLocationsFromRows']
256
        );
257
        $mapperMock
258
            ->expects($this->any())
259
            ->method('createLocationsFromRows')
260
            ->with($this->isType('array'))
261
            ->will(
262
                $this->returnCallback(
263
                    function ($rows) {
264
                        $locations = [];
265
                        foreach ($rows as $row) {
266
                            $locationId = (int)$row['node_id'];
267
                            if (!isset($locations[$locationId])) {
268
                                $locations[$locationId] = new SPILocation();
269
                                $locations[$locationId]->id = $locationId;
270
                            }
271
                        }
272
273
                        return array_values($locations);
274
                    }
275
                )
276
            );
277
278
        return $mapperMock;
279
    }
280
281
    public function testFindWithoutOffsetLimit()
282
    {
283
        $handler = $this->getContentSearchHandler();
284
285
        $searchResult = $handler->findLocations(
286
            new LocationQuery(
287
                [
288
                    'filter' => new Criterion\LocationId(2),
289
                ]
290
            )
291
        );
292
293
        $this->assertEquals(1, $searchResult->totalCount);
294
        $this->assertCount(1, $searchResult->searchHits);
295
    }
296
297 View Code Duplication
    public function testFindWithZeroLimit()
298
    {
299
        $handler = $this->getContentSearchHandler();
300
301
        $searchResult = $handler->findLocations(
302
            new LocationQuery(
303
                [
304
                    'filter' => new Criterion\LocationId(2),
305
                    'offset' => 0,
306
                    'limit' => 0,
307
                ]
308
            )
309
        );
310
311
        $this->assertEquals(1, $searchResult->totalCount);
312
        $this->assertEquals([], $searchResult->searchHits);
313
    }
314
315
    /**
316
     * Issue with PHP_MAX_INT limit overflow in databases.
317
     */
318 View Code Duplication
    public function testFindWithNullLimit()
319
    {
320
        $handler = $this->getContentSearchHandler();
321
322
        $searchResult = $handler->findLocations(
323
            new LocationQuery(
324
                [
325
                    'filter' => new Criterion\LocationId(2),
326
                    'offset' => 0,
327
                    'limit' => null,
328
                ]
329
            )
330
        );
331
332
        $this->assertEquals(1, $searchResult->totalCount);
333
        $this->assertCount(1, $searchResult->searchHits);
334
    }
335
336
    /**
337
     * Issue with offsetting to the nonexistent results produces \ezcQueryInvalidParameterException exception.
338
     */
339 View Code Duplication
    public function testFindWithOffsetToNonexistent()
340
    {
341
        $handler = $this->getContentSearchHandler();
342
343
        $searchResult = $handler->findLocations(
344
            new LocationQuery(
345
                [
346
                    'filter' => new Criterion\LocationId(2),
347
                    'offset' => 1000,
348
                    'limit' => null,
349
                ]
350
            )
351
        );
352
353
        $this->assertEquals(1, $searchResult->totalCount);
354
        $this->assertEquals([], $searchResult->searchHits);
355
    }
356
357
    public function testLocationIdFilter()
358
    {
359
        $this->assertSearchResults(
360
            [12, 13],
361
            $this->getContentSearchHandler()->findLocations(
362
                new LocationQuery(
363
                    [
364
                        'filter' => new Criterion\LocationId(
365
                            [4, 12, 13]
366
                        ),
367
                        'limit' => 10,
368
                    ]
369
                )
370
            )
371
        );
372
    }
373
374
    public function testParentLocationIdFilter()
375
    {
376
        $this->assertSearchResults(
377
            [12, 13, 14, 44, 227],
378
            $this->getContentSearchHandler()->findLocations(
379
                new LocationQuery(
380
                    [
381
                        'filter' => new Criterion\ParentLocationId(5),
382
                        'limit' => 10,
383
                    ]
384
                )
385
            )
386
        );
387
    }
388
389 View Code Duplication
    public function testLocationIdAndCombinatorFilter()
390
    {
391
        $this->assertSearchResults(
392
            [13],
393
            $this->getContentSearchHandler()->findLocations(
394
                new LocationQuery(
395
                    [
396
                        'filter' => new Criterion\LogicalAnd(
397
                            [
398
                                new Criterion\LocationId(
399
                                    [4, 12, 13]
400
                                ),
401
                                new Criterion\LocationId(
402
                                    [13, 44]
403
                                ),
404
                            ]
405
                        ),
406
                        'limit' => 10,
407
                    ]
408
                )
409
            )
410
        );
411
    }
412
413 View Code Duplication
    public function testLocationIdParentLocationIdAndCombinatorFilter()
414
    {
415
        $this->assertSearchResults(
416
            [44, 160],
417
            $this->getContentSearchHandler()->findLocations(
418
                new LocationQuery(
419
                    [
420
                        'filter' => new Criterion\LogicalAnd(
421
                            [
422
                                new Criterion\LocationId(
423
                                    [2, 44, 160, 166]
424
                                ),
425
                                new Criterion\ParentLocationId(
426
                                    [5, 156]
427
                                ),
428
                            ]
429
                        ),
430
                        'limit' => 10,
431
                    ]
432
                )
433
            )
434
        );
435
    }
436
437
    public function testContentDepthFilterEq()
438
    {
439
        $this->assertSearchResults(
440
            [2, 5, 43, 48, 58],
441
            $this->getContentSearchHandler()->findLocations(
442
                new LocationQuery(
443
                    [
444
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::EQ, 1),
445
                        'limit' => 10,
446
                    ]
447
                )
448
            )
449
        );
450
    }
451
452 View Code Duplication
    public function testContentDepthFilterIn()
453
    {
454
        $this->assertSearchResults(
455
            [2, 5, 12, 13, 14, 43, 44, 48, 51, 52, 53, 54, 56, 58, 59, 69, 77, 86, 96, 107, 153, 156, 167, 190, 227],
456
            $this->getContentSearchHandler()->findLocations(
457
                new LocationQuery(
458
                    [
459
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::IN, [1, 2]),
460
                        'limit' => 50,
461
                    ]
462
                )
463
            )
464
        );
465
    }
466
467
    public function testContentDepthFilterBetween()
468
    {
469
        $this->assertSearchResults(
470
            [2, 5, 43, 48, 58],
471
            $this->getContentSearchHandler()->findLocations(
472
                new LocationQuery(
473
                    [
474
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::BETWEEN, [0, 1]),
475
                    ]
476
                )
477
            )
478
        );
479
    }
480
481 View Code Duplication
    public function testContentDepthFilterGreaterThan()
482
    {
483
        $this->assertSearchResults(
484
            [99, 102, 135, 136, 137, 139, 140, 142, 143, 144, 145, 148, 151, 174, 175, 177, 194, 196, 197, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 214, 215],
485
            $this->getContentSearchHandler()->findLocations(
486
                new LocationQuery(
487
                    [
488
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::GT, 4),
489
                        'limit' => 50,
490
                    ]
491
                )
492
            )
493
        );
494
    }
495
496 View Code Duplication
    public function testContentDepthFilterGreaterThanOrEqual()
497
    {
498
        $this->assertSearchResults(
499
            [99, 102, 135, 136, 137, 139, 140, 142, 143, 144, 145, 148, 151, 174, 175, 177, 194, 196, 197, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 214, 215],
500
            $this->getContentSearchHandler()->findLocations(
501
                new LocationQuery(
502
                    [
503
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::GTE, 5),
504
                        'limit' => 50,
505
                    ]
506
                )
507
            )
508
        );
509
    }
510
511
    public function testContentDepthFilterLessThan()
512
    {
513
        $this->assertSearchResults(
514
            [2, 5, 43, 48, 58],
515
            $this->getContentSearchHandler()->findLocations(
516
                new LocationQuery(
517
                    [
518
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::LT, 2),
519
                        'limit' => 10,
520
                    ]
521
                )
522
            )
523
        );
524
    }
525
526 View Code Duplication
    public function testContentDepthFilterLessThanOrEqual()
527
    {
528
        $this->assertSearchResults(
529
            [2, 5, 12, 13, 14, 43, 44, 48, 51, 52, 53, 54, 56, 58, 59, 69, 77, 86, 96, 107, 153, 156, 167, 190, 227],
530
            $this->getContentSearchHandler()->findLocations(
531
                new LocationQuery(
532
                    [
533
                        'filter' => new Criterion\Location\Depth(Criterion\Operator::LTE, 2),
534
                        'limit' => 50,
535
                    ]
536
                )
537
            )
538
        );
539
    }
540
541
    public function testLocationPriorityFilter()
542
    {
543
        $this->assertSearchResults(
544
            [156, 167, 190],
545
            $this->getContentSearchHandler()->findLocations(
546
                new LocationQuery(
547
                    [
548
                        'filter' => new Criterion\Location\Priority(
549
                            Criterion\Operator::BETWEEN,
550
                            [1, 10]
551
                        ),
552
                        'limit' => 10,
553
                    ]
554
                )
555
            )
556
        );
557
    }
558
559
    public function testLocationRemoteIdFilter()
560
    {
561
        $this->assertSearchResults(
562
            [2, 5],
563
            $this->getContentSearchHandler()->findLocations(
564
                new LocationQuery(
565
                    [
566
                        'filter' => new Criterion\LocationRemoteId(
567
                            ['3f6d92f8044aed134f32153517850f5a', 'f3e90596361e31d496d4026eb624c983']
568
                        ),
569
                        'limit' => 10,
570
                    ]
571
                )
572
            )
573
        );
574
    }
575
576 View Code Duplication
    public function testVisibilityFilterVisible()
577
    {
578
        $this->assertSearchResults(
579
            [2, 5, 12, 13, 14],
580
            $this->getContentSearchHandler()->findLocations(
581
                new LocationQuery(
582
                    [
583
                        'filter' => new Criterion\Visibility(
584
                            Criterion\Visibility::VISIBLE
585
                        ),
586
                        'limit' => 5,
587
                        'sortClauses' => [new SortClause\Location\Id()],
588
                    ]
589
                )
590
            )
591
        );
592
    }
593
594
    public function testVisibilityFilterHidden()
595
    {
596
        $this->assertSearchResults(
597
            [228],
598
            $this->getContentSearchHandler()->findLocations(
599
                new LocationQuery(
600
                    [
601
                        'filter' => new Criterion\Visibility(
602
                            Criterion\Visibility::HIDDEN
603
                        ),
604
                    ]
605
                )
606
            )
607
        );
608
    }
609
610 View Code Duplication
    public function testLocationNotCombinatorFilter()
611
    {
612
        $this->assertSearchResults(
613
            [2, 5],
614
            $this->getContentSearchHandler()->findLocations(
615
                new LocationQuery(
616
                    [
617
                        'filter' => new Criterion\LogicalAnd(
618
                            [
619
                                new Criterion\LocationId(
620
                                    [2, 5, 12, 356]
621
                                ),
622
                                new Criterion\LogicalNot(
623
                                    new Criterion\LocationId(
624
                                        [12, 13, 14]
625
                                    )
626
                                ),
627
                            ]
628
                        ),
629
                        'limit' => 10,
630
                    ]
631
                )
632
            )
633
        );
634
    }
635
636
    public function testLocationOrCombinatorFilter()
637
    {
638
        $this->assertSearchResults(
639
            [2, 5, 12, 13, 14],
640
            $this->getContentSearchHandler()->findLocations(
641
                new LocationQuery(
642
                    [
643
                        'filter' => new Criterion\LogicalOr(
644
                            [
645
                                new Criterion\LocationId(
646
                                    [2, 5, 12]
647
                                ),
648
                                new Criterion\LocationId(
649
                                    [12, 13, 14]
650
                                ),
651
                            ]
652
                        ),
653
                        'limit' => 10,
654
                    ]
655
                )
656
            )
657
        );
658
    }
659
660
    public function testContentIdFilterEquals()
661
    {
662
        $this->assertSearchResults(
663
            [225],
664
            $this->getContentSearchHandler()->findLocations(
665
                new LocationQuery(
666
                    [
667
                        'filter' => new Criterion\ContentId(223),
668
                    ]
669
                )
670
            )
671
        );
672
    }
673
674
    public function testContentIdFilterIn()
675
    {
676
        $this->assertSearchResults(
677
            [225, 226, 227],
678
            $this->getContentSearchHandler()->findLocations(
679
                new LocationQuery(
680
                    [
681
                        'filter' => new Criterion\ContentId(
682
                            [223, 224, 225]
683
                        ),
684
                    ]
685
                )
686
            )
687
        );
688
    }
689
690 View Code Duplication
    public function testContentTypeGroupFilter()
691
    {
692
        $this->assertSearchResults(
693
            [5, 12, 13, 14, 15, 44, 45, 227, 228],
694
            $this->getContentSearchHandler()->findLocations(
695
                new LocationQuery(
696
                    [
697
                        'filter' => new Criterion\ContentTypeGroupId(2),
698
                        'limit' => 10,
699
                    ]
700
                )
701
            )
702
        );
703
    }
704
705
    public function testContentTypeIdFilter()
706
    {
707
        $this->assertSearchResults(
708
            [15, 45, 228],
709
            $this->getContentSearchHandler()->findLocations(
710
                new LocationQuery(
711
                    [
712
                        'filter' => new Criterion\ContentTypeId(4),
713
                        'limit' => 10,
714
                    ]
715
                )
716
            )
717
        );
718
    }
719
720 View Code Duplication
    public function testContentTypeIdentifierFilter()
721
    {
722
        $this->assertSearchResults(
723
            [43, 48, 51, 52, 53],
724
            $this->getContentSearchHandler()->findLocations(
725
                new LocationQuery(
726
                    [
727
                        'filter' => new Criterion\ContentTypeIdentifier('folder'),
728
                        'limit' => 5,
729
                        'sortClauses' => [new SortClause\Location\Id()],
730
                    ]
731
                )
732
            )
733
        );
734
    }
735
736 View Code Duplication
    public function testObjectStateIdFilter()
737
    {
738
        $this->assertSearchResults(
739
            [5, 12, 13, 14, 15, 43, 44, 45, 48, 51],
740
            $this->getContentSearchHandler()->findLocations(
741
                new LocationQuery(
742
                    [
743
                        'filter' => new Criterion\ObjectStateId(1),
744
                        'limit' => 10,
745
                        'sortClauses' => [new SortClause\ContentId()],
746
                    ]
747
                )
748
            )
749
        );
750
    }
751
752
    public function testObjectStateIdFilterIn()
753
    {
754
        $this->assertSearchResults(
755
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48],
756
            $this->getContentSearchHandler()->findLocations(
757
                new LocationQuery(
758
                    [
759
                        'filter' => new Criterion\ObjectStateId([1, 2]),
760
                        'limit' => 10,
761
                        'sortClauses' => [new SortClause\Location\Id()],
762
                    ]
763
                )
764
            )
765
        );
766
    }
767
768
    public function testRemoteIdFilter()
769
    {
770
        $this->assertSearchResults(
771
            [5, 45],
772
            $this->getContentSearchHandler()->findLocations(
773
                new LocationQuery(
774
                    [
775
                        'filter' => new Criterion\RemoteId(
776
                            ['f5c88a2209584891056f987fd965b0ba', 'faaeb9be3bd98ed09f606fc16d144eca']
777
                        ),
778
                        'limit' => 10,
779
                    ]
780
                )
781
            )
782
        );
783
    }
784
785 View Code Duplication
    public function testSectionFilter()
786
    {
787
        $this->assertSearchResults(
788
            [5, 12, 13, 14, 15, 44, 45, 228],
789
            $this->getContentSearchHandler()->findLocations(
790
                new LocationQuery(
791
                    [
792
                        'filter' => new Criterion\SectionId([2]),
793
                        'limit' => 10,
794
                    ]
795
                )
796
            )
797
        );
798
    }
799
800
    public function testDateMetadataFilterModifiedGreater()
801
    {
802
        $this->assertSearchResults(
803
            [12, 227, 228],
804
            $this->getContentSearchHandler()->findLocations(
805
                new LocationQuery(
806
                    [
807
                        'filter' => new Criterion\DateMetadata(
808
                            Criterion\DateMetadata::MODIFIED,
809
                            Criterion\Operator::GT,
810
                            1311154214
811
                        ),
812
                        'limit' => 10,
813
                    ]
814
                )
815
            )
816
        );
817
    }
818
819
    public function testDateMetadataFilterModifiedGreaterOrEqual()
820
    {
821
        $this->assertSearchResults(
822
            [12, 15, 227, 228],
823
            $this->getContentSearchHandler()->findLocations(
824
                new LocationQuery(
825
                    [
826
                        'filter' => new Criterion\DateMetadata(
827
                            Criterion\DateMetadata::MODIFIED,
828
                            Criterion\Operator::GTE,
829
                            1311154214
830
                        ),
831
                        'limit' => 10,
832
                    ]
833
                )
834
            )
835
        );
836
    }
837
838 View Code Duplication
    public function testDateMetadataFilterModifiedIn()
839
    {
840
        $this->assertSearchResults(
841
            [12, 15, 227, 228],
842
            $this->getContentSearchHandler()->findLocations(
843
                new LocationQuery(
844
                    [
845
                        'filter' => new Criterion\DateMetadata(
846
                            Criterion\DateMetadata::MODIFIED,
847
                            Criterion\Operator::IN,
848
                            [1311154214, 1311154215]
849
                        ),
850
                        'limit' => 10,
851
                    ]
852
                )
853
            )
854
        );
855
    }
856
857 View Code Duplication
    public function testDateMetadataFilterModifiedBetween()
858
    {
859
        $this->assertSearchResults(
860
            [12, 15, 227, 228],
861
            $this->getContentSearchHandler()->findLocations(
862
                new LocationQuery(
863
                    [
864
                        'filter' => new Criterion\DateMetadata(
865
                            Criterion\DateMetadata::MODIFIED,
866
                            Criterion\Operator::BETWEEN,
867
                            [1311154213, 1311154215]
868
                        ),
869
                        'limit' => 10,
870
                    ]
871
                )
872
            )
873
        );
874
    }
875
876 View Code Duplication
    public function testDateMetadataFilterCreatedBetween()
877
    {
878
        $this->assertSearchResults(
879
            [68, 133, 227],
880
            $this->getContentSearchHandler()->findLocations(
881
                new LocationQuery(
882
                    [
883
                        'filter' => new Criterion\DateMetadata(
884
                            Criterion\DateMetadata::CREATED,
885
                            Criterion\Operator::BETWEEN,
886
                            [1299780749, 1311154215]
887
                        ),
888
                        'limit' => 10,
889
                    ]
890
                )
891
            )
892
        );
893
    }
894
895
    public function testUserMetadataFilterOwnerWrongUserId()
896
    {
897
        $this->assertSearchResults(
898
            [],
899
            $this->getContentSearchHandler()->findLocations(
900
                new LocationQuery(
901
                    [
902
                        'filter' => new Criterion\UserMetadata(
903
                            Criterion\UserMetadata::OWNER,
904
                            Criterion\Operator::EQ,
905
                            2
906
                        ),
907
                    ]
908
                )
909
            )
910
        );
911
    }
912
913 View Code Duplication
    public function testUserMetadataFilterOwnerAdministrator()
914
    {
915
        $this->assertSearchResults(
916
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48],
917
            $this->getContentSearchHandler()->findLocations(
918
                new LocationQuery(
919
                    [
920
                        'filter' => new Criterion\UserMetadata(
921
                            Criterion\UserMetadata::OWNER,
922
                            Criterion\Operator::EQ,
923
                            14
924
                        ),
925
                        'limit' => 10,
926
                        'sortClauses' => [new SortClause\Location\Id()],
927
                    ]
928
                )
929
            )
930
        );
931
    }
932
933
    public function testUserMetadataFilterOwnerEqAMember()
934
    {
935
        $this->assertSearchResults(
936
            [225],
937
            $this->getContentSearchHandler()->findLocations(
938
                new LocationQuery(
939
                    [
940
                        'filter' => new Criterion\UserMetadata(
941
                            Criterion\UserMetadata::OWNER,
942
                            Criterion\Operator::EQ,
943
                            226
944
                        ),
945
                    ]
946
                )
947
            )
948
        );
949
    }
950
951
    public function testUserMetadataFilterOwnerInAMember()
952
    {
953
        $this->assertSearchResults(
954
            [225],
955
            $this->getContentSearchHandler()->findLocations(
956
                new LocationQuery(
957
                    [
958
                        'filter' => new Criterion\UserMetadata(
959
                            Criterion\UserMetadata::OWNER,
960
                            Criterion\Operator::IN,
961
                            [226]
962
                        ),
963
                    ]
964
                )
965
            )
966
        );
967
    }
968
969
    public function testUserMetadataFilterCreatorEqAMember()
970
    {
971
        $this->assertSearchResults(
972
            [225],
973
            $this->getContentSearchHandler()->findLocations(
974
                new LocationQuery(
975
                    [
976
                        'filter' => new Criterion\UserMetadata(
977
                            Criterion\UserMetadata::MODIFIER,
978
                            Criterion\Operator::EQ,
979
                            226
980
                        ),
981
                    ]
982
                )
983
            )
984
        );
985
    }
986
987
    public function testUserMetadataFilterCreatorInAMember()
988
    {
989
        $this->assertSearchResults(
990
            [225],
991
            $this->getContentSearchHandler()->findLocations(
992
                new LocationQuery(
993
                    [
994
                        'filter' => new Criterion\UserMetadata(
995
                            Criterion\UserMetadata::MODIFIER,
996
                            Criterion\Operator::IN,
997
                            [226]
998
                        ),
999
                    ]
1000
                )
1001
            )
1002
        );
1003
    }
1004
1005
    public function testUserMetadataFilterEqGroupMember()
1006
    {
1007
        $this->assertSearchResults(
1008
            [225],
1009
            $this->getContentSearchHandler()->findLocations(
1010
                new LocationQuery(
1011
                    [
1012
                        'filter' => new Criterion\UserMetadata(
1013
                            Criterion\UserMetadata::GROUP,
1014
                            Criterion\Operator::EQ,
1015
                            11
1016
                        ),
1017
                    ]
1018
                )
1019
            )
1020
        );
1021
    }
1022
1023
    public function testUserMetadataFilterInGroupMember()
1024
    {
1025
        $this->assertSearchResults(
1026
            [225],
1027
            $this->getContentSearchHandler()->findLocations(
1028
                new LocationQuery(
1029
                    [
1030
                        'filter' => new Criterion\UserMetadata(
1031
                            Criterion\UserMetadata::GROUP,
1032
                            Criterion\Operator::IN,
1033
                            [11]
1034
                        ),
1035
                    ]
1036
                )
1037
            )
1038
        );
1039
    }
1040
1041
    public function testUserMetadataFilterEqGroupMemberNoMatch()
1042
    {
1043
        $this->assertSearchResults(
1044
            [],
1045
            $this->getContentSearchHandler()->findLocations(
1046
                new LocationQuery(
1047
                    [
1048
                        'filter' => new Criterion\UserMetadata(
1049
                            Criterion\UserMetadata::GROUP,
1050
                            Criterion\Operator::EQ,
1051
                            13
1052
                        ),
1053
                    ]
1054
                )
1055
            )
1056
        );
1057
    }
1058
1059
    public function testUserMetadataFilterInGroupMemberNoMatch()
1060
    {
1061
        $this->assertSearchResults(
1062
            [],
1063
            $this->getContentSearchHandler()->findLocations(
1064
                new LocationQuery(
1065
                    [
1066
                        'filter' => new Criterion\UserMetadata(
1067
                            Criterion\UserMetadata::GROUP,
1068
                            Criterion\Operator::IN,
1069
                            [13]
1070
                        ),
1071
                    ]
1072
                )
1073
            )
1074
        );
1075
    }
1076
1077 View Code Duplication
    public function testLanguageCodeFilter()
1078
    {
1079
        $this->assertSearchResults(
1080
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48],
1081
            $this->getContentSearchHandler()->findLocations(
1082
                new LocationQuery(
1083
                    [
1084
                        'filter' => new Criterion\LanguageCode('eng-US'),
1085
                        'limit' => 10,
1086
                        'sortClauses' => [new SortClause\Location\Id()],
1087
                    ]
1088
                )
1089
            )
1090
        );
1091
    }
1092
1093
    public function testLanguageCodeFilterIn()
1094
    {
1095
        $this->assertSearchResults(
1096
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48],
1097
            $this->getContentSearchHandler()->findLocations(
1098
                new LocationQuery(
1099
                    [
1100
                        'filter' => new Criterion\LanguageCode(['eng-US', 'eng-GB']),
1101
                        'limit' => 10,
1102
                        'sortClauses' => [new SortClause\Location\Id()],
1103
                    ]
1104
                )
1105
            )
1106
        );
1107
    }
1108
1109 View Code Duplication
    public function testLanguageCodeFilterWithAlwaysAvailable()
1110
    {
1111
        $this->assertSearchResults(
1112
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48, 51, 52, 53, 58, 59, 70, 72, 76, 78, 82],
1113
            $this->getContentSearchHandler()->findLocations(
1114
                new LocationQuery(
1115
                    [
1116
                        'filter' => new Criterion\LanguageCode('eng-GB', true),
1117
                        'limit' => 20,
1118
                        'sortClauses' => [new SortClause\ContentId()],
1119
                    ]
1120
                )
1121
            )
1122
        );
1123
    }
1124
1125
    public function testMatchAllFilter()
1126
    {
1127
        $result = $this->getContentSearchHandler()->findLocations(
1128
            new LocationQuery(
1129
                [
1130
                    'filter' => new Criterion\MatchAll(),
1131
                    'limit' => 10,
1132
                    'sortClauses' => [new SortClause\Location\Id()],
1133
                ]
1134
            )
1135
        );
1136
1137
        $this->assertCount(10, $result->searchHits);
1138
        $this->assertEquals(186, $result->totalCount);
1139
        $this->assertSearchResults(
1140
            [2, 5, 12, 13, 14, 15, 43, 44, 45, 48],
1141
            $result
1142
        );
1143
    }
1144
1145
    public function testFullTextFilter()
1146
    {
1147
        $this->assertSearchResults(
1148
            [193],
1149
            $this->getContentSearchHandler()->findLocations(
1150
                new LocationQuery(
1151
                    [
1152
                        'filter' => new Criterion\FullText('applied webpage'),
1153
                        'limit' => 10,
1154
                    ]
1155
                )
1156
            )
1157
        );
1158
    }
1159
1160
    public function testFullTextWildcardFilter()
1161
    {
1162
        $this->assertSearchResults(
1163
            [193],
1164
            $this->getContentSearchHandler()->findLocations(
1165
                new LocationQuery(
1166
                    [
1167
                        'filter' => new Criterion\FullText('applie*'),
1168
                        'limit' => 10,
1169
                    ]
1170
                )
1171
            )
1172
        );
1173
    }
1174
1175
    public function testFullTextDisabledWildcardFilter()
1176
    {
1177
        $this->assertSearchResults(
1178
            [],
1179
            $this->getContentSearchHandler(['enableWildcards' => false])->findLocations(
1180
                new LocationQuery(
1181
                    [
1182
                        'filter' => new Criterion\FullText('applie*'),
1183
                        'limit' => 10,
1184
                    ]
1185
                )
1186
            )
1187
        );
1188
    }
1189
1190
    public function testFullTextFilterStopwordRemoval()
1191
    {
1192
        $handler = $this->getContentSearchHandler(
1193
            [
1194
                'stopWordThresholdFactor' => 0.1,
1195
            ]
1196
        );
1197
        $this->assertSearchResults(
1198
            [],
1199
            $handler->findLocations(
1200
                new LocationQuery(
1201
                    [
1202
                        'filter' => new Criterion\FullText('the'),
1203
                        'limit' => 10,
1204
                    ]
1205
                )
1206
            )
1207
        );
1208
    }
1209
1210
    public function testFullTextFilterNoStopwordRemoval()
1211
    {
1212
        $handler = $this->getContentSearchHandler(
1213
            [
1214
                'stopWordThresholdFactor' => 1,
1215
            ]
1216
        );
1217
1218
        $result = $handler->findLocations(
1219
            new LocationQuery(
1220
                [
1221
                    'filter' => new Criterion\FullText(
1222
                        'the'
1223
                    ),
1224
                    'limit' => 10,
1225
                ]
1226
            )
1227
        );
1228
1229
        $this->assertEquals(26, $result->totalCount);
1230
        $this->assertCount(10, $result->searchHits);
1231
        $this->assertEquals(
1232
            10,
1233
            count(
1234
                array_map(
1235
                    function ($hit) {
1236
                        return $hit->valueObject->id;
1237
                    },
1238
                    $result->searchHits
1239
                )
1240
            )
1241
        );
1242
    }
1243
1244
    /**
1245
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1246
     */
1247
    public function testFullTextFilterInvalidStopwordThreshold()
1248
    {
1249
        $this->getContentSearchHandler(
1250
            [
1251
                'stopWordThresholdFactor' => 2,
1252
            ]
1253
        );
1254
    }
1255
1256
    public function testFieldRelationFilterContainsSingle()
1257
    {
1258
        $this->assertSearchResults(
1259
            [69],
1260
            $this->getContentSearchHandler()->findLocations(
1261
                new LocationQuery(
1262
                    [
1263
                        'filter' => new Criterion\FieldRelation(
1264
                            'billboard',
1265
                            Criterion\Operator::CONTAINS,
1266
                            [60]
1267
                        ),
1268
                    ]
1269
                )
1270
            )
1271
        );
1272
    }
1273
1274
    public function testFieldRelationFilterContainsSingleNoMatch()
1275
    {
1276
        $this->assertSearchResults(
1277
            [],
1278
            $this->getContentSearchHandler()->findLocations(
1279
                new LocationQuery(
1280
                    [
1281
                        'filter' => new Criterion\FieldRelation(
1282
                            'billboard',
1283
                            Criterion\Operator::CONTAINS,
1284
                            [4]
1285
                        ),
1286
                    ]
1287
                )
1288
            )
1289
        );
1290
    }
1291
1292 View Code Duplication
    public function testFieldRelationFilterContainsArray()
1293
    {
1294
        $this->assertSearchResults(
1295
            [69],
1296
            $this->getContentSearchHandler()->findLocations(
1297
                new LocationQuery(
1298
                    [
1299
                        'filter' => new Criterion\FieldRelation(
1300
                            'billboard',
1301
                            Criterion\Operator::CONTAINS,
1302
                            [60, 75]
1303
                        ),
1304
                    ]
1305
                )
1306
            )
1307
        );
1308
    }
1309
1310
    public function testFieldRelationFilterContainsArrayNotMatch()
1311
    {
1312
        $this->assertSearchResults(
1313
            [],
1314
            $this->getContentSearchHandler()->findLocations(
1315
                new LocationQuery(
1316
                    [
1317
                        'filter' => new Criterion\FieldRelation(
1318
                            'billboard',
1319
                            Criterion\Operator::CONTAINS,
1320
                            [60, 64]
1321
                        ),
1322
                    ]
1323
                )
1324
            )
1325
        );
1326
    }
1327
1328 View Code Duplication
    public function testFieldRelationFilterInArray()
1329
    {
1330
        $this->assertSearchResults(
1331
            [69, 77],
1332
            $this->getContentSearchHandler()->findLocations(
1333
                new LocationQuery(
1334
                    [
1335
                        'filter' => new Criterion\FieldRelation(
1336
                            'billboard',
1337
                            Criterion\Operator::IN,
1338
                            [60, 64]
1339
                        ),
1340
                    ]
1341
                )
1342
            )
1343
        );
1344
    }
1345
1346
    public function testFieldRelationFilterInArrayNotMatch()
1347
    {
1348
        $this->assertSearchResults(
1349
            [],
1350
            $this->getContentSearchHandler()->findLocations(
1351
                new LocationQuery(
1352
                    [
1353
                        'filter' => new Criterion\FieldRelation(
1354
                            'billboard',
1355
                            Criterion\Operator::IN,
1356
                            [4, 10]
1357
                        ),
1358
                    ]
1359
                )
1360
            )
1361
        );
1362
    }
1363
1364
    public function testFieldFilter()
1365
    {
1366
        $this->assertSearchResults(
1367
            [12],
1368
            $this->getContentSearchHandler()->findLocations(
1369
                new LocationQuery(
1370
                    [
1371
                        'filter' => new Criterion\Field(
1372
                            'name',
1373
                            Criterion\Operator::EQ,
1374
                            'members'
1375
                        ),
1376
                        'limit' => 10,
1377
                    ]
1378
                )
1379
            )
1380
        );
1381
    }
1382
1383 View Code Duplication
    public function testFieldFilterIn()
1384
    {
1385
        $this->assertSearchResults(
1386
            [12, 44],
1387
            $this->getContentSearchHandler()->findLocations(
1388
                new LocationQuery(
1389
                    [
1390
                        'filter' => new Criterion\Field(
1391
                            'name',
1392
                            Criterion\Operator::IN,
1393
                            ['members', 'anonymous users']
1394
                        ),
1395
                        'limit' => 10,
1396
                    ]
1397
                )
1398
            )
1399
        );
1400
    }
1401
1402
    public function testFieldFilterContainsPartial()
1403
    {
1404
        $this->assertSearchResults(
1405
            [44],
1406
            $this->getContentSearchHandler()->findLocations(
1407
                new LocationQuery(
1408
                    [
1409
                        'filter' => new Criterion\Field(
1410
                            'name',
1411
                            Criterion\Operator::CONTAINS,
1412
                            'nonymous use'
1413
                        ),
1414
                        'limit' => 10,
1415
                    ]
1416
                )
1417
            )
1418
        );
1419
    }
1420
1421
    public function testFieldFilterContainsSimple()
1422
    {
1423
        $this->assertSearchResults(
1424
            [79],
1425
            $this->getContentSearchHandler()->findLocations(
1426
                new LocationQuery(
1427
                    [
1428
                        'filter' => new Criterion\Field(
1429
                            'publish_date',
1430
                            Criterion\Operator::CONTAINS,
1431
                            1174643880
1432
                        ),
1433
                        'limit' => 10,
1434
                    ]
1435
                )
1436
            )
1437
        );
1438
    }
1439
1440
    public function testFieldFilterContainsSimpleNoMatch()
1441
    {
1442
        $this->assertSearchResults(
1443
            [],
1444
            $this->getContentSearchHandler()->findLocations(
1445
                new LocationQuery(
1446
                    [
1447
                        'filter' => new Criterion\Field(
1448
                            'publish_date',
1449
                            Criterion\Operator::CONTAINS,
1450
                            1174643
1451
                        ),
1452
                        'limit' => 10,
1453
                    ]
1454
                )
1455
            )
1456
        );
1457
    }
1458
1459 View Code Duplication
    public function testFieldFilterBetween()
1460
    {
1461
        $this->assertSearchResults(
1462
            [71, 73, 74],
1463
            $this->getContentSearchHandler()->findLocations(
1464
                new LocationQuery(
1465
                    [
1466
                        'filter' => new Criterion\Field(
1467
                            'price',
1468
                            Criterion\Operator::BETWEEN,
1469
                            [10000, 1000000]
1470
                        ),
1471
                        'limit' => 10,
1472
                    ]
1473
                )
1474
            )
1475
        );
1476
    }
1477
1478 View Code Duplication
    public function testFieldFilterOr()
1479
    {
1480
        $this->assertSearchResults(
1481
            [12, 71, 73, 74],
1482
            $this->getContentSearchHandler()->findLocations(
1483
                new LocationQuery(
1484
                    [
1485
                        'filter' => new Criterion\LogicalOr(
1486
                            [
1487
                                new Criterion\Field(
1488
                                    'name',
1489
                                    Criterion\Operator::EQ,
1490
                                    'members'
1491
                                ),
1492
                                new Criterion\Field(
1493
                                    'price',
1494
                                    Criterion\Operator::BETWEEN,
1495
                                    [10000, 1000000]
1496
                                ),
1497
                            ]
1498
                        ),
1499
                        'limit' => 10,
1500
                    ]
1501
                )
1502
            )
1503
        );
1504
    }
1505
1506 View Code Duplication
    public function testIsMainLocationFilter()
1507
    {
1508
        $this->assertSearchResults(
1509
            [225],
1510
            $this->getContentSearchHandler()->findLocations(
1511
                new LocationQuery(
1512
                    [
1513
                        'filter' => new Criterion\LogicalAnd(
1514
                            [
1515
                                new Criterion\ParentLocationId(224),
1516
                                new Criterion\Location\IsMainLocation(
1517
                                    Criterion\Location\IsMainLocation::MAIN
1518
                                ),
1519
                            ]
1520
                        ),
1521
                        'limit' => 10,
1522
                    ]
1523
                )
1524
            )
1525
        );
1526
    }
1527
1528 View Code Duplication
    public function testIsNotMainLocationFilter()
1529
    {
1530
        $this->assertSearchResults(
1531
            [510],
1532
            $this->getContentSearchHandler()->findLocations(
1533
                new LocationQuery(
1534
                    [
1535
                        'filter' => new Criterion\LogicalAnd(
1536
                            [
1537
                                new Criterion\ParentLocationId(224),
1538
                                new Criterion\Location\IsMainLocation(
1539
                                    Criterion\Location\IsMainLocation::NOT_MAIN
1540
                                ),
1541
                            ]
1542
                        ),
1543
                        'limit' => 10,
1544
                    ]
1545
                )
1546
            )
1547
        );
1548
    }
1549
}
1550