Code Duplication    Length = 73-73 lines in 2 locations

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

@@ 2656-2728 (lines=73) @@
2653
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2654
     * @group maplocation
2655
     */
2656
    public function testMapLocationDistanceLessThanOrEqual()
2657
    {
2658
        $contentType = $this->createTestPlaceContentType();
2659
2660
        // Create a draft to account for behaviour with ContentType in different states
2661
        $repository = $this->getRepository();
2662
        $contentTypeService = $repository->getContentTypeService();
2663
        $contentService = $repository->getContentService();
2664
        $contentTypeService->createContentTypeDraft($contentType);
2665
2666
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2667
        $createStruct->alwaysAvailable = false;
2668
        $createStruct->mainLanguageCode = 'eng-GB';
2669
        $createStruct->setField(
2670
            'maplocation',
2671
            [
2672
                'latitude' => 45.894877,
2673
                'longitude' => 15.972699,
2674
                'address' => 'Here be wild boars',
2675
            ],
2676
            'eng-GB'
2677
        );
2678
2679
        $draft = $contentService->createContent($createStruct);
2680
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2681
2682
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2683
        $createStruct->alwaysAvailable = false;
2684
        $createStruct->mainLanguageCode = 'eng-GB';
2685
        $createStruct->setField(
2686
            'maplocation',
2687
            [
2688
                'latitude' => 45.927334,
2689
                'longitude' => 15.934847,
2690
                'address' => 'A lone tree',
2691
            ],
2692
            'eng-GB'
2693
        );
2694
2695
        $draft = $contentService->createContent($createStruct);
2696
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2697
2698
        $this->refreshSearch($repository);
2699
2700
        $query = new Query(
2701
            [
2702
                'filter' => new Criterion\LogicalAnd(
2703
                    [
2704
                        new Criterion\ContentTypeId($contentType->id),
2705
                        new Criterion\MapLocationDistance(
2706
                            'maplocation',
2707
                            Criterion\Operator::LTE,
2708
                            240,
2709
                            43.756825,
2710
                            15.775074
2711
                        ),
2712
                    ]
2713
                ),
2714
                'offset' => 0,
2715
                'limit' => 10,
2716
                'sortClauses' => [],
2717
            ]
2718
        );
2719
2720
        $searchService = $repository->getSearchService();
2721
        $result = $searchService->findContent($query);
2722
2723
        $this->assertEquals(1, $result->totalCount);
2724
        $this->assertEquals(
2725
            $wildBoars->id,
2726
            $result->searchHits[0]->valueObject->id
2727
        );
2728
    }
2729
2730
    /**
2731
     * Test for the findContent() method.
@@ 2736-2808 (lines=73) @@
2733
     * @see \eZ\Publish\API\Repository\SearchService::findContent()
2734
     * @group maplocation
2735
     */
2736
    public function testMapLocationDistanceGreaterThanOrEqual()
2737
    {
2738
        $contentType = $this->createTestPlaceContentType();
2739
2740
        // Create a draft to account for behaviour with ContentType in different states
2741
        $repository = $this->getRepository();
2742
        $contentTypeService = $repository->getContentTypeService();
2743
        $contentService = $repository->getContentService();
2744
        $contentTypeService->createContentTypeDraft($contentType);
2745
2746
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2747
        $createStruct->alwaysAvailable = false;
2748
        $createStruct->mainLanguageCode = 'eng-GB';
2749
        $createStruct->setField(
2750
            'maplocation',
2751
            [
2752
                'latitude' => 45.894877,
2753
                'longitude' => 15.972699,
2754
                'address' => 'Here be wild boars',
2755
            ],
2756
            'eng-GB'
2757
        );
2758
2759
        $draft = $contentService->createContent($createStruct);
2760
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
2761
2762
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2763
        $createStruct->alwaysAvailable = false;
2764
        $createStruct->mainLanguageCode = 'eng-GB';
2765
        $createStruct->setField(
2766
            'maplocation',
2767
            [
2768
                'latitude' => 45.927334,
2769
                'longitude' => 15.934847,
2770
                'address' => 'A lone tree',
2771
            ],
2772
            'eng-GB'
2773
        );
2774
2775
        $draft = $contentService->createContent($createStruct);
2776
        $tree = $contentService->publishVersion($draft->getVersionInfo());
2777
2778
        $this->refreshSearch($repository);
2779
2780
        $query = new Query(
2781
            [
2782
                'filter' => new Criterion\LogicalAnd(
2783
                    [
2784
                        new Criterion\ContentTypeId($contentType->id),
2785
                        new Criterion\MapLocationDistance(
2786
                            'maplocation',
2787
                            Criterion\Operator::GTE,
2788
                            240,
2789
                            43.756825,
2790
                            15.775074
2791
                        ),
2792
                    ]
2793
                ),
2794
                'offset' => 0,
2795
                'limit' => 10,
2796
                'sortClauses' => [],
2797
            ]
2798
        );
2799
2800
        $searchService = $repository->getSearchService();
2801
        $result = $searchService->findContent($query);
2802
2803
        $this->assertEquals(1, $result->totalCount);
2804
        $this->assertEquals(
2805
            $tree->id,
2806
            $result->searchHits[0]->valueObject->id
2807
        );
2808
    }
2809
2810
    /**
2811
     * Test for the findContent() method.