public function testGetPreviewLocationNoLocation()
 {
     $contentId = 123;
     $contentInfo = $this->getMockBuilder('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo')->setConstructorArgs(array(array('id' => $contentId)))->getMockForAbstractClass();
     $this->contentService->expects($this->once())->method('loadContentInfo')->with($contentId)->will($this->returnValue($contentInfo));
     $this->locationHandler->expects($this->once())->method('loadParentLocationsForDraftContent')->with($contentId)->will($this->returnValue(array()));
     $this->locationHandler->expects($this->never())->method('loadLocation');
     $this->assertNull($this->provider->loadMainLocation($contentId));
 }
 /**
  * Extracts value object from $hit returned by Solr backend.
  *
  * @throws \RuntimeException If search $hit could not be handled
  *
  * @param mixed $hit
  *
  * @return \eZ\Publish\API\Repository\Values\ValueObject
  */
 public function extractHit($hit)
 {
     if ($hit->document_type_id === 'content') {
         return $this->contentHandler->loadContentInfo($hit->content_id);
     }
     if ($hit->document_type_id === 'location') {
         return $this->locationHandler->load($hit->location_id);
     }
     throw new RuntimeException("Could not extract: document of type '{$hit->document_type_id}' is not handled.");
 }
Beispiel #3
0
 /**
  *
  *
  * @throws \RuntimeException If search $hit could not be handled
  *
  * @param mixed $hit
  *
  * @return \eZ\Publish\API\Repository\Values\ValueObject
  */
 public function extractHit($hit)
 {
     if ($hit->_type === "content") {
         return $this->contentHandler->loadContentInfo($hit->_id);
     }
     if ($hit->_type === "location") {
         return $this->locationHandler->load($hit->_id);
     }
     throw new RuntimeException("Could not extract: document of type '{$hit->_type}' is not handled.");
 }
 /**
  * Creates an array of SPI location create structs from given array of API location create structs.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
  * @param \eZ\Publish\API\Repository\Values\Content\Location $parentLocation
  * @param mixed $mainLocation
  * @param mixed $contentId
  * @param mixed $contentVersionNo
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
  */
 public function buildSPILocationCreateStruct($locationCreateStruct, APILocation $parentLocation, $mainLocation, $contentId, $contentVersionNo)
 {
     if ($locationCreateStruct->priority !== null && !is_int($locationCreateStruct->priority)) {
         throw new InvalidArgumentValue('priority', $locationCreateStruct->priority, 'LocationCreateStruct');
     }
     if (!is_bool($locationCreateStruct->hidden)) {
         throw new InvalidArgumentValue('hidden', $locationCreateStruct->hidden, 'LocationCreateStruct');
     }
     if ($locationCreateStruct->remoteId !== null && (!is_string($locationCreateStruct->remoteId) || empty($locationCreateStruct->remoteId))) {
         throw new InvalidArgumentValue('remoteId', $locationCreateStruct->remoteId, 'LocationCreateStruct');
     }
     if ($locationCreateStruct->sortField !== null && !$this->isValidLocationSortField($locationCreateStruct->sortField)) {
         throw new InvalidArgumentValue('sortField', $locationCreateStruct->sortField, 'LocationCreateStruct');
     }
     if ($locationCreateStruct->sortOrder !== null && !$this->isValidLocationSortOrder($locationCreateStruct->sortOrder)) {
         throw new InvalidArgumentValue('sortOrder', $locationCreateStruct->sortOrder, 'LocationCreateStruct');
     }
     $remoteId = $locationCreateStruct->remoteId;
     if (null === $remoteId) {
         $remoteId = $this->getUniqueHash($locationCreateStruct);
     } else {
         try {
             $this->locationHandler->loadByRemoteId($remoteId);
             throw new InvalidArgumentException('$locationCreateStructs', "Another Location with remoteId '{$remoteId}' exists");
         } catch (NotFoundException $e) {
             // Do nothing
         }
     }
     return new SPILocationCreateStruct(array('priority' => $locationCreateStruct->priority, 'hidden' => $locationCreateStruct->hidden, 'invisible' => $locationCreateStruct->hidden === true || $parentLocation->invisible, 'remoteId' => $remoteId, 'contentId' => $contentId, 'contentVersion' => $contentVersionNo, 'pathIdentificationString' => null, 'mainLocationId' => $mainLocation, 'sortField' => $locationCreateStruct->sortField !== null ? $locationCreateStruct->sortField : Location::SORT_FIELD_NAME, 'sortOrder' => $locationCreateStruct->sortOrder !== null ? $locationCreateStruct->sortOrder : Location::SORT_ORDER_ASC, 'parentId' => $locationCreateStruct->parentLocationId));
 }
