Code Duplication    Length = 110-110 lines in 2 locations

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

@@ 2984-3093 (lines=110) @@
2981
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2982
     * @group maplocation
2983
     */
2984
    public function testMapLocationDistanceSortAscending()
2985
    {
2986
        $contentType = $this->createTestPlaceContentType();
2987
2988
        // Create a draft to account for behaviour with ContentType in different states
2989
        $repository = $this->getRepository();
2990
        $contentTypeService = $repository->getContentTypeService();
2991
        $contentService = $repository->getContentService();
2992
        $contentTypeService->createContentTypeDraft($contentType);
2993
2994
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2995
        $createStruct->alwaysAvailable = false;
2996
        $createStruct->mainLanguageCode = 'eng-GB';
2997
        $createStruct->setField(
2998
            'maplocation',
2999
            [
3000
                'latitude' => 45.894877,
3001
                'longitude' => 15.972699,
3002
                'address' => 'Here be wild boars',
3003
            ],
3004
            'eng-GB'
3005
        );
3006
3007
        $draft = $contentService->createContent($createStruct);
3008
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3009
3010
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3011
        $createStruct->alwaysAvailable = false;
3012
        $createStruct->mainLanguageCode = 'eng-GB';
3013
        $createStruct->setField(
3014
            'maplocation',
3015
            [
3016
                'latitude' => 45.927334,
3017
                'longitude' => 15.934847,
3018
                'address' => 'A lone tree',
3019
            ],
3020
            'eng-GB'
3021
        );
3022
3023
        $draft = $contentService->createContent($createStruct);
3024
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3025
3026
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3027
        $createStruct->alwaysAvailable = false;
3028
        $createStruct->mainLanguageCode = 'eng-GB';
3029
        $createStruct->setField(
3030
            'maplocation',
3031
            [
3032
                'latitude' => 45.903777,
3033
                'longitude' => 15.958788,
3034
                'address' => 'Meadow with mushrooms',
3035
            ],
3036
            'eng-GB'
3037
        );
3038
3039
        $draft = $contentService->createContent($createStruct);
3040
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3041
3042
        $this->refreshSearch($repository);
3043
3044
        $wellInVodice = [
3045
            'latitude' => 43.756825,
3046
            'longitude' => 15.775074,
3047
        ];
3048
3049
        $query = new Query(
3050
            [
3051
                'filter' => new Criterion\LogicalAnd(
3052
                    [
3053
                        new Criterion\ContentTypeId($contentType->id),
3054
                        new Criterion\MapLocationDistance(
3055
                            'maplocation',
3056
                            Criterion\Operator::GTE,
3057
                            235,
3058
                            $wellInVodice['latitude'],
3059
                            $wellInVodice['longitude']
3060
                        ),
3061
                    ]
3062
                ),
3063
                'offset' => 0,
3064
                'limit' => 10,
3065
                'sortClauses' => [
3066
                    new SortClause\MapLocationDistance(
3067
                        'testtype',
3068
                        'maplocation',
3069
                        $wellInVodice['latitude'],
3070
                        $wellInVodice['longitude'],
3071
                        Query::SORT_ASC
3072
                    ),
3073
                ],
3074
            ]
3075
        );
3076
3077
        $searchService = $repository->getSearchService();
3078
        $result = $searchService->findContent($query);
3079
3080
        $this->assertEquals(3, $result->totalCount);
3081
        $this->assertEquals(
3082
            $wildBoars->id,
3083
            $result->searchHits[0]->valueObject->id
3084
        );
3085
        $this->assertEquals(
3086
            $mushrooms->id,
3087
            $result->searchHits[1]->valueObject->id
3088
        );
3089
        $this->assertEquals(
3090
            $tree->id,
3091
            $result->searchHits[2]->valueObject->id
3092
        );
3093
    }
3094
3095
    /**
3096
     * Test for the findContent() method.
@@ 3101-3210 (lines=110) @@
3098
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
3099
     * @group maplocation
3100
     */
3101
    public function testMapLocationDistanceSortDescending()
3102
    {
3103
        $contentType = $this->createTestPlaceContentType();
3104
3105
        // Create a draft to account for behaviour with ContentType in different states
3106
        $repository = $this->getRepository();
3107
        $contentTypeService = $repository->getContentTypeService();
3108
        $contentService = $repository->getContentService();
3109
        $contentTypeService->createContentTypeDraft($contentType);
3110
3111
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3112
        $createStruct->alwaysAvailable = false;
3113
        $createStruct->mainLanguageCode = 'eng-GB';
3114
        $createStruct->setField(
3115
            'maplocation',
3116
            [
3117
                'latitude' => 45.894877,
3118
                'longitude' => 15.972699,
3119
                'address' => 'Here be wild boars',
3120
            ],
3121
            'eng-GB'
3122
        );
3123
3124
        $draft = $contentService->createContent($createStruct);
3125
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
3126
3127
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3128
        $createStruct->alwaysAvailable = false;
3129
        $createStruct->mainLanguageCode = 'eng-GB';
3130
        $createStruct->setField(
3131
            'maplocation',
3132
            [
3133
                'latitude' => 45.927334,
3134
                'longitude' => 15.934847,
3135
                'address' => 'A lone tree',
3136
            ],
3137
            'eng-GB'
3138
        );
3139
3140
        $draft = $contentService->createContent($createStruct);
3141
        $tree = $contentService->publishVersion($draft->getVersionInfo());
3142
3143
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
3144
        $createStruct->alwaysAvailable = false;
3145
        $createStruct->mainLanguageCode = 'eng-GB';
3146
        $createStruct->setField(
3147
            'maplocation',
3148
            [
3149
                'latitude' => 45.903777,
3150
                'longitude' => 15.958788,
3151
                'address' => 'Meadow with mushrooms',
3152
            ],
3153
            'eng-GB'
3154
        );
3155
3156
        $draft = $contentService->createContent($createStruct);
3157
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
3158
3159
        $this->refreshSearch($repository);
3160
3161
        $well = [
3162
            'latitude' => 43.756825,
3163
            'longitude' => 15.775074,
3164
        ];
3165
3166
        $query = new Query(
3167
            [
3168
                'filter' => new Criterion\LogicalAnd(
3169
                    [
3170
                        new Criterion\ContentTypeId($contentType->id),
3171
                        new Criterion\MapLocationDistance(
3172
                            'maplocation',
3173
                            Criterion\Operator::GTE,
3174
                            235,
3175
                            $well['latitude'],
3176
                            $well['longitude']
3177
                        ),
3178
                    ]
3179
                ),
3180
                'offset' => 0,
3181
                'limit' => 10,
3182
                'sortClauses' => [
3183
                    new SortClause\MapLocationDistance(
3184
                        'testtype',
3185
                        'maplocation',
3186
                        $well['latitude'],
3187
                        $well['longitude'],
3188
                        Query::SORT_DESC
3189
                    ),
3190
                ],
3191
            ]
3192
        );
3193
3194
        $searchService = $repository->getSearchService();
3195
        $result = $searchService->findContent($query);
3196
3197
        $this->assertEquals(3, $result->totalCount);
3198
        $this->assertEquals(
3199
            $wildBoars->id,
3200
            $result->searchHits[2]->valueObject->id
3201
        );
3202
        $this->assertEquals(
3203
            $mushrooms->id,
3204
            $result->searchHits[1]->valueObject->id
3205
        );
3206
        $this->assertEquals(
3207
            $tree->id,
3208
            $result->searchHits[0]->valueObject->id
3209
        );
3210
    }
3211
3212
    /**
3213
     * Test for the findContent() method.