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

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