Code Duplication    Length = 74-74 lines in 2 locations

eZ/Publish/API/Repository/Tests/SearchServiceLocationTest.php 2 locations

@@ 486-559 (lines=74) @@
483
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
484
     * @group maplocation
485
     */
486
    public function testMapLocationDistanceLessThanOrEqual()
487
    {
488
        $contentType = $this->createTestPlaceContentType();
489
490
        // Create a draft to account for behaviour with ContentType in different states
491
        $repository = $this->getRepository();
492
        $contentTypeService = $repository->getContentTypeService();
493
        $contentService = $repository->getContentService();
494
        $contentTypeService->createContentTypeDraft($contentType);
495
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
496
497
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
498
        $createStruct->alwaysAvailable = false;
499
        $createStruct->mainLanguageCode = 'eng-GB';
500
        $createStruct->setField(
501
            'maplocation',
502
            [
503
                'latitude' => 45.894877,
504
                'longitude' => 15.972699,
505
                'address' => 'Here be wild boars',
506
            ],
507
            'eng-GB'
508
        );
509
510
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
511
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
512
513
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
514
        $createStruct->alwaysAvailable = false;
515
        $createStruct->mainLanguageCode = 'eng-GB';
516
        $createStruct->setField(
517
            'maplocation',
518
            [
519
                'latitude' => 45.927334,
520
                'longitude' => 15.934847,
521
                'address' => 'A lone tree',
522
            ],
523
            'eng-GB'
524
        );
525
526
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
527
        $tree = $contentService->publishVersion($draft->getVersionInfo());
528
529
        $this->refreshSearch($repository);
530
531
        $query = new LocationQuery(
532
            [
533
                'filter' => new Criterion\LogicalAnd(
534
                    [
535
                        new Criterion\ContentTypeId($contentType->id),
536
                        new Criterion\MapLocationDistance(
537
                            'maplocation',
538
                            Criterion\Operator::LTE,
539
                            240,
540
                            43.756825,
541
                            15.775074
542
                        ),
543
                    ]
544
                ),
545
                'offset' => 0,
546
                'limit' => 10,
547
                'sortClauses' => [],
548
            ]
549
        );
550
551
        $searchService = $repository->getSearchService();
552
        $result = $searchService->findLocations($query);
553
554
        $this->assertEquals(1, $result->totalCount);
555
        $this->assertEquals(
556
            $wildBoars->contentInfo->mainLocationId,
557
            $result->searchHits[0]->valueObject->id
558
        );
559
    }
560
561
    /**
562
     * Test for the findLocations() method.
@@ 567-640 (lines=74) @@
564
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
565
     * @group maplocation
566
     */
567
    public function testMapLocationDistanceGreaterThanOrEqual()
568
    {
569
        $contentType = $this->createTestPlaceContentType();
570
571
        // Create a draft to account for behaviour with ContentType in different states
572
        $repository = $this->getRepository();
573
        $contentTypeService = $repository->getContentTypeService();
574
        $contentService = $repository->getContentService();
575
        $contentTypeService->createContentTypeDraft($contentType);
576
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
577
578
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
579
        $createStruct->alwaysAvailable = false;
580
        $createStruct->mainLanguageCode = 'eng-GB';
581
        $createStruct->setField(
582
            'maplocation',
583
            [
584
                'latitude' => 45.894877,
585
                'longitude' => 15.972699,
586
                'address' => 'Here be wild boars',
587
            ],
588
            'eng-GB'
589
        );
590
591
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
592
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
593
594
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
595
        $createStruct->alwaysAvailable = false;
596
        $createStruct->mainLanguageCode = 'eng-GB';
597
        $createStruct->setField(
598
            'maplocation',
599
            [
600
                'latitude' => 45.927334,
601
                'longitude' => 15.934847,
602
                'address' => 'A lone tree',
603
            ],
604
            'eng-GB'
605
        );
606
607
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
608
        $tree = $contentService->publishVersion($draft->getVersionInfo());
609
610
        $this->refreshSearch($repository);
611
612
        $query = new LocationQuery(
613
            [
614
                'filter' => new Criterion\LogicalAnd(
615
                    [
616
                        new Criterion\ContentTypeId($contentType->id),
617
                        new Criterion\MapLocationDistance(
618
                            'maplocation',
619
                            Criterion\Operator::GTE,
620
                            240,
621
                            43.756825,
622
                            15.775074
623
                        ),
624
                    ]
625
                ),
626
                'offset' => 0,
627
                'limit' => 10,
628
                'sortClauses' => [],
629
            ]
630
        );
631
632
        $searchService = $repository->getSearchService();
633
        $result = $searchService->findLocations($query);
634
635
        $this->assertEquals(1, $result->totalCount);
636
        $this->assertEquals(
637
            $tree->contentInfo->mainLocationId,
638
            $result->searchHits[0]->valueObject->id
639
        );
640
    }
641
642
    /**
643
     * Test for the findLocations() method.