Code Duplication    Length = 73-73 lines in 2 locations

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

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