Code Duplication    Length = 73-73 lines in 2 locations

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

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