/** * @param Context $context * @return NodeInterface * @throws NodeTypeNotFoundException * @throws NodeConfigurationException */ public function findOrCreateMetaDataRootNode(Context $context) { if ($this->metaDataRootNode instanceof NodeInterface) { return $this->metaDataRootNode; } $metaDataRootNodeData = $this->metaDataRepository->findOneByPath('/' . MetaDataRepository::METADATA_ROOT_NODE_NAME, $context->getWorkspace()); if ($metaDataRootNodeData !== null) { $metaDataRootNode = $this->nodeFactory->createFromNodeData($metaDataRootNodeData, $context); return $metaDataRootNode; } $nodeTemplate = new NodeTemplate(); $nodeTemplate->setNodeType($this->nodeTypeManager->getNodeType('unstructured')); $nodeTemplate->setName(MetaDataRepository::METADATA_ROOT_NODE_NAME); $context = $this->contextFactory->create(['workspaceName' => 'live']); $rootNode = $context->getRootNode(); $this->metaDataRootNode = $rootNode->createNodeFromTemplate($nodeTemplate); $this->persistenceManager->persistAll(); return $this->metaDataRootNode; }
/** * @test */ public function nodeWithRelatedEntitiesWillTakeCareOfAddingToPersistence() { $identifier = Algorithms::generateUUID(); $template = new NodeTemplate(); $template->setName('new-node'); $template->setIdentifier($identifier); $newEntity = new Fixtures\RelatedEntity(); $newEntity->setFavoritePlace('Reykjavik'); $anotherNewEntity = new Fixtures\RelatedEntity(); $anotherNewEntity->setFavoritePlace('Japan'); $template->setProperty('entity', array($newEntity, $anotherNewEntity)); $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNodeFromTemplate($template); $this->persistenceManager->persistAll(); $this->persistenceManager->clearState(); $this->inject($this->contextFactory, 'contextInstances', array()); $newLiveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $newNodeAgain = $newLiveContext->getNode('/new-node'); $entityArray = $newNodeAgain->getProperty('entity'); $this->assertCount(2, $entityArray); $this->assertEquals('Japan', $entityArray[1]->getFavoritePlace()); }
/** * @param Dto\Asset $asset * @param NodeType $nodeType * @return NodeTemplate */ protected function createAssetNodeTemplate(Dto\Asset $asset, NodeType $nodeType) { $assetNodeTemplate = new NodeTemplate(); $assetNodeTemplate->setNodeType($nodeType); $assetNodeTemplate->setName($asset->getIdentifier()); return $assetNodeTemplate; }
/** * @test * @expectedException \InvalidArgumentException */ public function setNameWithInvalidNameThrowsException() { $nodeTemplate = new NodeTemplate(); $nodeTemplate->setName(',?/invalid-node-name'); }