Code Duplication    Length = 74-74 lines in 2 locations

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

@@ 346-419 (lines=74) @@
343
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
344
     * @group maplocation
345
     */
346
    public function testMapLocationDistanceLessThanOrEqual()
347
    {
348
        $contentType = $this->createTestPlaceContentType();
349
350
        // Create a draft to account for behaviour with ContentType in different states
351
        $repository = $this->getRepository();
352
        $contentTypeService = $repository->getContentTypeService();
353
        $contentService = $repository->getContentService();
354
        $contentTypeService->createContentTypeDraft($contentType);
355
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
356
357
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
358
        $createStruct->alwaysAvailable = false;
359
        $createStruct->mainLanguageCode = 'eng-GB';
360
        $createStruct->setField(
361
            'maplocation',
362
            array(
363
                'latitude' => 45.894877,
364
                'longitude' => 15.972699,
365
                'address' => 'Here be wild boars',
366
            ),
367
            'eng-GB'
368
        );
369
370
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
371
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
372
373
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
374
        $createStruct->alwaysAvailable = false;
375
        $createStruct->mainLanguageCode = 'eng-GB';
376
        $createStruct->setField(
377
            'maplocation',
378
            array(
379
                'latitude' => 45.927334,
380
                'longitude' => 15.934847,
381
                'address' => 'A lone tree',
382
            ),
383
            'eng-GB'
384
        );
385
386
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
387
        $tree = $contentService->publishVersion($draft->getVersionInfo());
388
389
        $this->refreshSearch($repository);
390
391
        $query = new LocationQuery(
392
            array(
393
                'filter' => new Criterion\LogicalAnd(
394
                    array(
395
                        new Criterion\ContentTypeId($contentType->id),
396
                        new Criterion\MapLocationDistance(
397
                            'maplocation',
398
                            Criterion\Operator::LTE,
399
                            240,
400
                            43.756825,
401
                            15.775074
402
                        ),
403
                    )
404
                ),
405
                'offset' => 0,
406
                'limit' => 10,
407
                'sortClauses' => array(),
408
            )
409
        );
410
411
        $searchService = $repository->getSearchService();
412
        $result = $searchService->findLocations($query);
413
414
        $this->assertEquals(1, $result->totalCount);
415
        $this->assertEquals(
416
            $wildBoars->contentInfo->mainLocationId,
417
            $result->searchHits[0]->valueObject->id
418
        );
419
    }
420
421
    /**
422
     * Test for the findLocations() method.
@@ 427-500 (lines=74) @@
424
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
425
     * @group maplocation
426
     */
427
    public function testMapLocationDistanceGreaterThanOrEqual()
428
    {
429
        $contentType = $this->createTestPlaceContentType();
430
431
        // Create a draft to account for behaviour with ContentType in different states
432
        $repository = $this->getRepository();
433
        $contentTypeService = $repository->getContentTypeService();
434
        $contentService = $repository->getContentService();
435
        $contentTypeService->createContentTypeDraft($contentType);
436
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
437
438
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
439
        $createStruct->alwaysAvailable = false;
440
        $createStruct->mainLanguageCode = 'eng-GB';
441
        $createStruct->setField(
442
            'maplocation',
443
            array(
444
                'latitude' => 45.894877,
445
                'longitude' => 15.972699,
446
                'address' => 'Here be wild boars',
447
            ),
448
            'eng-GB'
449
        );
450
451
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
452
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
453
454
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
455
        $createStruct->alwaysAvailable = false;
456
        $createStruct->mainLanguageCode = 'eng-GB';
457
        $createStruct->setField(
458
            'maplocation',
459
            array(
460
                'latitude' => 45.927334,
461
                'longitude' => 15.934847,
462
                'address' => 'A lone tree',
463
            ),
464
            'eng-GB'
465
        );
466
467
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
468
        $tree = $contentService->publishVersion($draft->getVersionInfo());
469
470
        $this->refreshSearch($repository);
471
472
        $query = new LocationQuery(
473
            array(
474
                'filter' => new Criterion\LogicalAnd(
475
                    array(
476
                        new Criterion\ContentTypeId($contentType->id),
477
                        new Criterion\MapLocationDistance(
478
                            'maplocation',
479
                            Criterion\Operator::GTE,
480
                            240,
481
                            43.756825,
482
                            15.775074
483
                        ),
484
                    )
485
                ),
486
                'offset' => 0,
487
                'limit' => 10,
488
                'sortClauses' => array(),
489
            )
490
        );
491
492
        $searchService = $repository->getSearchService();
493
        $result = $searchService->findLocations($query);
494
495
        $this->assertEquals(1, $result->totalCount);
496
        $this->assertEquals(
497
            $tree->contentInfo->mainLocationId,
498
            $result->searchHits[0]->valueObject->id
499
        );
500
    }
501
502
    /**
503
     * Test for the findLocations() method.