/** * Test for the findContent() method. * * @see \eZ\Publish\API\Repository\SearchService::findContent() * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetSearchService * @group maplocation */ public function testMapLocationDistanceWithCustomField() { $setupFactory = $this->getSetupFactory(); if ( $setupFactory instanceof LegacyElasticsearch ) { $this->markTestIncomplete( "TODO: Some issues with 'copy_to' and 'geo_point'" ); } $contentType = $this->createTestPlaceContentType(); // Create a draft to account for behaviour with ContentType in different states $repository = $this->getRepository(); $contentTypeService = $repository->getContentTypeService(); $contentService = $repository->getContentService(); $contentTypeService->createContentTypeDraft( $contentType ); $createStruct = $contentService->newContentCreateStruct( $contentType, "eng-GB" ); $createStruct->alwaysAvailable = false; $createStruct->mainLanguageCode = "eng-GB"; $createStruct->setField( "maplocation", array( "latitude" => 45.894877, "longitude" => 15.972699, "address" => "Here be wild boars", ), "eng-GB" ); $draft = $contentService->createContent( $createStruct ); $wildBoars = $contentService->publishVersion( $draft->getVersionInfo() ); $createStruct = $contentService->newContentCreateStruct( $contentType, "eng-GB" ); $createStruct->alwaysAvailable = false; $createStruct->mainLanguageCode = "eng-GB"; $createStruct->setField( "maplocation", array( "latitude" => 45.927334, "longitude" => 15.934847, "address" => "A lone tree", ), "eng-GB" ); $draft = $contentService->createContent( $createStruct ); $tree = $contentService->publishVersion( $draft->getVersionInfo() ); $distanceCriterion = new Criterion\MapLocationDistance( "maplocation", Criterion\Operator::LTE, 240, 43.756825, 15.775074 ); $distanceCriterion->setCustomField( 'testtype', 'maplocation', 'custom_geolocation_field' ); $query = new Query( array( 'filter' => new Criterion\LogicalAnd( array( new Criterion\ContentTypeId( $contentType->id ), $distanceCriterion ) ), 'offset' => 0, 'limit' => 10, 'sortClauses' => array() ) ); $searchService = $repository->getSearchService(); $result = $searchService->findContent( $query ); $this->assertEquals( 1, $result->totalCount ); $this->assertEquals( $wildBoars->id, $result->searchHits[0]->valueObject->id ); }
/** * Test for the findLocations() method. * * @see \eZ\Publish\API\Repository\SearchService::findLocations() * @group maplocation */ public function testMapLocationDistanceWithCustomField() { $contentType = $this->createTestPlaceContentType(); // Create a draft to account for behaviour with ContentType in different states $repository = $this->getRepository(); $contentTypeService = $repository->getContentTypeService(); $contentService = $repository->getContentService(); $contentTypeService->createContentTypeDraft($contentType); $locationCreateStruct = $repository->getLocationService()->newLocationCreateStruct(2); $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); $createStruct->alwaysAvailable = false; $createStruct->mainLanguageCode = 'eng-GB'; $createStruct->setField('maplocation', array('latitude' => 45.894877, 'longitude' => 15.972699, 'address' => 'Here be wild boars'), 'eng-GB'); $draft = $contentService->createContent($createStruct, array($locationCreateStruct)); $wildBoars = $contentService->publishVersion($draft->getVersionInfo()); $createStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB'); $createStruct->alwaysAvailable = false; $createStruct->mainLanguageCode = 'eng-GB'; $createStruct->setField('maplocation', array('latitude' => 45.927334, 'longitude' => 15.934847, 'address' => 'A lone tree'), 'eng-GB'); $draft = $contentService->createContent($createStruct, array($locationCreateStruct)); $tree = $contentService->publishVersion($draft->getVersionInfo()); $this->refreshSearch($repository); $distanceCriterion = new Criterion\MapLocationDistance('maplocation', Criterion\Operator::LTE, 240, 43.756825, 15.775074); $distanceCriterion->setCustomField('testtype', 'maplocation', 'custom_geolocation_field'); $query = new LocationQuery(array('filter' => new Criterion\LogicalAnd(array(new Criterion\ContentTypeId($contentType->id), $distanceCriterion)), 'offset' => 0, 'limit' => 10, 'sortClauses' => array())); $searchService = $repository->getSearchService(); $result = $searchService->findLocations($query); $this->assertEquals(1, $result->totalCount); $this->assertEquals($wildBoars->contentInfo->mainLocationId, $result->searchHits[0]->valueObject->id); }