Code Duplication    Length = 53-53 lines in 2 locations

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

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

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

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