Code Duplication    Length = 73-73 lines in 2 locations

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

@@ 2657-2729 (lines=73) @@
2654
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2655
     * @group maplocation
2656
     */
2657
    public function testMapLocationDistanceLessThanOrEqual()
2658
    {
2659
        $contentType = $this->createTestPlaceContentType();
2660
2661
        // Create a draft to account for behaviour with ContentType in different states
2662
        $repository = $this->getRepository();
2663
        $contentTypeService = $repository->getContentTypeService();
2664
        $contentService = $repository->getContentService();
2665
        $contentTypeService->createContentTypeDraft($contentType);
2666
2667
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2668
        $createStruct->alwaysAvailable = false;
2669
        $createStruct->mainLanguageCode = 'eng-GB';
2670
        $createStruct->setField(
2671
            'maplocation',
2672
            [
2673
                'latitude' => 45.894877,
2674
                'longitude' => 15.972699,
2675
                'address' => 'Here be wild boars',
2676
            ],
2677
            'eng-GB'
2678
        );
2679
2680
        $draft = $contentService->createContent($createStruct);
2681
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2682
2683
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2684
        $createStruct->alwaysAvailable = false;
2685
        $createStruct->mainLanguageCode = 'eng-GB';
2686
        $createStruct->setField(
2687
            'maplocation',
2688
            [
2689
                'latitude' => 45.927334,
2690
                'longitude' => 15.934847,
2691
                'address' => 'A lone tree',
2692
            ],
2693
            'eng-GB'
2694
        );
2695
2696
        $draft = $contentService->createContent($createStruct);
2697
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2698
2699
        $this->refreshSearch($repository);
2700
2701
        $query = new Query(
2702
            [
2703
                'filter' => new Criterion\LogicalAnd(
2704
                    [
2705
                        new Criterion\ContentTypeId($contentType->id),
2706
                        new Criterion\MapLocationDistance(
2707
                            'maplocation',
2708
                            Criterion\Operator::LTE,
2709
                            240,
2710
                            43.756825,
2711
                            15.775074
2712
                        ),
2713
                    ]
2714
                ),
2715
                'offset' => 0,
2716
                'limit' => 10,
2717
                'sortClauses' => [],
2718
            ]
2719
        );
2720
2721
        $searchService = $repository->getSearchService();
2722
        $result = $searchService->findContent($query);
2723
2724
        $this->assertEquals(1, $result->totalCount);
2725
        $this->assertEquals(
2726
            $wildBoars->id,
2727
            $result->searchHits[0]->valueObject->id
2728
        );
2729
    }
2730
2731
    /**
2732
     * Test for the findContent() method.
@@ 2737-2809 (lines=73) @@
2734
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2735
     * @group maplocation
2736
     */
2737
    public function testMapLocationDistanceGreaterThanOrEqual()
2738
    {
2739
        $contentType = $this->createTestPlaceContentType();
2740
2741
        // Create a draft to account for behaviour with ContentType in different states
2742
        $repository = $this->getRepository();
2743
        $contentTypeService = $repository->getContentTypeService();
2744
        $contentService = $repository->getContentService();
2745
        $contentTypeService->createContentTypeDraft($contentType);
2746
2747
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2748
        $createStruct->alwaysAvailable = false;
2749
        $createStruct->mainLanguageCode = 'eng-GB';
2750
        $createStruct->setField(
2751
            'maplocation',
2752
            [
2753
                'latitude' => 45.894877,
2754
                'longitude' => 15.972699,
2755
                'address' => 'Here be wild boars',
2756
            ],
2757
            'eng-GB'
2758
        );
2759
2760
        $draft = $contentService->createContent($createStruct);
2761
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2762
2763
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2764
        $createStruct->alwaysAvailable = false;
2765
        $createStruct->mainLanguageCode = 'eng-GB';
2766
        $createStruct->setField(
2767
            'maplocation',
2768
            [
2769
                'latitude' => 45.927334,
2770
                'longitude' => 15.934847,
2771
                'address' => 'A lone tree',
2772
            ],
2773
            'eng-GB'
2774
        );
2775
2776
        $draft = $contentService->createContent($createStruct);
2777
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2778
2779
        $this->refreshSearch($repository);
2780
2781
        $query = new Query(
2782
            [
2783
                'filter' => new Criterion\LogicalAnd(
2784
                    [
2785
                        new Criterion\ContentTypeId($contentType->id),
2786
                        new Criterion\MapLocationDistance(
2787
                            'maplocation',
2788
                            Criterion\Operator::GTE,
2789
                            240,
2790
                            43.756825,
2791
                            15.775074
2792
                        ),
2793
                    ]
2794
                ),
2795
                'offset' => 0,
2796
                'limit' => 10,
2797
                'sortClauses' => [],
2798
            ]
2799
        );
2800
2801
        $searchService = $repository->getSearchService();
2802
        $result = $searchService->findContent($query);
2803
2804
        $this->assertEquals(1, $result->totalCount);
2805
        $this->assertEquals(
2806
            $tree->id,
2807
            $result->searchHits[0]->valueObject->id
2808
        );
2809
    }
2810
2811
    /**
2812
     * Test for the findContent() method.