Code Duplication    Length = 53-53 lines in 2 locations

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

@@ 292-344 (lines=53) @@
289
        }
290
    }
291
292
    public function testSortSectionName()
293
    {
294
        $locator = $this->getContentSearchHandler();
295
296
        $result = $locator->findContent(
297
            new Query(
298
                array(
299
                    'filter' => new Criterion\SectionId(array(4, 2, 6, 3)),
300
                    'offset' => 0,
301
                    'limit' => null,
302
                    'sortClauses' => array(
303
                        new SortClause\SectionName(),
304
                    ),
305
                )
306
            )
307
        );
308
309
        // First, results of section "Media" should appear, then the ones of "Protected",
310
        // "Setup" and "Users"
311
        // From inside a specific section, no particular order should be defined
312
        // the logic is then to have a set of sorted id's to compare with
313
        // the comparison being done slice by slice.
314
        $idMapSet = array(
315
            'media' => array(41, 49, 50, 51, 57, 58, 59, 60, 61, 62, 63, 64, 66, 200, 201),
316
            'protected' => array(154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164),
317
            'setup' => array(45, 52),
318
            'users' => array(4, 10, 11, 12, 13, 14, 42, 226),
319
        );
320
        $contentIds = array_map(
321
            function ($hit) {
322
                return $hit->valueObject->id;
323
            },
324
            $result->searchHits
325
        );
326
327
        $expectedCount = 0;
328
        foreach ($idMapSet as $set) {
329
            $expectedCount += count($set);
330
        }
331
332
        $this->assertEquals($expectedCount, $result->totalCount);
333
334
        $index = 0;
335
        foreach ($idMapSet as $idSet) {
336
            $contentIdsSubset = array_slice($contentIds, $index, $count = count($idSet));
337
            $index += $count;
338
            sort($contentIdsSubset);
339
            $this->assertEquals(
340
                $idSet,
341
                $contentIdsSubset
342
            );
343
        }
344
    }
345
346
    public function testSortContentName()
347
    {

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

@@ 456-508 (lines=53) @@
453
        );
454
    }
455
456
    public function testSortSectionName()
457
    {
458
        $handler = $this->getContentSearchHandler();
459
460
        $result = $handler->findLocations(
461
            new LocationQuery(
462
                array(
463
                    'filter' => new Criterion\SectionId(array(4, 2, 6, 3)),
464
                    'offset' => 0,
465
                    'limit' => null,
466
                    'sortClauses' => array(
467
                        new SortClause\SectionName(),
468
                    ),
469
                )
470
            )
471
        );
472
473
        // First, results of section "Media" should appear, then the ones of "Protected",
474
        // "Setup" and "Users"
475
        // From inside a specific section, no particular order should be defined
476
        // the logic is then to have a set of sorted id's to compare with
477
        // the comparison being done slice by slice.
478
        $idMapSet = array(
479
            'media' => array(43, 51, 52, 53, 59, 60, 61, 62, 63, 64, 65, 66, 68, 202, 203),
480
            'protected' => array(156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166),
481
            'setup' => array(48, 54),
482
            'users' => array(5, 12, 13, 14, 15, 44, 45, 228),
483
        );
484
        $locationIds = array_map(
485
            function ($hit) {
486
                return $hit->valueObject->id;
487
            },
488
            $result->searchHits
489
        );
490
491
        $expectedCount = 0;
492
        foreach ($idMapSet as $set) {
493
            $expectedCount += count($set);
494
        }
495
496
        $this->assertEquals($expectedCount, $result->totalCount);
497
498
        $index = 0;
499
        foreach ($idMapSet as $idSet) {
500
            $locationIdsSubset = array_slice($locationIds, $index, $count = count($idSet));
501
            $index += $count;
502
            sort($locationIdsSubset);
503
            $this->assertEquals(
504
                $idSet,
505
                $locationIdsSubset
506
            );
507
        }
508
    }
509
510
    public function testSortFieldText()
511
    {