Beispiel #5
0
 /**
  * Finds Location objects for the given query.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationQuery $query
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
  */
 public function findLocations(LocationQuery $query)
 {
     $parameters = array("q" => 'document_type_id:"location" AND ' . $this->criterionVisitor->visit($query->query), "fq" => 'document_type_id:"location" AND ' . $this->criterionVisitor->visit($query->filter), "sort" => implode(", ", array_map(array($this->sortClauseVisitor, "visit"), $query->sortClauses)), "fl" => "*,score", "wt" => "json");
     if ($query->offset !== null) {
         $parameters["start"] = $query->offset;
     }
     if ($query->limit !== null) {
         $parameters["rows"] = $query->limit;
     }
     // @todo: Extract method
     $response = $this->client->request('GET', '/solr/select?' . http_build_query($parameters) . (count($query->facetBuilders) ? '&facet=true&facet.sort=count&' : '') . implode('&', array_map(array($this->facetBuilderVisitor, 'visit'), $query->facetBuilders)));
     // @todo: Error handling?
     $data = json_decode($response->body);
     if (!isset($data->response)) {
         throw new \Exception('->response not set: ' . var_export(array($data, $parameters), true));
     }
     // @todo: Extract method
     $result = new SearchResult(array('time' => $data->responseHeader->QTime / 1000, 'maxScore' => $data->response->maxScore, 'totalCount' => $data->response->numFound));
     foreach ($data->response->docs as $doc) {
         $searchHit = new SearchHit(array('score' => $doc->score, 'valueObject' => $this->locationHandler->load(substr($doc->id, 8))));
         $result->searchHits[] = $searchHit;
     }
     if (isset($data->facet_counts)) {
         foreach ($data->facet_counts->facet_fields as $field => $facet) {
             $result->facets[] = $this->facetBuilderVisitor->map($field, $facet);
         }
     }
     return $result;
 }
 /**
  * Creates an array of SPI location create structs from given array of API location create structs
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
  *
  * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $locationCreateStruct
  * @param \eZ\Publish\API\Repository\Values\Content\Location $parentLocation
  * @param mixed $mainLocation
  * @param mixed $contentId
  * @param mixed $contentVersionNo
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct
  */
 public function buildSPILocationCreateStruct($locationCreateStruct, APILocation $parentLocation, $mainLocation, $contentId, $contentVersionNo)
 {
     if ($locationCreateStruct->priority !== null && !is_int($locationCreateStruct->priority)) {
         throw new InvalidArgumentValue("priority", $locationCreateStruct->priority, "LocationCreateStruct");
     }
     if (!is_bool($locationCreateStruct->hidden)) {
         throw new InvalidArgumentValue("hidden", $locationCreateStruct->hidden, "LocationCreateStruct");
     }
     if ($locationCreateStruct->remoteId !== null && (!is_string($locationCreateStruct->remoteId) || empty($locationCreateStruct->remoteId))) {
         throw new InvalidArgumentValue("remoteId", $locationCreateStruct->remoteId, "LocationCreateStruct");
     }
     if ($locationCreateStruct->sortField !== null && !$this->isValidLocationSortField($locationCreateStruct->sortField)) {
         throw new InvalidArgumentValue("sortField", $locationCreateStruct->sortField, "LocationCreateStruct");
     }
     if ($locationCreateStruct->sortOrder !== null && !$this->isValidLocationSortOrder($locationCreateStruct->sortOrder)) {
         throw new InvalidArgumentValue("sortOrder", $locationCreateStruct->sortOrder, "LocationCreateStruct");
     }
     $remoteId = $locationCreateStruct->remoteId;
     if (null === $remoteId) {
         $remoteId = $this->getUniqueHash($locationCreateStruct);
     } else {
         try {
             $this->locationHandler->loadByRemoteId($remoteId);
             throw new InvalidArgumentException("\$locationCreateStructs", "Another Location with remoteId '{$remoteId}' exists");
         } catch (NotFoundException $e) {
             // Do nothing
         }
     }
     return new SPILocationCreateStruct(array("priority" => $locationCreateStruct->priority, "hidden" => $locationCreateStruct->hidden, "invisible" => $locationCreateStruct->hidden === true || $parentLocation->invisible, "remoteId" => $remoteId, "contentId" => $contentId, "contentVersion" => $contentVersionNo, "pathIdentificationString" => null, "mainLocationId" => $mainLocation, "sortField" => $locationCreateStruct->sortField !== null ? $locationCreateStruct->sortField : Location::SORT_FIELD_NAME, "sortOrder" => $locationCreateStruct->sortOrder !== null ? $locationCreateStruct->sortOrder : Location::SORT_ORDER_ASC, "parentId" => $locationCreateStruct->parentLocationId));
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(ParentContentTypeLimitation $limitation, ValueObject $object, $targets, array $persistence, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     // ContentTypeHandler is never used in evaluate()
     $persistenceMock->expects($this->never())->method('contentTypeHandler');
     if (empty($persistence)) {
         // Covers API targets, where no additional loading is required
         $persistenceMock->expects($this->never())->method($this->anything());
     } elseif (!empty($targets)) {
         foreach ($targets as $index => $target) {
             if ($target instanceof LocationCreateStruct) {
                 $this->getPersistenceMock()->expects($this->once($index))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
                 $this->locationHandlerMock->expects($this->at($index))->method('load')->with($target->parentLocationId)->will($this->returnValue($location = $persistence['locations'][$index]));
                 $contentId = $location->contentId;
             } else {
                 $contentId = $target->contentId;
             }
             $this->assertContentHandlerExpectations($index, $target instanceof LocationCreateStruct, $contentId, $persistence['contentInfos'][$index]);
         }
     } else {
         $this->getPersistenceMock()->expects($this->at(0))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? 'loadLocationsByContent' : 'loadParentLocationsForDraftContent')->with($object->id)->will($this->returnValue($persistence['locations']));
         foreach ($persistence['locations'] as $index => $location) {
             $this->assertContentHandlerExpectations($index, true, $location->contentId, $persistence['contentInfos'][$index]);
         }
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertInternalType('boolean', $value);
     self::assertEquals($expected, $value);
 }
 /**
  * Clear all content persistence cache, or by locationIds (legacy content/cache mechanism is location based).
  *
  * Either way all location and urlAlias cache is cleared as well.
  *
  * @param int|int[]|null $locationIds Ids of location we need to purge content cache for. Purges all content cache if null
  *
  * @return array|int|\int[]|null
  *
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType On invalid $id type
  */
 public function content($locationIds = null)
 {
     if ($this->allCleared === true || $this->enabled === false) {
         return;
     }
     if ($locationIds === null) {
         $this->cache->clear('content');
         goto relatedCache;
     } else {
         if (!is_array($locationIds)) {
             $locationIds = array($locationIds);
         }
     }
     foreach ($locationIds as $id) {
         if (!is_scalar($id)) {
             throw new InvalidArgumentType("\$id", "int[]|null", $id);
         }
         try {
             $location = $this->locationHandler->load($id);
             $this->cache->clear('content', $location->contentId);
             $this->cache->clear('content', 'info', $location->contentId);
             $this->cache->clear('content', 'info', 'remoteId');
             $this->cache->clear('content', 'locations', $location->contentId);
             $this->cache->clear('user', 'role', 'assignments', 'byGroup', $location->contentId);
             $this->cache->clear('user', 'role', 'assignments', 'byGroup', 'inherited', $location->contentId);
         } catch (NotFoundException $e) {
             $this->logger->notice("Unable to load the location with the id '{$id}' to clear its cache");
         }
     }
     // clear content related cache as well
     relatedCache:
     $this->cache->clear('urlAlias');
     $this->cache->clear('location');
     return $locationIds;
 }
    /**
     * Returns Content ids of all ancestor Locations of all Locations
     * of a Content with given $contentId.
     *
     * Used to determine user groups of a user with $contentId.
     *
     * @param int|string $contentId
     *
     * @return array
     */
    protected function getAncestorLocationsContentIds( $contentId )
    {
        $locations = $this->locationHandler->loadLocationsByContent( $contentId );
        $ancestorLocationContentIds = array();
        $ancestorLocationIds = array();

        foreach ( $locations as $location )
        {
            $locationIds = explode( "/", trim( $location->pathString, "/" ) );
            // Remove Location of Content with $contentId
            array_pop( $locationIds );
            // Remove Root Location id (id==1 in legacy DB)
            array_shift( $locationIds );

            $ancestorLocationIds = array_merge( $ancestorLocationIds, $locationIds );
        }

        foreach ( array_unique( $ancestorLocationIds ) as $locationId )
        {
            $location = $this->locationHandler->load( $locationId );

            $ancestorLocationContentIds[$location->contentId] = true;
        }

        return array_keys( $ancestorLocationContentIds );
    }
 /**
  * Loads the main location for $contentId.
  *
  * If the content does not have a location (yet), but has a Location draft, it is returned instead.
  * Location drafts do not have an id (it is set to null), and can be tested using the isDraft() method.
  *
  * If the content doesn't have a location nor a location draft, null is returned.
  *
  * @param mixed $contentId
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location|null
  */
 public function loadMainLocation($contentId)
 {
     $location = null;
     $contentInfo = $this->contentService->loadContentInfo($contentId);
     // mainLocationId already exists, content has been published at least once.
     if ($contentInfo->mainLocationId) {
         $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
     } elseif (!$contentInfo->published) {
         // New Content, never published, create a virtual location object.
         // In cases content is missing locations this will return empty array
         $parentLocations = $this->locationHandler->loadParentLocationsForDraftContent($contentInfo->id);
         if (empty($parentLocations)) {
             return null;
         }
         $location = new Location(array('contentInfo' => $contentInfo, 'status' => Location::STATUS_DRAFT, 'parentLocationId' => $parentLocations[0]->id, 'depth' => $parentLocations[0]->depth + 1, 'pathString' => $parentLocations[0]->pathString . '/x'));
     }
     return $location;
 }
 /**
  * Loads the main location for $contentId
  *
  * If the content does not have a location (yet), but has a Location draft, it is returned instead.
  * Location drafts do not have an id (it is set to null), and can be tested using the isDraft() method.
  *
  * If the content doesn't have a location nor a location draft, null is returned.
  *
  * @param mixed $contentInfo
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Location|null
  */
 public function loadMainLocation($contentId)
 {
     $contentInfo = $this->contentService->loadContentInfo($contentId);
     // mainLocationId already exists, content has been published at least once.
     if ($contentInfo->mainLocationId) {
         $location = $this->locationService->loadLocation($contentInfo->mainLocationId);
     } else {
         // @todo In future releases this will be a full draft location when this feature
         // is implemented. Or it might return null when content does not have location,
         // but for now we can't detect that so we return a virtual draft location
         $parentLocations = $this->locationHandler->loadParentLocationsForDraftContent($contentInfo->id);
         if (count($parentLocations) === 0) {
             return null;
         }
         $location = new Location(array('contentInfo' => $contentInfo, 'status' => Location::STATUS_DRAFT, 'parentLocationId' => $parentLocations[0]->id, 'depth' => $parentLocations[0]->depth + 1));
     }
     return $location;
 }
Beispiel #12
0
 /**
  * Map content to document.
  *
  * A document is an array of fields
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  *
  * @return array
  */
 protected function mapContent(Content $content)
 {
     $locations = $this->locationHandler->loadLocationsByContent($content->versionInfo->contentInfo->id);
     $mainLocation = null;
     foreach ($locations as $location) {
         if ($location->id == $content->versionInfo->contentInfo->mainLocationId) {
             $mainLocation = $location;
         }
     }
     $section = $this->sectionHandler->load($content->versionInfo->contentInfo->sectionId);
     $document = array(new Field('id', $content->versionInfo->contentInfo->id, new FieldType\IdentifierField()), new Field('type', $content->versionInfo->contentInfo->contentTypeId, new FieldType\IdentifierField()), new Field('version', $content->versionInfo->versionNo, new FieldType\IdentifierField()), new Field('status', $content->versionInfo->status, new FieldType\IdentifierField()), new Field('name', $content->versionInfo->contentInfo->name, new FieldType\StringField()), new Field('creator', $content->versionInfo->creatorId, new FieldType\IdentifierField()), new Field('owner', $content->versionInfo->contentInfo->ownerId, new FieldType\IdentifierField()), new Field('section', $content->versionInfo->contentInfo->sectionId, new FieldType\IdentifierField()), new Field('section_identifier', $section->identifier, new FieldType\IdentifierField()), new Field('section_name', $section->name, new FieldType\StringField()), new Field('remote_id', $content->versionInfo->contentInfo->remoteId, new FieldType\IdentifierField()), new Field('modified', $content->versionInfo->contentInfo->modificationDate, new FieldType\DateField()), new Field('published', $content->versionInfo->contentInfo->publicationDate, new FieldType\DateField()), new Field('path', array_map(function ($location) {
         return $location->pathString;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('location', array_map(function ($location) {
         return $location->id;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('depth', array_map(function ($location) {
         return $location->depth;
     }, $locations), new FieldType\IntegerField()), new Field('priority', array_map(function ($location) {
         return $location->priority;
     }, $locations), new FieldType\IntegerField()), new Field('location_parent', array_map(function ($location) {
         return $location->parentId;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('location_remote_id', array_map(function ($location) {
         return $location->remoteId;
     }, $locations), new FieldType\MultipleIdentifierField()), new Field('language_code', array_keys($content->versionInfo->names), new FieldType\MultipleStringField()), new Field('main_language_code', $content->versionInfo->contentInfo->mainLanguageCode, new FieldType\StringField()), new Field('invisible', array_map(function ($location) {
         return $location->invisible;
     }, $locations), new FieldType\MultipleBooleanField()), new Field('always_available', $content->versionInfo->contentInfo->alwaysAvailable, new FieldType\BooleanField()));
     if ($mainLocation !== null) {
         $document[] = new Field('main_location', $mainLocation->id, new FieldType\IdentifierField());
         $document[] = new Field('main_location_parent', $mainLocation->parentId, new FieldType\IdentifierField());
         $document[] = new Field('main_location_remote_id', $mainLocation->remoteId, new FieldType\IdentifierField());
         $document[] = new Field('main_path', $mainLocation->pathString, new FieldType\IdentifierField());
         $document[] = new Field('main_depth', $mainLocation->depth, new FieldType\IntegerField());
         $document[] = new Field('main_priority', $mainLocation->priority, new FieldType\IntegerField());
     }
     $contentType = $this->contentTypeHandler->load($content->versionInfo->contentInfo->contentTypeId);
     $document[] = new Field('group', $contentType->groupIds, new FieldType\MultipleIdentifierField());
     foreach ($content->fields as $field) {
         foreach ($contentType->fieldDefinitions as $fieldDefinition) {
             if ($fieldDefinition->id !== $field->fieldDefinitionId) {
                 continue;
             }
             $fieldType = $this->fieldRegistry->getType($field->type);
             foreach ($fieldType->getIndexData($field) as $indexField) {
                 $document[] = new Field($this->fieldNameGenerator->getName($indexField->name, $fieldDefinition->identifier, $contentType->identifier), $indexField->value, $indexField->type);
             }
         }
     }
     $objectStateIds = array();
     foreach ($this->objectStateHandler->loadAllGroups() as $objectStateGroup) {
         $objectStateIds[] = $this->objectStateHandler->getContentState($content->versionInfo->contentInfo->id, $objectStateGroup->id)->id;
     }
     $document[] = new Field('object_state', $objectStateIds, new FieldType\MultipleIdentifierField());
     return $document;
 }
 public function mapFields(Content $content)
 {
     $locations = $this->locationHandler->loadLocationsByContent($content->versionInfo->contentInfo->id);
     $mainLocation = null;
     $isSomeLocationVisible = false;
     $locationData = [];
     $fields = [];
     foreach ($locations as $location) {
         $locationData['ids'][] = $location->id;
         $locationData['parent_ids'][] = $location->parentId;
         $locationData['remote_ids'][] = $location->remoteId;
         $locationData['path_strings'][] = $location->pathString;
         if ($location->id == $content->versionInfo->contentInfo->mainLocationId) {
             $mainLocation = $location;
         }
         if (!$location->hidden && !$location->invisible) {
             $isSomeLocationVisible = true;
         }
     }
     if (!empty($locationData)) {
         $fields[] = new Field('location_id', $locationData['ids'], new FieldType\MultipleIdentifierField());
         $fields[] = new Field('location_parent_id', $locationData['parent_ids'], new FieldType\MultipleIdentifierField());
         $fields[] = new Field('location_remote_id', $locationData['remote_ids'], new FieldType\MultipleIdentifierField());
         $fields[] = new Field('location_path_string', $locationData['path_strings'], new FieldType\MultipleIdentifierField());
     }
     if ($mainLocation !== null) {
         $fields[] = new Field('main_location', $mainLocation->id, new FieldType\IdentifierField());
         $fields[] = new Field('main_location_parent', $mainLocation->parentId, new FieldType\IdentifierField());
         $fields[] = new Field('main_location_remote_id', $mainLocation->remoteId, new FieldType\IdentifierField());
         $fields[] = new Field('main_location_visible', !$mainLocation->hidden && !$mainLocation->invisible, new FieldType\BooleanField());
         $fields[] = new Field('main_location_path', $mainLocation->pathString, new FieldType\IdentifierField());
         $fields[] = new Field('main_location_depth', $mainLocation->depth, new FieldType\IntegerField());
         $fields[] = new Field('main_location_priority', $mainLocation->priority, new FieldType\IntegerField());
     }
     $fields[] = new Field('location_visible', $isSomeLocationVisible, new FieldType\BooleanField());
     return $fields;
 }
 /**
  * Maps given Content to a Document.
  *
  * @param \eZ\Publish\SPI\Persistence\Content $content
  *
  * @return \eZ\Publish\SPI\Search\Document[]
  */
 public function mapContentBlock(Content $content)
 {
     $contentInfo = $content->versionInfo->contentInfo;
     $locations = $this->locationHandler->loadLocationsByContent($contentInfo->id);
     $blockFields = $this->getBlockFields($content);
     $contentFields = $this->getContentFields($content);
     $documents = [];
     $locationFieldsMap = [];
     foreach ($locations as $location) {
         $locationFieldsMap[$location->id] = $this->getLocationFields($location);
     }
     foreach (array_keys($content->versionInfo->names) as $languageCode) {
         $blockTranslationFields = $this->getBlockTranslationFields($content, $languageCode);
         $translationLocationDocuments = array();
         foreach ($locations as $location) {
             $translationLocationDocuments[] = new Document(array('id' => $this->generateLocationDocumentId($location->id, $languageCode), 'fields' => array_merge($blockFields, $locationFieldsMap[$location->id], $blockTranslationFields)));
         }
         $isMainTranslation = $contentInfo->mainLanguageCode === $languageCode;
         $alwaysAvailable = $isMainTranslation && $contentInfo->alwaysAvailable;
         $contentTranslationFields = $this->getContentTranslationFields($content, $languageCode);
         $documents[] = new Document(array('id' => $this->generateContentDocumentId($contentInfo->id, $languageCode), 'languageCode' => $languageCode, 'alwaysAvailable' => $alwaysAvailable, 'isMainTranslation' => $isMainTranslation, 'fields' => array_merge($blockFields, $contentFields, $blockTranslationFields, $contentTranslationFields), 'documents' => $translationLocationDocuments));
     }
     return $documents;
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(LocationLimitation $limitation, ValueObject $object, $targets, array $persistenceLocations, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     if (empty($persistenceLocations) && $targets !== null) {
         $persistenceMock->expects($this->never())->method($this->anything());
     } else {
         $this->getPersistenceMock()->expects($this->once())->method("locationHandler")->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? "loadLocationsByContent" : "loadParentLocationsForDraftContent")->with($object->id)->will($this->returnValue($persistenceLocations));
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertInternalType('boolean', $value);
     self::assertEquals($expected, $value);
 }
 /**
  * @dataProvider providerForTestEvaluate
  */
 public function testEvaluate(SubtreeLimitation $limitation, ValueObject $object, $targets, array $persistenceLocations, $expected)
 {
     // Need to create inline instead of depending on testConstruct() to get correct mock instance
     $limitationType = $this->testConstruct();
     $userMock = $this->getUserMock();
     $userMock->expects($this->never())->method($this->anything());
     $persistenceMock = $this->getPersistenceMock();
     if (empty($persistenceLocations) && $targets !== null) {
         $persistenceMock->expects($this->never())->method($this->anything());
     } elseif ($object instanceof ContentCreateStruct) {
         foreach ((array) $targets as $key => $target) {
             $this->getPersistenceMock()->expects($this->at($key))->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
             $this->locationHandlerMock->expects($this->at($key))->method('load')->with($target->parentLocationId)->will($this->returnValue($persistenceLocations[$key]));
         }
     } else {
         $this->getPersistenceMock()->expects($this->once())->method('locationHandler')->will($this->returnValue($this->locationHandlerMock));
         $this->locationHandlerMock->expects($this->once())->method($object instanceof ContentInfo && $object->published ? 'loadLocationsByContent' : 'loadParentLocationsForDraftContent')->with($object->id)->will($this->returnValue($persistenceLocations));
     }
     $value = $limitationType->evaluate($limitation, $userMock, $object, $targets);
     self::assertEquals($expected, $value);
 }