Code Duplication    Length = 53-53 lines in 2 locations

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

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

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

@@ 537-589 (lines=53) @@
534
        );
535
    }
536
537
    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
    public function testSortFieldText()
592
    {