Code Duplication    Length = 73-73 lines in 2 locations

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

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