Code Duplication    Length = 69-69 lines in 2 locations

eZ/Publish/Core/Search/Legacy/Tests/Content/HandlerContentSortTest.php 1 location

@@ 435-503 (lines=69) @@
432
        );
433
    }
434
435
    public function testSortFieldText()
436
    {
437
        $locator = $this->getContentSearchHandler();
438
439
        $result = $locator->findContent(
440
            new Query(
441
                [
442
                    'filter' => new Criterion\LogicalAnd(
443
                        [
444
                            new Criterion\SectionId([1]),
445
                            new Criterion\ContentTypeIdentifier(['article']),
446
                        ]
447
                    ),
448
                    'offset' => 0,
449
                    'limit' => null,
450
                    'sortClauses' => [
451
                        new SortClause\Field('article', 'title', Query::SORT_ASC, 'eng-US'),
452
                    ],
453
                ]
454
            )
455
        );
456
457
        // There are several identical titles, need to take care about this
458
        $idMapSet = [
459
            'aenean malesuada ligula' => [83],
460
            'aliquam pulvinar suscipit tellus' => [102],
461
            'asynchronous publishing' => [148, 215],
462
            'canonical links' => [147, 216],
463
            'class aptent taciti' => [88],
464
            'class aptent taciti sociosqu' => [82],
465
            'duis auctor vehicula erat' => [89],
466
            'etiam posuere sodales arcu' => [78],
467
            'etiam sodales mauris' => [87],
468
            'ez publish enterprise' => [151],
469
            'fastcgi' => [144, 218],
470
            'fusce sagittis sagittis' => [77],
471
            'fusce sagittis sagittis urna' => [81],
472
            'get involved' => [107],
473
            'how to develop with ez publish' => [127, 211],
474
            'how to manage ez publish' => [118, 202],
475
            'how to use ez publish' => [108, 193],
476
            'improved block editing' => [136],
477
            'improved front-end editing' => [139],
478
            'improved user registration workflow' => [132],
479
            'in hac habitasse platea' => [79],
480
            'lots of websites, one ez publish installation' => [130],
481
            'rest api interface' => [150, 214],
482
            'separate content & design in ez publish' => [191],
483
            'support for red hat enterprise' => [145, 217],
484
            'tutorials for' => [106],
485
        ];
486
        $contentIds = array_map(
487
            function ($hit) {
488
                return $hit->valueObject->id;
489
            },
490
            $result->searchHits
491
        );
492
        $index = 0;
493
494
        foreach ($idMapSet as $idSet) {
495
            $contentIdsSubset = array_slice($contentIds, $index, $count = count($idSet));
496
            $index += $count;
497
            sort($contentIdsSubset);
498
            $this->assertEquals(
499
                $idSet,
500
                $contentIdsSubset
501
            );
502
        }
503
    }
504
505
    public function testSortFieldNumeric()
506
    {

eZ/Publish/Core/Search/Legacy/Tests/Content/HandlerLocationSortTest.php 1 location

@@ 590-658 (lines=69) @@
587
        }
588
    }
589
590
    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
    public function testSortFieldNumeric()
661
    {