Code Duplication    Length = 53-53 lines in 2 locations

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

@@ 345-397 (lines=53) @@
342
        }
343
    }
344
345
    public function testSortSectionName()
346
    {
347
        $locator = $this->getContentSearchHandler();
348
349
        $result = $locator->findContent(
350
            new Query(
351
                array(
352
                    'filter' => new Criterion\SectionId(array(4, 2, 6, 3)),
353
                    'offset' => 0,
354
                    'limit' => null,
355
                    'sortClauses' => array(
356
                        new SortClause\SectionName(),
357
                    ),
358
                )
359
            )
360
        );
361
362
        // First, results of section "Media" should appear, then the ones of "Protected",
363
        // "Setup" and "Users"
364
        // From inside a specific section, no particular order should be defined
365
        // the logic is then to have a set of sorted id's to compare with
366
        // the comparison being done slice by slice.
367
        $idMapSet = array(
368
            'media' => array(41, 49, 50, 51, 57, 58, 59, 60, 61, 62, 63, 64, 66, 200, 201),
369
            'protected' => array(154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164),
370
            'setup' => array(45, 52),
371
            'users' => array(4, 10, 11, 12, 13, 14, 42, 226),
372
        );
373
        $contentIds = array_map(
374
            function ($hit) {
375
                return $hit->valueObject->id;
376
            },
377
            $result->searchHits
378
        );
379
380
        $expectedCount = 0;
381
        foreach ($idMapSet as $set) {
382
            $expectedCount += count($set);
383
        }
384
385
        $this->assertEquals($expectedCount, $result->totalCount);
386
387
        $index = 0;
388
        foreach ($idMapSet as $idSet) {
389
            $contentIdsSubset = array_slice($contentIds, $index, $count = count($idSet));
390
            $index += $count;
391
            sort($contentIdsSubset);
392
            $this->assertEquals(
393
                $idSet,
394
                $contentIdsSubset
395
            );
396
        }
397
    }
398
399
    public function testSortContentName()
400
    {

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

@@ 527-579 (lines=53) @@
524
        );
525
    }
526
527
    public function testSortSectionName()
528
    {
529
        $handler = $this->getContentSearchHandler();
530
531
        $result = $handler->findLocations(
532
            new LocationQuery(
533
                array(
534
                    'filter' => new Criterion\SectionId(array(4, 2, 6, 3)),
535
                    'offset' => 0,
536
                    'limit' => null,
537
                    'sortClauses' => array(
538
                        new SortClause\SectionName(),
539
                    ),
540
                )
541
            )
542
        );
543
544
        // First, results of section "Media" should appear, then the ones of "Protected",
545
        // "Setup" and "Users"
546
        // From inside a specific section, no particular order should be defined
547
        // the logic is then to have a set of sorted id's to compare with
548
        // the comparison being done slice by slice.
549
        $idMapSet = array(
550
            'media' => array(43, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 68, 202, 203),
551
            'protected' => array(156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166),
552
            'setup' => array(48, 54),
553
            'users' => array(5, 12, 13, 14, 15, 44, 45, 228),
554
        );
555
        $locationIds = array_map(
556
            function ($hit) {
557
                return $hit->valueObject->id;
558
            },
559
            $result->searchHits
560
        );
561
562
        $expectedCount = 0;
563
        foreach ($idMapSet as $set) {
564
            $expectedCount += count($set);
565
        }
566
567
        $this->assertEquals($expectedCount, $result->totalCount);
568
569
        $index = 0;
570
        foreach ($idMapSet as $idSet) {
571
            $locationIdsSubset = array_slice($locationIds, $index, $count = count($idSet));
572
            $index += $count;
573
            sort($locationIdsSubset);
574
            $this->assertEquals(
575
                $idSet,
576
                $locationIdsSubset
577
            );
578
        }
579
    }
580
581
    public function testSortFieldText()
582
    {