Code Duplication    Length = 111-111 lines in 2 locations

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

@@ 746-856 (lines=111) @@
743
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
744
     * @group maplocation
745
     */
746
    public function testMapLocationDistanceSortAscending()
747
    {
748
        $contentType = $this->createTestPlaceContentType();
749
750
        // Create a draft to account for behaviour with ContentType in different states
751
        $repository = $this->getRepository();
752
        $contentTypeService = $repository->getContentTypeService();
753
        $contentService = $repository->getContentService();
754
        $contentTypeService->createContentTypeDraft($contentType);
755
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
756
757
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
758
        $createStruct->alwaysAvailable = false;
759
        $createStruct->mainLanguageCode = 'eng-GB';
760
        $createStruct->setField(
761
            'maplocation',
762
            [
763
                'latitude' => 45.894877,
764
                'longitude' => 15.972699,
765
                'address' => 'Here be wild boars',
766
            ],
767
            'eng-GB'
768
        );
769
770
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
771
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
772
773
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
774
        $createStruct->alwaysAvailable = false;
775
        $createStruct->mainLanguageCode = 'eng-GB';
776
        $createStruct->setField(
777
            'maplocation',
778
            [
779
                'latitude' => 45.927334,
780
                'longitude' => 15.934847,
781
                'address' => 'A lone tree',
782
            ],
783
            'eng-GB'
784
        );
785
786
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
787
        $tree = $contentService->publishVersion($draft->getVersionInfo());
788
789
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
790
        $createStruct->alwaysAvailable = false;
791
        $createStruct->mainLanguageCode = 'eng-GB';
792
        $createStruct->setField(
793
            'maplocation',
794
            [
795
                'latitude' => 45.903777,
796
                'longitude' => 15.958788,
797
                'address' => 'Meadow with mushrooms',
798
            ],
799
            'eng-GB'
800
        );
801
802
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
803
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
804
805
        $this->refreshSearch($repository);
806
807
        $wellInVodice = [
808
            'latitude' => 43.756825,
809
            'longitude' => 15.775074,
810
        ];
811
812
        $query = new LocationQuery(
813
            [
814
                'filter' => new Criterion\LogicalAnd(
815
                    [
816
                        new Criterion\ContentTypeId($contentType->id),
817
                        new Criterion\MapLocationDistance(
818
                            'maplocation',
819
                            Criterion\Operator::GTE,
820
                            235,
821
                            $wellInVodice['latitude'],
822
                            $wellInVodice['longitude']
823
                        ),
824
                    ]
825
                ),
826
                'offset' => 0,
827
                'limit' => 10,
828
                'sortClauses' => [
829
                    new SortClause\MapLocationDistance(
830
                        'testtype',
831
                        'maplocation',
832
                        $wellInVodice['latitude'],
833
                        $wellInVodice['longitude'],
834
                        LocationQuery::SORT_ASC
835
                    ),
836
                ],
837
            ]
838
        );
839
840
        $searchService = $repository->getSearchService();
841
        $result = $searchService->findLocations($query);
842
843
        $this->assertEquals(3, $result->totalCount);
844
        $this->assertEquals(
845
            $wildBoars->contentInfo->mainLocationId,
846
            $result->searchHits[0]->valueObject->id
847
        );
848
        $this->assertEquals(
849
            $mushrooms->contentInfo->mainLocationId,
850
            $result->searchHits[1]->valueObject->id
851
        );
852
        $this->assertEquals(
853
            $tree->contentInfo->mainLocationId,
854
            $result->searchHits[2]->valueObject->id
855
        );
856
    }
857
858
    /**
859
     * Test for the findLocations() method.
@@ 864-974 (lines=111) @@
861
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
862
     * @group maplocation
863
     */
864
    public function testMapLocationDistanceSortDescending()
865
    {
866
        $contentType = $this->createTestPlaceContentType();
867
868
        // Create a draft to account for behaviour with ContentType in different states
869
        $repository = $this->getRepository();
870
        $contentTypeService = $repository->getContentTypeService();
871
        $contentService = $repository->getContentService();
872
        $contentTypeService->createContentTypeDraft($contentType);
873
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
874
875
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
876
        $createStruct->alwaysAvailable = false;
877
        $createStruct->mainLanguageCode = 'eng-GB';
878
        $createStruct->setField(
879
            'maplocation',
880
            [
881
                'latitude' => 45.894877,
882
                'longitude' => 15.972699,
883
                'address' => 'Here be wild boars',
884
            ],
885
            'eng-GB'
886
        );
887
888
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
889
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
890
891
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
892
        $createStruct->alwaysAvailable = false;
893
        $createStruct->mainLanguageCode = 'eng-GB';
894
        $createStruct->setField(
895
            'maplocation',
896
            [
897
                'latitude' => 45.927334,
898
                'longitude' => 15.934847,
899
                'address' => 'A lone tree',
900
            ],
901
            'eng-GB'
902
        );
903
904
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
905
        $tree = $contentService->publishVersion($draft->getVersionInfo());
906
907
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
908
        $createStruct->alwaysAvailable = false;
909
        $createStruct->mainLanguageCode = 'eng-GB';
910
        $createStruct->setField(
911
            'maplocation',
912
            [
913
                'latitude' => 45.903777,
914
                'longitude' => 15.958788,
915
                'address' => 'Meadow with mushrooms',
916
            ],
917
            'eng-GB'
918
        );
919
920
        $draft = $contentService->createContent($createStruct, [$locationCreateStruct]);
921
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
922
923
        $this->refreshSearch($repository);
924
925
        $well = [
926
            'latitude' => 43.756825,
927
            'longitude' => 15.775074,
928
        ];
929
930
        $query = new LocationQuery(
931
            [
932
                'filter' => new Criterion\LogicalAnd(
933
                    [
934
                        new Criterion\ContentTypeId($contentType->id),
935
                        new Criterion\MapLocationDistance(
936
                            'maplocation',
937
                            Criterion\Operator::GTE,
938
                            235,
939
                            $well['latitude'],
940
                            $well['longitude']
941
                        ),
942
                    ]
943
                ),
944
                'offset' => 0,
945
                'limit' => 10,
946
                'sortClauses' => [
947
                    new SortClause\MapLocationDistance(
948
                        'testtype',
949
                        'maplocation',
950
                        $well['latitude'],
951
                        $well['longitude'],
952
                        LocationQuery::SORT_DESC
953
                    ),
954
                ],
955
            ]
956
        );
957
958
        $searchService = $repository->getSearchService();
959
        $result = $searchService->findLocations($query);
960
961
        $this->assertEquals(3, $result->totalCount);
962
        $this->assertEquals(
963
            $wildBoars->contentInfo->mainLocationId,
964
            $result->searchHits[2]->valueObject->id
965
        );
966
        $this->assertEquals(
967
            $mushrooms->contentInfo->mainLocationId,
968
            $result->searchHits[1]->valueObject->id
969
        );
970
        $this->assertEquals(
971
            $tree->contentInfo->mainLocationId,
972
            $result->searchHits[0]->valueObject->id
973
        );
974
    }
975
976
    /**
977
     * Test for the findLocations() method.