Code Duplication    Length = 73-73 lines in 2 locations

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

@@ 2822-2894 (lines=73) @@
2819
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2820
     * @group maplocation
2821
     */
2822
    public function testMapLocationDistanceLessThanOrEqual()
2823
    {
2824
        $contentType = $this->createTestPlaceContentType();
2825
2826
        // Create a draft to account for behaviour with ContentType in different states
2827
        $repository = $this->getRepository();
2828
        $contentTypeService = $repository->getContentTypeService();
2829
        $contentService = $repository->getContentService();
2830
        $contentTypeService->createContentTypeDraft($contentType);
2831
2832
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2833
        $createStruct->alwaysAvailable = false;
2834
        $createStruct->mainLanguageCode = 'eng-GB';
2835
        $createStruct->setField(
2836
            'maplocation',
2837
            [
2838
                'latitude' => 45.894877,
2839
                'longitude' => 15.972699,
2840
                'address' => 'Here be wild boars',
2841
            ],
2842
            'eng-GB'
2843
        );
2844
2845
        $draft = $contentService->createContent($createStruct);
2846
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2847
2848
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2849
        $createStruct->alwaysAvailable = false;
2850
        $createStruct->mainLanguageCode = 'eng-GB';
2851
        $createStruct->setField(
2852
            'maplocation',
2853
            [
2854
                'latitude' => 45.927334,
2855
                'longitude' => 15.934847,
2856
                'address' => 'A lone tree',
2857
            ],
2858
            'eng-GB'
2859
        );
2860
2861
        $draft = $contentService->createContent($createStruct);
2862
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2863
2864
        $this->refreshSearch($repository);
2865
2866
        $query = new Query(
2867
            [
2868
                'filter' => new Criterion\LogicalAnd(
2869
                    [
2870
                        new Criterion\ContentTypeId($contentType->id),
2871
                        new Criterion\MapLocationDistance(
2872
                            'maplocation',
2873
                            Criterion\Operator::LTE,
2874
                            240,
2875
                            43.756825,
2876
                            15.775074
2877
                        ),
2878
                    ]
2879
                ),
2880
                'offset' => 0,
2881
                'limit' => 10,
2882
                'sortClauses' => [],
2883
            ]
2884
        );
2885
2886
        $searchService = $repository->getSearchService();
2887
        $result = $searchService->findContent($query);
2888
2889
        $this->assertEquals(1, $result->totalCount);
2890
        $this->assertEquals(
2891
            $wildBoars->id,
2892
            $result->searchHits[0]->valueObject->id
2893
        );
2894
    }
2895
2896
    /**
2897
     * Test for the findContent() method.
@@ 2902-2974 (lines=73) @@
2899
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2900
     * @group maplocation
2901
     */
2902
    public function testMapLocationDistanceGreaterThanOrEqual()
2903
    {
2904
        $contentType = $this->createTestPlaceContentType();
2905
2906
        // Create a draft to account for behaviour with ContentType in different states
2907
        $repository = $this->getRepository();
2908
        $contentTypeService = $repository->getContentTypeService();
2909
        $contentService = $repository->getContentService();
2910
        $contentTypeService->createContentTypeDraft($contentType);
2911
2912
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2913
        $createStruct->alwaysAvailable = false;
2914
        $createStruct->mainLanguageCode = 'eng-GB';
2915
        $createStruct->setField(
2916
            'maplocation',
2917
            [
2918
                'latitude' => 45.894877,
2919
                'longitude' => 15.972699,
2920
                'address' => 'Here be wild boars',
2921
            ],
2922
            'eng-GB'
2923
        );
2924
2925
        $draft = $contentService->createContent($createStruct);
2926
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2927
2928
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2929
        $createStruct->alwaysAvailable = false;
2930
        $createStruct->mainLanguageCode = 'eng-GB';
2931
        $createStruct->setField(
2932
            'maplocation',
2933
            [
2934
                'latitude' => 45.927334,
2935
                'longitude' => 15.934847,
2936
                'address' => 'A lone tree',
2937
            ],
2938
            'eng-GB'
2939
        );
2940
2941
        $draft = $contentService->createContent($createStruct);
2942
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2943
2944
        $this->refreshSearch($repository);
2945
2946
        $query = new Query(
2947
            [
2948
                'filter' => new Criterion\LogicalAnd(
2949
                    [
2950
                        new Criterion\ContentTypeId($contentType->id),
2951
                        new Criterion\MapLocationDistance(
2952
                            'maplocation',
2953
                            Criterion\Operator::GTE,
2954
                            240,
2955
                            43.756825,
2956
                            15.775074
2957
                        ),
2958
                    ]
2959
                ),
2960
                'offset' => 0,
2961
                'limit' => 10,
2962
                'sortClauses' => [],
2963
            ]
2964
        );
2965
2966
        $searchService = $repository->getSearchService();
2967
        $result = $searchService->findContent($query);
2968
2969
        $this->assertEquals(1, $result->totalCount);
2970
        $this->assertEquals(
2971
            $tree->id,
2972
            $result->searchHits[0]->valueObject->id
2973
        );
2974
    }
2975
2976
    /**
2977
     * Test for the findContent() method.