/** * @test */ public function similarizeClearsPropertiesBeforeAddingNewOnes() { /** @var $sourceNode NodeData */ $sourceNode = $this->getAccessibleMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', array('addOrUpdate'), array('/foo/bar', $this->mockWorkspace)); $this->inject($sourceNode, 'nodeTypeManager', $this->mockNodeTypeManager); $sourceNode->_set('nodeDataRepository', $this->createMock('TYPO3\\Flow\\Persistence\\RepositoryInterface')); $this->nodeData->setProperty('someProperty', 'somePropertyValue'); $this->nodeData->setProperty('someOtherProperty', 'someOtherPropertyValue'); $sourceNode->setProperty('newProperty', 'newPropertyValue'); $sourceNode->setProperty('someProperty', 'someOverriddenPropertyValue'); $this->nodeData->similarize($sourceNode); $expectedProperties = array('newProperty' => 'newPropertyValue', 'someProperty' => 'someOverriddenPropertyValue'); $this->assertEquals($expectedProperties, $this->nodeData->getProperties()); }
/** * For internal use in createRecursiveCopy. * * @param NodeInterface $sourceNode * @return void */ public function similarize(NodeInterface $sourceNode) { $this->nodeData->similarize($sourceNode->getNodeData()); }
/** * Create a shadow NodeData at the given path with the same workspace and dimensions as this * * Note: The constructor will already add the new object to the repository * * @param string $path The (original) path for the node data * @return NodeData */ public function createShadow($path) { $shadowNode = new NodeData($path, $this->workspace, $this->identifier, $this->dimensionValues); $shadowNode->similarize($this); $shadowNode->setAsShadowOf($this); return $shadowNode; }
/** * Given a context a new node is returned that is like this node, but * lives in the new context. * * @param Context $context * @return NodeInterface */ public function createVariantForContext($context) { $autoCreatedChildNodes = array(); $nodeType = $this->getNodeType(); foreach ($nodeType->getAutoCreatedChildNodes() as $childNodeName => $childNodeConfiguration) { $childNode = $this->getNode($childNodeName); if ($childNode !== null) { $autoCreatedChildNodes[$childNodeName] = $childNode; } } $nodeData = new NodeData($this->nodeData->getPath(), $context->getWorkspace(), $this->nodeData->getIdentifier(), $context->getTargetDimensionValues()); $nodeData->similarize($this->nodeData); if ($this->context !== $context) { $node = $this->nodeFactory->createFromNodeData($nodeData, $context); } else { $this->setNodeData($nodeData); $node = $this; } $this->context->getFirstLevelNodeCache()->flush(); $this->emitNodeAdded($node); /** * @var $autoCreatedChildNode NodeInterface */ foreach ($autoCreatedChildNodes as $autoCreatedChildNode) { $autoCreatedChildNode->createVariantForContext($context); } return $node; }