Code Duplication    Length = 111-111 lines in 2 locations

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

@@ 605-715 (lines=111) @@
602
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
603
     * @group maplocation
604
     */
605
    public function testMapLocationDistanceSortAscending()
606
    {
607
        $contentType = $this->createTestPlaceContentType();
608
609
        // Create a draft to account for behaviour with ContentType in different states
610
        $repository = $this->getRepository();
611
        $contentTypeService = $repository->getContentTypeService();
612
        $contentService = $repository->getContentService();
613
        $contentTypeService->createContentTypeDraft($contentType);
614
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
615
616
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
617
        $createStruct->alwaysAvailable = false;
618
        $createStruct->mainLanguageCode = 'eng-GB';
619
        $createStruct->setField(
620
            'maplocation',
621
            array(
622
                'latitude' => 45.894877,
623
                'longitude' => 15.972699,
624
                'address' => 'Here be wild boars',
625
            ),
626
            'eng-GB'
627
        );
628
629
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
630
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
631
632
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
633
        $createStruct->alwaysAvailable = false;
634
        $createStruct->mainLanguageCode = 'eng-GB';
635
        $createStruct->setField(
636
            'maplocation',
637
            array(
638
                'latitude' => 45.927334,
639
                'longitude' => 15.934847,
640
                'address' => 'A lone tree',
641
            ),
642
            'eng-GB'
643
        );
644
645
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
646
        $tree = $contentService->publishVersion($draft->getVersionInfo());
647
648
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
649
        $createStruct->alwaysAvailable = false;
650
        $createStruct->mainLanguageCode = 'eng-GB';
651
        $createStruct->setField(
652
            'maplocation',
653
            array(
654
                'latitude' => 45.903777,
655
                'longitude' => 15.958788,
656
                'address' => 'Meadow with mushrooms',
657
            ),
658
            'eng-GB'
659
        );
660
661
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
662
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
663
664
        $this->refreshSearch($repository);
665
666
        $wellInVodice = array(
667
            'latitude' => 43.756825,
668
            'longitude' => 15.775074,
669
        );
670
671
        $query = new LocationQuery(
672
            array(
673
                'filter' => new Criterion\LogicalAnd(
674
                    array(
675
                        new Criterion\ContentTypeId($contentType->id),
676
                        new Criterion\MapLocationDistance(
677
                            'maplocation',
678
                            Criterion\Operator::GTE,
679
                            235,
680
                            $wellInVodice['latitude'],
681
                            $wellInVodice['longitude']
682
                        ),
683
                    )
684
                ),
685
                'offset' => 0,
686
                'limit' => 10,
687
                'sortClauses' => array(
688
                    new SortClause\MapLocationDistance(
689
                        'testtype',
690
                        'maplocation',
691
                        $wellInVodice['latitude'],
692
                        $wellInVodice['longitude'],
693
                        LocationQuery::SORT_ASC
694
                    ),
695
                ),
696
            )
697
        );
698
699
        $searchService = $repository->getSearchService();
700
        $result = $searchService->findLocations($query);
701
702
        $this->assertEquals(3, $result->totalCount);
703
        $this->assertEquals(
704
            $wildBoars->contentInfo->mainLocationId,
705
            $result->searchHits[0]->valueObject->id
706
        );
707
        $this->assertEquals(
708
            $mushrooms->contentInfo->mainLocationId,
709
            $result->searchHits[1]->valueObject->id
710
        );
711
        $this->assertEquals(
712
            $tree->contentInfo->mainLocationId,
713
            $result->searchHits[2]->valueObject->id
714
        );
715
    }
716
717
    /**
718
     * Test for the findLocations() method.
@@ 723-833 (lines=111) @@
720
     * @see \eZ\Publish\API\Repository\SearchService::findLocations()
721
     * @group maplocation
722
     */
723
    public function testMapLocationDistanceSortDescending()
724
    {
725
        $contentType = $this->createTestPlaceContentType();
726
727
        // Create a draft to account for behaviour with ContentType in different states
728
        $repository = $this->getRepository();
729
        $contentTypeService = $repository->getContentTypeService();
730
        $contentService = $repository->getContentService();
731
        $contentTypeService->createContentTypeDraft($contentType);
732
        $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2);
733
734
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
735
        $createStruct->alwaysAvailable = false;
736
        $createStruct->mainLanguageCode = 'eng-GB';
737
        $createStruct->setField(
738
            'maplocation',
739
            array(
740
                'latitude' => 45.894877,
741
                'longitude' => 15.972699,
742
                'address' => 'Here be wild boars',
743
            ),
744
            'eng-GB'
745
        );
746
747
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
748
        $wildBoars = $contentService->publishVersion($draft->getVersionInfo());
749
750
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
751
        $createStruct->alwaysAvailable = false;
752
        $createStruct->mainLanguageCode = 'eng-GB';
753
        $createStruct->setField(
754
            'maplocation',
755
            array(
756
                'latitude' => 45.927334,
757
                'longitude' => 15.934847,
758
                'address' => 'A lone tree',
759
            ),
760
            'eng-GB'
761
        );
762
763
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
764
        $tree = $contentService->publishVersion($draft->getVersionInfo());
765
766
        $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');
767
        $createStruct->alwaysAvailable = false;
768
        $createStruct->mainLanguageCode = 'eng-GB';
769
        $createStruct->setField(
770
            'maplocation',
771
            array(
772
                'latitude' => 45.903777,
773
                'longitude' => 15.958788,
774
                'address' => 'Meadow with mushrooms',
775
            ),
776
            'eng-GB'
777
        );
778
779
        $draft = $contentService->createContent($createStruct, array($locationCreateStruct));
780
        $mushrooms = $contentService->publishVersion($draft->getVersionInfo());
781
782
        $this->refreshSearch($repository);
783
784
        $well = array(
785
            'latitude' => 43.756825,
786
            'longitude' => 15.775074,
787
        );
788
789
        $query = new LocationQuery(
790
            array(
791
                'filter' => new Criterion\LogicalAnd(
792
                    array(
793
                        new Criterion\ContentTypeId($contentType->id),
794
                        new Criterion\MapLocationDistance(
795
                            'maplocation',
796
                            Criterion\Operator::GTE,
797
                            235,
798
                            $well['latitude'],
799
                            $well['longitude']
800
                        ),
801
                    )
802
                ),
803
                'offset' => 0,
804
                'limit' => 10,
805
                'sortClauses' => array(
806
                    new SortClause\MapLocationDistance(
807
                        'testtype',
808
                        'maplocation',
809
                        $well['latitude'],
810
                        $well['longitude'],
811
                        LocationQuery::SORT_DESC
812
                    ),
813
                ),
814
            )
815
        );
816
817
        $searchService = $repository->getSearchService();
818
        $result = $searchService->findLocations($query);
819
820
        $this->assertEquals(3, $result->totalCount);
821
        $this->assertEquals(
822
            $wildBoars->contentInfo->mainLocationId,
823
            $result->searchHits[2]->valueObject->id
824
        );
825
        $this->assertEquals(
826
            $mushrooms->contentInfo->mainLocationId,
827
            $result->searchHits[1]->valueObject->id
828
        );
829
        $this->assertEquals(
830
            $tree->contentInfo->mainLocationId,
831
            $result->searchHits[0]->valueObject->id
832
        );
833
    }
834
835
    /**
836
     * Test for the findLocations() method.