Completed
Push — 6.13 ( 9c335d...8c8805 )
by
unknown
16:33
created

HandlerLocationSortTest::getConverterRegistry()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

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