/**
  * Change the property on the given node.
  *
  * @param NodeData $node
  * @return NodeData
  */
 public function execute(NodeData $node)
 {
     $node = $this->nodeFactory->createFromNodeData($node, $this->nodeFactory->createContextMatchingNodeData($node));
     $column0 = $node->getPrimaryChildNode();
     $column0->setName('contents');
     return $node;
 }
 /**
  * @test
  */
 public function createContextMatchingNodeDataCreatesMatchingContext()
 {
     $dimensionValues = array('language' => array('is'));
     $workspaceName = 'some-workspace';
     $mockContext = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\Context', null, array(), '', false);
     $mockWorkspace = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace', array(), array(), 'MockWorkspace', false);
     $mockWorkspace->expects(self::any())->method('getName')->will(self::returnValue($workspaceName));
     $mockContextFactory = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface', array(), array(), '', false);
     $mockContextFactory->expects(self::once())->method('create')->with(array('workspaceName' => $workspaceName, 'invisibleContentShown' => true, 'inaccessibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensionValues))->willReturn($mockContext);
     $this->inject($this->nodeFactory, 'contextFactory', $mockContextFactory);
     $mockNodeData = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', array(), array(), '', false);
     $mockNodeData->expects(self::any())->method('getWorkspace')->will($this->returnValue($mockWorkspace));
     $mockNodeData->expects(self::any())->method('getDimensionValues')->willReturn($dimensionValues);
     $context = $this->nodeFactory->createContextMatchingNodeData($mockNodeData);
     self::assertEquals($mockContext, $context);
 }
 /**
  * @test
  */
 public function createContextMatchingNodeDataCreatesMatchingContext()
 {
     $dimensionValues = array('language' => array('is'));
     $workspaceName = 'some-workspace';
     $mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     $mockWorkspace = $this->getMockBuilder(Workspace::class)->setMockClassName('MockWorkspace')->disableOriginalConstructor()->getMock();
     $mockWorkspace->expects(self::any())->method('getName')->will(self::returnValue($workspaceName));
     $mockContextFactory = $this->createMock(ContextFactoryInterface::class);
     $mockContextFactory->expects(self::once())->method('create')->with(array('workspaceName' => $workspaceName, 'invisibleContentShown' => true, 'inaccessibleContentShown' => true, 'removedContentShown' => true, 'dimensions' => $dimensionValues))->willReturn($mockContext);
     $this->inject($this->nodeFactory, 'contextFactory', $mockContextFactory);
     $mockNodeData = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
     $mockNodeData->expects(self::any())->method('getWorkspace')->will($this->returnValue($mockWorkspace));
     $mockNodeData->expects(self::any())->method('getDimensionValues')->willReturn($dimensionValues);
     $context = $this->nodeFactory->createContextMatchingNodeData($mockNodeData);
     self::assertEquals($mockContext, $context);
 }
 /**
  * Reorder child nodes for the given node type
  *
  * @param NodeType $nodeType
  * @param string $workspaceName
  * @param boolean $dryRun
  * @return void
  */
 protected function reorderChildNodesByNodeType(NodeType $nodeType, $workspaceName, $dryRun)
 {
     $nodeTypes = $this->nodeTypeManager->getSubNodeTypes($nodeType->getName(), false);
     $nodeTypes[$nodeType->getName()] = $nodeType;
     if ($this->nodeTypeManager->hasNodeType((string) $nodeType)) {
         $nodeType = $this->nodeTypeManager->getNodeType((string) $nodeType);
         $nodeTypeNames[$nodeType->getName()] = $nodeType;
     } else {
         $this->output->outputLine('Node type "%s" does not exist', array((string) $nodeType));
         exit(1);
     }
     /** @var $nodeType NodeType */
     foreach ($nodeTypes as $nodeTypeName => $nodeType) {
         $childNodes = $nodeType->getAutoCreatedChildNodes();
         if ($childNodes === array()) {
             continue;
         }
         foreach ($this->getNodeDataByNodeTypeAndWorkspace($nodeTypeName, $workspaceName) as $nodeData) {
             /** @var NodeInterface $childNodeBefore */
             $childNodeBefore = null;
             $context = $this->nodeFactory->createContextMatchingNodeData($nodeData);
             $node = $this->nodeFactory->createFromNodeData($nodeData, $context);
             if (!$node instanceof NodeInterface) {
                 continue;
             }
             foreach ($childNodes as $childNodeName => $childNodeType) {
                 $childNode = $node->getNode($childNodeName);
                 if ($childNode) {
                     if ($childNodeBefore) {
                         if ($dryRun === false) {
                             if ($childNodeBefore->getIndex() >= $childNode->getIndex()) {
                                 $childNode->moveAfter($childNodeBefore);
                                 $this->output->outputLine('Moved node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
                             }
                         } else {
                             $this->output->outputLine('Should move node named "%s" after node named "%s" in "%s"', array($childNodeName, $childNodeBefore->getName(), $node->getPath()));
                         }
                     }
                 } else {
                     $this->output->outputLine('Missing child node named "%s" in "%s".', array($childNodeName, $node->getPath()));
                 }
                 $childNodeBefore = $childNode;
             }
         }
     }
 }