Code Duplication    Length = 73-73 lines in 2 locations

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

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