Code Duplication    Length = 53-53 lines in 2 locations

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

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

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

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