Code Duplication    Length = 73-73 lines in 2 locations

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

@@ 2875-2947 (lines=73) @@
2872
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2873
     * @group maplocation
2874
     */
2875
    public function testMapLocationDistanceLessThanOrEqual()
2876
    {
2877
        $contentType = $this->createTestPlaceContentType();
2878
2879
        // Create a draft to account for behaviour with ContentType in different states
2880
        $repository = $this->getRepository();
2881
        $contentTypeService = $repository->getContentTypeService();
2882
        $contentService = $repository->getContentService();
2883
        $contentTypeService->createContentTypeDraft($contentType);
2884
2885
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2886
        $createStruct->alwaysAvailable = false;
2887
        $createStruct->mainLanguageCode = 'eng-GB';
2888
        $createStruct->setField(
2889
            'maplocation',
2890
            array(
2891
                'latitude' => 45.894877,
2892
                'longitude' => 15.972699,
2893
                'address' => 'Here be wild boars',
2894
            ),
2895
            'eng-GB'
2896
        );
2897
2898
        $draft = $contentService->createContent($createStruct);
2899
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2900
2901
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2902
        $createStruct->alwaysAvailable = false;
2903
        $createStruct->mainLanguageCode = 'eng-GB';
2904
        $createStruct->setField(
2905
            'maplocation',
2906
            array(
2907
                'latitude' => 45.927334,
2908
                'longitude' => 15.934847,
2909
                'address' => 'A lone tree',
2910
            ),
2911
            'eng-GB'
2912
        );
2913
2914
        $draft = $contentService->createContent($createStruct);
2915
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2916
2917
        $this->refreshSearch($repository);
2918
2919
        $query = new Query(
2920
            array(
2921
                'filter' => new Criterion\LogicalAnd(
2922
                    array(
2923
                        new Criterion\ContentTypeId($contentType->id),
2924
                        new Criterion\MapLocationDistance(
2925
                            'maplocation',
2926
                            Criterion\Operator::LTE,
2927
                            240,
2928
                            43.756825,
2929
                            15.775074
2930
                        ),
2931
                    )
2932
                ),
2933
                'offset' => 0,
2934
                'limit' => 10,
2935
                'sortClauses' => array(),
2936
            )
2937
        );
2938
2939
        $searchService = $repository->getSearchService();
2940
        $result = $searchService->findContent($query);
2941
2942
        $this->assertEquals(1, $result->totalCount);
2943
        $this->assertEquals(
2944
            $wildBoars->id,
2945
            $result->searchHits[0]->valueObject->id
2946
        );
2947
    }
2948
2949
    /**
2950
     * Test for the findContent() method.
@@ 2955-3027 (lines=73) @@
2952
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2953
     * @group maplocation
2954
     */
2955
    public function testMapLocationDistanceGreaterThanOrEqual()
2956
    {
2957
        $contentType = $this->createTestPlaceContentType();
2958
2959
        // Create a draft to account for behaviour with ContentType in different states
2960
        $repository = $this->getRepository();
2961
        $contentTypeService = $repository->getContentTypeService();
2962
        $contentService = $repository->getContentService();
2963
        $contentTypeService->createContentTypeDraft($contentType);
2964
2965
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2966
        $createStruct->alwaysAvailable = false;
2967
        $createStruct->mainLanguageCode = 'eng-GB';
2968
        $createStruct->setField(
2969
            'maplocation',
2970
            array(
2971
                'latitude' => 45.894877,
2972
                'longitude' => 15.972699,
2973
                'address' => 'Here be wild boars',
2974
            ),
2975
            'eng-GB'
2976
        );
2977
2978
        $draft = $contentService->createContent($createStruct);
2979
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2980
2981
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2982
        $createStruct->alwaysAvailable = false;
2983
        $createStruct->mainLanguageCode = 'eng-GB';
2984
        $createStruct->setField(
2985
            'maplocation',
2986
            array(
2987
                'latitude' => 45.927334,
2988
                'longitude' => 15.934847,
2989
                'address' => 'A lone tree',
2990
            ),
2991
            'eng-GB'
2992
        );
2993
2994
        $draft = $contentService->createContent($createStruct);
2995
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2996
2997
        $this->refreshSearch($repository);
2998
2999
        $query = new Query(
3000
            array(
3001
                'filter' => new Criterion\LogicalAnd(
3002
                    array(
3003
                        new Criterion\ContentTypeId($contentType->id),
3004
                        new Criterion\MapLocationDistance(
3005
                            'maplocation',
3006
                            Criterion\Operator::GTE,
3007
                            240,
3008
                            43.756825,
3009
                            15.775074
3010
                        ),
3011
                    )
3012
                ),
3013
                'offset' => 0,
3014
                'limit' => 10,
3015
                'sortClauses' => array(),
3016
            )
3017
        );
3018
3019
        $searchService = $repository->getSearchService();
3020
        $result = $searchService->findContent($query);
3021
3022
        $this->assertEquals(1, $result->totalCount);
3023
        $this->assertEquals(
3024
            $tree->id,
3025
            $result->searchHits[0]->valueObject->id
3026
        );
3027
    }
3028
3029
    /**
3030
     * Test for the findContent() method.