Code Duplication    Length = 111-111 lines in 2 locations

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

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