Code Duplication    Length = 53-53 lines in 2 locations

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

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

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

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