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

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