Completed
Push — 7.0 ( e06b0d...07af66 )
by André
31:05 queued 19:36
created

HandlerLocationTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %

Importance

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