Completed
Push — master ( 97e40f...89ec5c )
by André
40:26 queued 12:35
created

HandlerLocationSortTest::assertSearchResults()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
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\Search\Legacy\Content;
13
use eZ\Publish\SPI\Persistence\Content\Location as SPILocation;
14
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
15
use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
16
use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
17
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
18
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler as CommonCriterionHandler;
19
use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\CriterionHandler as LocationCriterionHandler;
20
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter;
21
use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler as CommonSortClauseHandler;
22
use eZ\Publish\Core\Search\Legacy\Content\Location\Gateway\SortClauseHandler as LocationSortClauseHandler;
23
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway\DoctrineDatabase as ContentTypeGateway;
24
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler;
25
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper as ContentTypeMapper;
26
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter;
27
use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry;
28
use eZ\Publish\Core\Search\Legacy\Content\Gateway as ContentGateway;
29
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper as ContentMapper;
30
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Update\Handler as ContentTypeUpdateHandler;
31
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper as LocationMapper;
32
33
/**
34
 * Location Search test case for ContentSearchHandler.
35
 */
36
class HandlerLocationSortTest extends LanguageAwareTestCase
37
{
38
    protected static $setUp = false;
39
40
    /**
41
     * Only set up once for these read only tests on a large fixture.
42
     *
43
     * Skipping the reset-up, since setting up for these tests takes quite some
44
     * time, which is not required to spent, since we are only reading from the
45
     * database anyways.
46
     */
47 View Code Duplication
    public function setUp()
48
    {
49
        if (!self::$setUp) {
50
            parent::setUp();
51
            $this->insertDatabaseFixture(__DIR__ . '/../_fixtures/full_dump.php');
52
            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...
53
        } else {
54
            $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...
55
        }
56
    }
57
58
    /**
59
     * Assert that the elements are.
60
     */
61
    protected function assertSearchResults($expectedIds, $locations)
62
    {
63
        $ids = $this->getIds($locations);
64
        $this->assertEquals($expectedIds, $ids);
65
    }
66
67
    protected function getIds($searchResult)
68
    {
69
        $ids = array_map(
70
            function ($hit) {
71
                return $hit->valueObject->id;
72
            },
73
            $searchResult->searchHits
74
        );
75
76
        return $ids;
77
    }
78
79
    /**
80
     * Returns the location search handler to test.
81
     *
82
     * This method returns a fully functional search handler to perform tests on.
83
     *
84
     * @return \eZ\Publish\Core\Search\Legacy\Content\Handler
85
     */
86
    protected function getContentSearchHandler()
87
    {
88
        return new Content\Handler(
89
            $this->createMock(ContentGateway::class),
90
            new Content\Location\Gateway\DoctrineDatabase(
91
                $this->getDatabaseHandler(),
92
                new CriteriaConverter(
93
                    array(
94
                        new LocationCriterionHandler\LocationId($this->getDatabaseHandler()),
95
                        new LocationCriterionHandler\ParentLocationId($this->getDatabaseHandler()),
96
                        new CommonCriterionHandler\LogicalAnd($this->getDatabaseHandler()),
97
                        new CommonCriterionHandler\MatchAll($this->getDatabaseHandler()),
98
                        new CommonCriterionHandler\SectionId($this->getDatabaseHandler()),
99
                        new CommonCriterionHandler\ContentTypeIdentifier(
100
                            $this->getDatabaseHandler(),
101
                            $this->getContentTypeHandler()
102
                        ),
103
                    )
104
                ),
105
                new SortClauseConverter(
106
                    array(
107
                        new LocationSortClauseHandler\Location\Id($this->getDatabaseHandler()),
108
                        new LocationSortClauseHandler\Location\Depth($this->getDatabaseHandler()),
109
                        new LocationSortClauseHandler\Location\Path($this->getDatabaseHandler()),
110
                        new LocationSortClauseHandler\Location\Priority($this->getDatabaseHandler()),
111
                        new LocationSortClauseHandler\Location\Visibility($this->getDatabaseHandler()),
112
                        new LocationSortClauseHandler\Location\IsMainLocation($this->getDatabaseHandler()),
113
                        new CommonSortClauseHandler\ContentId($this->getDatabaseHandler()),
114
                        new CommonSortClauseHandler\ContentName($this->getDatabaseHandler()),
115
                        new CommonSortClauseHandler\DateModified($this->getDatabaseHandler()),
116
                        new CommonSortClauseHandler\DatePublished($this->getDatabaseHandler()),
117
                        new CommonSortClauseHandler\SectionIdentifier($this->getDatabaseHandler()),
118
                        new CommonSortClauseHandler\SectionName($this->getDatabaseHandler()),
119
                        new CommonSortClauseHandler\Field(
120
                            $this->getDatabaseHandler(),
121
                            $this->getLanguageHandler(),
122
                            $this->getContentTypeHandler()
123
                        ),
124
                    )
125
                ),
126
                $this->getLanguageHandler()
127
            ),
128
            new Content\WordIndexer\Gateway\DoctrineDatabase(
129
                $this->getDatabaseHandler(),
130
                $this->getContentTypeHandler(),
131
                $this->getDefinitionBasedTransformationProcessor(),
132
                new Content\WordIndexer\Repository\SearchIndex($this->getDatabaseHandler()),
133
                $this->getFullTextSearchConfiguration()
134
            ),
135
            $this->createMock(ContentMapper::class),
136
            $this->getLocationMapperMock(),
137
            $this->getLanguageHandler(),
138
            $this->getFullTextMapper($this->getContentTypeHandler())
139
        );
140
    }
141
142
    protected $contentTypeHandler;
143
144 View Code Duplication
    protected function getContentTypeHandler()
145
    {
146
        if (!isset($this->contentTypeHandler)) {
147
            $this->contentTypeHandler = new ContentTypeHandler(
148
                new ContentTypeGateway(
149
                    $this->getDatabaseHandler(),
150
                    $this->getDatabaseConnection(),
151
                    $this->getLanguageMaskGenerator()
152
                ),
153
                new ContentTypeMapper($this->getConverterRegistry()),
154
                $this->createMock(ContentTypeUpdateHandler::class)
155
            );
156
        }
157
158
        return $this->contentTypeHandler;
159
    }
160
161
    protected $fieldRegistry;
162
163
    protected function getConverterRegistry()
164
    {
165
        if (!isset($this->fieldRegistry)) {
166
            $this->fieldRegistry = new ConverterRegistry(
167
                array(
168
                    'ezdatetime' => new Converter\DateAndTimeConverter(),
169
                    'ezinteger' => new Converter\IntegerConverter(),
170
                    'ezstring' => new Converter\TextLineConverter(),
171
                    'ezprice' => new Converter\IntegerConverter(),
172
                    'ezurl' => new Converter\UrlConverter(),
173
                    'ezrichtext' => new Converter\RichTextConverter(),
174
                    'ezboolean' => new Converter\CheckboxConverter(),
175
                    'ezkeyword' => new Converter\KeywordConverter(),
176
                    'ezauthor' => new Converter\AuthorConverter(),
177
                    'ezimage' => new Converter\NullConverter(),
178
                    'ezsrrating' => new Converter\NullConverter(),
179
                    'ezmultioption' => new Converter\NullConverter(),
180
                )
181
            );
182
        }
183
184
        return $this->fieldRegistry;
185
    }
186
187
    /**
188
     * Returns a location mapper mock.
189
     *
190
     * @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper
191
     */
192 View Code Duplication
    protected function getLocationMapperMock()
193
    {
194
        $mapperMock = $this->getMockBuilder(LocationMapper::class)
195
            ->setMethods(array('createLocationsFromRows'))
196
            ->getMock();
197
        $mapperMock
198
            ->expects($this->any())
199
            ->method('createLocationsFromRows')
200
            ->with($this->isType('array'))
201
            ->will(
202
                $this->returnCallback(
203
                    function ($rows) {
204
                        $locations = array();
205
                        foreach ($rows as $row) {
206
                            $locationId = (int)$row['node_id'];
207
                            if (!isset($locations[$locationId])) {
208
                                $locations[$locationId] = new SPILocation();
209
                                $locations[$locationId]->id = $locationId;
210
                            }
211
                        }
212
213
                        return array_values($locations);
214
                    }
215
                )
216
            );
217
218
        return $mapperMock;
219
    }
220
221
    public function testNoSorting()
222
    {
223
        $handler = $this->getContentSearchHandler();
224
225
        $locations = $handler->findLocations(
226
            new LocationQuery(
227
                array(
228
                    'filter' => new Criterion\ParentLocationId(array(178)),
229
                    'offset' => 0,
230
                    'limit' => 5,
231
                    'sortClauses' => array(),
232
                )
233
            )
234
        );
235
236
        $ids = $this->getIds($locations);
237
        sort($ids);
238
        $this->assertEquals(
239
            array(179, 180, 181, 182, 183),
240
            $ids
241
        );
242
    }
243
244
    public function testSortLocationPath()
245
    {
246
        $handler = $this->getContentSearchHandler();
247
248
        $locations = $handler->findLocations(
249
            new LocationQuery(
250
                array(
251
                    'filter' => new Criterion\ParentLocationId(array(178)),
252
                    'offset' => 0,
253
                    'limit' => 10,
254
                    'sortClauses' => array(new SortClause\Location\Path(LocationQuery::SORT_DESC)),
255
                )
256
            )
257
        );
258
259
        $this->assertSearchResults(
260
            array(186, 185, 184, 183, 182, 181, 180, 179),
261
            $locations
262
        );
263
    }
264
265 View Code Duplication
    public function testSortLocationDepth()
266
    {
267
        $handler = $this->getContentSearchHandler();
268
269
        $locations = $handler->findLocations(
270
            new LocationQuery(
271
                array(
272
                    'filter' => new Criterion\LocationId(array(148, 167, 169, 172)),
273
                    'offset' => 0,
274
                    'limit' => 10,
275
                    'sortClauses' => array(new SortClause\Location\Depth(LocationQuery::SORT_ASC)),
276
                )
277
            )
278
        );
279
280
        $this->assertSearchResults(
281
            array(167, 172, 169, 148),
282
            $locations
283
        );
284
    }
285
286
    public function testSortLocationDepthAndPath()
287
    {
288
        $handler = $this->getContentSearchHandler();
289
290
        $locations = $handler->findLocations(
291
            new LocationQuery(
292
                array(
293
                    'filter' => new Criterion\LocationId(array(141, 142, 143, 144, 146, 147)),
294
                    'offset' => 0,
295
                    'limit' => 10,
296
                    'sortClauses' => array(
297
                        new SortClause\Location\Depth(LocationQuery::SORT_ASC),
298
                        new SortClause\Location\Path(LocationQuery::SORT_DESC),
299
                    ),
300
                )
301
            )
302
        );
303
304
        $this->assertSearchResults(
305
            array(147, 146, 141, 144, 143, 142),
306
            $locations
307
        );
308
    }
309
310 View Code Duplication
    public function testSortLocationPriority()
311
    {
312
        $handler = $this->getContentSearchHandler();
313
314
        $locations = $handler->findLocations(
315
            new LocationQuery(
316
                array(
317
                    'filter' => new Criterion\LocationId(array(149, 156, 167)),
318
                    'offset' => 0,
319
                    'limit' => 10,
320
                    'sortClauses' => array(
321
                        new SortClause\Location\Priority(LocationQuery::SORT_DESC),
322
                    ),
323
                )
324
            )
325
        );
326
327
        $this->assertSearchResults(
328
            array(167, 156, 149),
329
            $locations
330
        );
331
    }
332
333
    public function testSortDateModified()
334
    {
335
        $handler = $this->getContentSearchHandler();
336
337
        $locations = $handler->findLocations(
338
            new LocationQuery(
339
                array(
340
                    'filter' => new Criterion\LocationId(array(148, 167, 169, 172)),
341
                    'offset' => 0,
342
                    'limit' => 10,
343
                    'sortClauses' => array(
344
                        new SortClause\DateModified(),
345
                    ),
346
                )
347
            )
348
        );
349
350
        $this->assertSearchResults(
351
            array(169, 172, 167, 148),
352
            $locations
353
        );
354
    }
355
356 View Code Duplication
    public function testSortDatePublished()
357
    {
358
        $handler = $this->getContentSearchHandler();
359
360
        $locations = $handler->findLocations(
361
            new LocationQuery(
362
                array(
363
                    'filter' => new Criterion\LocationId(array(148, 167, 169, 172)),
364
                    'offset' => 0,
365
                    'limit' => 10,
366
                    'sortClauses' => array(
367
                        new SortClause\DatePublished(LocationQuery::SORT_DESC),
368
                    ),
369
                )
370
            )
371
        );
372
373
        $this->assertSearchResults(
374
            array(148, 172, 169, 167),
375
            $locations
376
        );
377
    }
378
379
    public function testSortSectionIdentifier()
380
    {
381
        $handler = $this->getContentSearchHandler();
382
383
        $locations = $handler->findLocations(
384
            new LocationQuery(
385
                array(
386
                    'filter' => new Criterion\LocationId(
387
                        array(5, 43, 45, 48, 51, 54, 156, 157)
388
                    ),
389
                    'offset' => 0,
390
                    'limit' => null,
391
                    'sortClauses' => array(
392
                        new SortClause\SectionIdentifier(),
393
                    ),
394
                )
395
            )
396
        );
397
398
        // First, results of section 2 should appear, then the ones of 3, 4 and 6
399
        // From inside a specific section, no particular order should be defined
400
        // the logic is then to have a set of sorted id's to compare with
401
        // the comparison being done slice by slice.
402
        $idMapSet = array(
403
            2 => array(5, 45),
404
            3 => array(43, 51),
405
            4 => array(48, 54),
406
            6 => array(156, 157),
407
        );
408
        $locationIds = $this->getIds($locations);
409
        $index = 0;
410
411
        foreach ($idMapSet as $idSet) {
412
            $locationIdsSubset = array_slice($locationIds, $index, $count = count($idSet));
413
            $index += $count;
414
            sort($locationIdsSubset);
415
            $this->assertEquals(
416
                $idSet,
417
                $locationIdsSubset
418
            );
419
        }
420
    }
421
422
    public function testSortContentName()
423
    {
424
        $handler = $this->getContentSearchHandler();
425
426
        $locations = $handler->findLocations(
427
            new LocationQuery(
428
                array(
429
                    'filter' => new Criterion\LocationId(array(13, 15, 44, 45, 228)),
430
                    'offset' => 0,
431
                    'limit' => null,
432
                    'sortClauses' => array(
433
                        new SortClause\ContentName(),
434
                    ),
435
                )
436
            )
437
        );
438
439
        $this->assertSearchResults(
440
            array(228, 15, 13, 45, 44),
441
            $locations
442
        );
443
    }
444
445
    public function testSortContentId()
446
    {
447
        $handler = $this->getContentSearchHandler();
448
449
        $locations = $handler->findLocations(
450
            new LocationQuery(
451
                array(
452
                    'filter' => new Criterion\LocationId(array(13, 15, 44, 45, 228)),
453
                    'offset' => 0,
454
                    'limit' => null,
455
                    'sortClauses' => array(
456
                        new SortClause\ContentId(),
457
                    ),
458
                )
459
            )
460
        );
461
462
        $this->assertSearchResults(
463
            array(45, 13, 15, 44, 228),
464
            $locations
465
        );
466
    }
467
468
    public function testSortLocationId()
469
    {
470
        $handler = $this->getContentSearchHandler();
471
472
        $locations = $handler->findLocations(
473
            new LocationQuery(
474
                array(
475
                    'filter' => new Criterion\LocationId(array(13, 15, 44, 45, 228)),
476
                    'offset' => 0,
477
                    'limit' => null,
478
                    'sortClauses' => array(
479
                        new SortClause\Location\Id(LocationQuery::SORT_DESC),
480
                    ),
481
                )
482
            )
483
        );
484
485
        $this->assertSearchResults(
486
            array(228, 45, 44, 15, 13),
487
            $locations
488
        );
489
    }
490
491 View Code Duplication
    public function testSortLocationVisibilityAscending()
492
    {
493
        $handler = $this->getContentSearchHandler();
494
495
        $locations = $handler->findLocations(
496
            new LocationQuery(
497
                array(
498
                    'filter' => new Criterion\LocationId(array(45, 228)),
499
                    'offset' => 0,
500
                    'limit' => null,
501
                    'sortClauses' => array(
502
                        new SortClause\Location\Visibility(LocationQuery::SORT_ASC),
503
                    ),
504
                )
505
            )
506
        );
507
508
        $this->assertSearchResults(
509
            array(45, 228),
510
            $locations
511
        );
512
    }
513
514 View Code Duplication
    public function testSortLocationVisibilityDescending()
515
    {
516
        $handler = $this->getContentSearchHandler();
517
518
        $locations = $handler->findLocations(
519
            new LocationQuery(
520
                array(
521
                    'filter' => new Criterion\LocationId(array(45, 228)),
522
                    'offset' => 0,
523
                    'limit' => null,
524
                    'sortClauses' => array(
525
                        new SortClause\Location\Visibility(LocationQuery::SORT_DESC),
526
                    ),
527
                )
528
            )
529
        );
530
531
        $this->assertSearchResults(
532
            array(228, 45),
533
            $locations
534
        );
535
    }
536
537 View Code Duplication
    public function testSortSectionName()
538
    {
539
        $handler = $this->getContentSearchHandler();
540
541
        $result = $handler->findLocations(
542
            new LocationQuery(
543
                array(
544
                    'filter' => new Criterion\SectionId(array(4, 2, 6, 3)),
545
                    'offset' => 0,
546
                    'limit' => null,
547
                    'sortClauses' => array(
548
                        new SortClause\SectionName(),
549
                    ),
550
                )
551
            )
552
        );
553
554
        // First, results of section "Media" should appear, then the ones of "Protected",
555
        // "Setup" and "Users"
556
        // From inside a specific section, no particular order should be defined
557
        // the logic is then to have a set of sorted id's to compare with
558
        // the comparison being done slice by slice.
559
        $idMapSet = array(
560
            'media' => array(43, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 68, 202, 203),
561
            'protected' => array(156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166),
562
            'setup' => array(48, 54),
563
            'users' => array(5, 12, 13, 14, 15, 44, 45, 228),
564
        );
565
        $locationIds = array_map(
566
            function ($hit) {
567
                return $hit->valueObject->id;
568
            },
569
            $result->searchHits
570
        );
571
572
        $expectedCount = 0;
573
        foreach ($idMapSet as $set) {
574
            $expectedCount += count($set);
575
        }
576
577
        $this->assertEquals($expectedCount, $result->totalCount);
578
579
        $index = 0;
580
        foreach ($idMapSet as $idSet) {
581
            $locationIdsSubset = array_slice($locationIds, $index, $count = count($idSet));
582
            $index += $count;
583
            sort($locationIdsSubset);
584
            $this->assertEquals(
585
                $idSet,
586
                $locationIdsSubset
587
            );
588
        }
589
    }
590
591 View Code Duplication
    public function testSortFieldText()
592
    {
593
        $handler = $this->getContentSearchHandler();
594
595
        $result = $handler->findLocations(
596
            new LocationQuery(
597
                array(
598
                    'filter' => new Criterion\LogicalAnd(
599
                        array(
600
                            new Criterion\SectionId(array(1)),
601
                            new Criterion\ContentTypeIdentifier(array('article')),
602
                        )
603
                    ),
604
                    'offset' => 0,
605
                    'limit' => null,
606
                    'sortClauses' => array(
607
                        new SortClause\Field('article', 'title', LocationQuery::SORT_ASC, 'eng-US'),
608
                    ),
609
                )
610
            )
611
        );
612
613
        // There are several identical titles, need to take care about this
614
        $idMapSet = array(
615
            'aenean malesuada ligula' => array(85),
616
            'aliquam pulvinar suscipit tellus' => array(104),
617
            'asynchronous publishing' => array(150, 217),
618
            'canonical links' => array(149, 218),
619
            'class aptent taciti' => array(90),
620
            'class aptent taciti sociosqu' => array(84),
621
            'duis auctor vehicula erat' => array(91),
622
            'etiam posuere sodales arcu' => array(80),
623
            'etiam sodales mauris' => array(89),
624
            'ez publish enterprise' => array(153),
625
            'fastcgi' => array(146, 220),
626
            'fusce sagittis sagittis' => array(79),
627
            'fusce sagittis sagittis urna' => array(83),
628
            'get involved' => array(109),
629
            'how to develop with ez publish' => array(129, 213),
630
            'how to manage ez publish' => array(120, 204),
631
            'how to use ez publish' => array(110, 195),
632
            'improved block editing' => array(138),
633
            'improved front-end editing' => array(141),
634
            'improved user registration workflow' => array(134),
635
            'in hac habitasse platea' => array(81),
636
            'lots of websites, one ez publish installation' => array(132),
637
            'rest api interface' => array(152, 216),
638
            'separate content & design in ez publish' => array(193),
639
            'support for red hat enterprise' => array(147, 219),
640
            'tutorials for' => array(108),
641
        );
642
        $locationIds = array_map(
643
            function ($hit) {
644
                return $hit->valueObject->id;
645
            },
646
            $result->searchHits
647
        );
648
        $index = 0;
649
650
        foreach ($idMapSet as $idSet) {
651
            $locationIdsSubset = array_slice($locationIds, $index, $count = count($idSet));
652
            $index += $count;
653
            sort($locationIdsSubset);
654
            $this->assertEquals(
655
                $idSet,
656
                $locationIdsSubset
657
            );
658
        }
659
    }
660
661 View Code Duplication
    public function testSortFieldNumeric()
662
    {
663
        $handler = $this->getContentSearchHandler();
664
665
        $result = $handler->findLocations(
666
            new LocationQuery(
667
                array(
668
                    'filter' => new Criterion\LogicalAnd(
669
                        array(
670
                            new Criterion\SectionId(array(1)),
671
                            new Criterion\ContentTypeIdentifier('product'),
672
                        )
673
                    ),
674
                    'offset' => 0,
675
                    'limit' => null,
676
                    'sortClauses' => array(
677
                        new SortClause\Field('product', 'price', LocationQuery::SORT_ASC, 'eng-US'),
678
                    ),
679
                )
680
            )
681
        );
682
683
        $this->assertEquals(
684
            array(75, 73, 74, 71),
685
            array_map(
686
                function ($hit) {
687
                    return $hit->valueObject->id;
688
                },
689
                $result->searchHits
690
            )
691
        );
692
    }
693
694 View Code Duplication
    public function testSortIsMainLocationAscending()
695
    {
696
        $handler = $this->getContentSearchHandler();
697
698
        $locations = $handler->findLocations(
699
            new LocationQuery(
700
                array(
701
                    'filter' => new Criterion\ParentLocationId(224),
702
                    'offset' => 0,
703
                    'limit' => null,
704
                    'sortClauses' => array(
705
                        new SortClause\Location\IsMainLocation(LocationQuery::SORT_ASC),
706
                    ),
707
                )
708
            )
709
        );
710
711
        $this->assertSearchResults(
712
            array(510, 225),
713
            $locations
714
        );
715
    }
716
717 View Code Duplication
    public function testSortIsMainLocationDescending()
718
    {
719
        $handler = $this->getContentSearchHandler();
720
721
        $locations = $handler->findLocations(
722
            new LocationQuery(
723
                array(
724
                    'filter' => new Criterion\ParentLocationId(224),
725
                    'offset' => 0,
726
                    'limit' => null,
727
                    'sortClauses' => array(
728
                        new SortClause\Location\IsMainLocation(LocationQuery::SORT_DESC),
729
                    ),
730
                )
731
            )
732
        );
733
734
        $this->assertSearchResults(
735
            array(225, 510),
736
            $locations
737
        );
738
    }
739
}
740