/** * @test */ public function createNodeFromTemplateUsesWorkspacesOfContext() { $nodeTemplate = $this->generateBasicNodeTemplate(); $this->context = $this->contextFactory->create(array('workspaceName' => 'user1')); $rootNode = $this->context->getNode('/'); $node = $rootNode->createNodeFromTemplate($nodeTemplate, 'just-a-node'); $workspace = $node->getWorkspace(); $this->assertEquals('user1', $workspace->getName(), 'Node should be created in workspace of context'); }
/** * @test */ public function createNodeFromTemplateUsesIdentifierFromTemplate() { $identifier = \TYPO3\Flow\Utility\Algorithms::generateUUID(); $template = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate(); $template->setName('new-node'); $template->setIdentifier($identifier); $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNodeFromTemplate($template); $this->assertSame($identifier, $newNode->getIdentifier()); }
/** * @test */ public function nodePathAvailableForNodeWillReturnFalseIfNodeWithGivenPathExistsAlready() { $this->workspaceRepository->add(new \TYPO3\TYPO3CR\Domain\Model\Workspace('live')); $rootNode = $this->context->getRootNode(); $fooNode = $rootNode->createNode('foo'); $fooNode->createNode('bar'); $bazNode = $rootNode->createNode('baz'); $this->persistenceManager->persistAll(); $actualResult = $this->nodeService->nodePathAvailableForNode('/foo/bar', $bazNode); $this->assertFalse($actualResult); }
/** * @test */ public function findNodesByRelatedEntitiesFindsExistingNodeWithMatchingEntityProperty() { $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNode('test', $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeTypeWithEntities')); $testImage = new Image(); $this->persistenceManager->add($testImage); $newNode->setProperty('image', $testImage); $this->persistenceManager->persistAll(); $relationMap = array('TYPO3\\Flow\\Tests\\Functional\\Persistence\\Fixtures\\Image' => array($this->persistenceManager->getIdentifierByObject($testImage))); $result = $this->nodeDataRepository->findNodesByRelatedEntities($relationMap); $this->assertCount(1, $result); }
/** * Filter a node by the current context. * Will either return the node or NULL if it is not permitted in current context. * * @param NodeInterface $node * @param Context $context * @return \TYPO3\TYPO3CR\Domain\Model\Node|NULL */ protected function filterNodeByContext(NodeInterface $node, Context $context) { if (!$context->isRemovedContentShown() && $node->isRemoved()) { return NULL; } if (!$context->isInvisibleContentShown() && !$node->isVisible()) { return NULL; } if (!$context->isInaccessibleContentShown() && !$node->isAccessible()) { return NULL; } return $node; }
public function setUp() { $this->convertEmailLinks = $this->getAccessibleMock('Networkteam\\Neos\\MailObfuscator\\Typoscript\\ConvertEmailLinksImplementation', array('getValue'), array(), '', FALSE); $this->mockContext = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\Context')->disableOriginalConstructor()->getMock(); $this->mockContext->expects($this->any())->method('getWorkspaceName')->will($this->returnValue('live')); $this->mockNode = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface')->getMock(); $this->mockNode->expects($this->any())->method('getContext')->will($this->returnValue($this->mockContext)); $this->mockTsRuntime = $this->getMockBuilder('TYPO3\\TypoScript\\Core\\Runtime')->disableOriginalConstructor()->getMock(); $this->mockTsRuntime->expects($this->any())->method('getCurrentContext')->will($this->returnValue(array('node' => $this->mockNode))); $this->convertEmailLinks->_set('tsRuntime', $this->mockTsRuntime); $this->convertEmailLinks->_set('linkNameConverter', new \Networkteam\Neos\MailObfuscator\String\Converter\RewriteAtCharConverter()); $this->convertEmailLinks->_set('mailToHrefConverter', new \Networkteam\Neos\MailObfuscator\String\Converter\Mailto2HrefObfuscatingConverter()); srand(10); }
public function setUp() { $this->siteNode = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); $this->firstLevelNode = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); $this->secondLevelNode = $this->getMock('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface'); $this->siteNode->expects($this->any())->method('getPath')->will($this->returnValue('/site')); $this->siteNode->expects($this->any())->method('getChildNodes')->will($this->returnValue(array($this->firstLevelNode))); $this->mockContext = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\Context')->disableOriginalConstructor()->getMock(); $this->mockContext->expects($this->any())->method('getCurrentSiteNode')->will($this->returnValue($this->siteNode)); $this->firstLevelNode->expects($this->any())->method('getParent')->will($this->returnValue($this->siteNode)); $this->firstLevelNode->expects($this->any())->method('getPath')->will($this->returnValue('/site/first')); $this->secondLevelNode->expects($this->any())->method('getParent')->will($this->returnValue($this->siteNode)); $this->secondLevelNode->expects($this->any())->method('getPath')->will($this->returnValue('/site/first/second')); }
/** * Internal method * * The dimension value of this node has to match the current target dimension value (must be higher in priority or equal) * * @return boolean */ public function dimensionsAreMatchingTargetDimensionValues() { $dimensions = $this->getDimensions(); $contextDimensions = $this->context->getDimensions(); foreach ($this->context->getTargetDimensions() as $dimensionName => $targetDimensionValue) { if (!isset($dimensions[$dimensionName])) { if ($targetDimensionValue === null) { continue; } else { return false; } } elseif ($targetDimensionValue === null && $dimensions[$dimensionName] === array()) { continue; } elseif (!in_array($targetDimensionValue, $dimensions[$dimensionName], true)) { $contextDimensionValues = $contextDimensions[$dimensionName]; $targetPositionInContext = array_search($targetDimensionValue, $contextDimensionValues, true); $nodePositionInContext = min(array_map(function ($value) use($contextDimensionValues) { return array_search($value, $contextDimensionValues, true); }, $dimensions[$dimensionName])); $val = $targetPositionInContext !== false && $nodePositionInContext !== false && $targetPositionInContext >= $nodePositionInContext; if ($val === false) { return false; } } } return true; }
public function setUp() { parent::setUp(); $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository'); $liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($liveWorkspace); $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface'); $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]); $rootNode = $this->context->getRootNode(); $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $this->siteNode->setProperty('title', 'welcome'); $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository'); $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController'); $this->createNodesForNodeSearchTest(); }
public function setUp() { parent::setUp(); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($liveWorkspace); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]); $rootNode = $this->context->getRootNode(); $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $this->siteNode->setProperty('title', 'welcome'); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->nodeIndexCommandController = $this->objectManager->get(NodeIndexCommandController::class); $this->createNodesForNodeSearchTest(); }
/** * Search all properties for given $term * * TODO: Implement a better search when Flow offer the possibility * * @param string $term * @param array $searchNodeTypes * @param Context $context * @param NodeInterface $startingPoint * @return array <\TYPO3\TYPO3CR\Domain\Model\NodeInterface> */ public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null) { if (strlen($term) === 0) { throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285); } $searchResult = array(); $nodeTypeFilter = implode(',', $searchNodeTypes); $nodeDataRecords = $this->nodeDataRepository->findByProperties($term, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $startingPoint ? $startingPoint->getPath() : null); foreach ($nodeDataRecords as $nodeData) { $node = $this->nodeFactory->createFromNodeData($nodeData, $context); if ($node !== null) { $searchResult[$node->getPath()] = $node; } } return $searchResult; }
/** * @test */ public function addHeadersInLiveWorkspaceAndCachedResponseAddsSiteToken() { $this->mockContext->expects($this->any())->method('getWorkspaceName')->willReturn('live'); $this->mockTokenStorage->expects($this->any())->method('getToken')->willReturn('RandomSiteToken'); $this->mockResponse->expects($this->at(0))->method('setHeader')->with('X-Site', 'RandomSiteToken'); $this->service->addHeaders($this->mockRequest, $this->mockResponse, $this->mockController); }
/** * Creates a new Content Context object. * * NOTE: This is for internal use only, you should use the ContextFactory for creating Context instances. * * @param string $workspaceName Name of the current workspace * @param \DateTimeInterface $currentDateTime The current date and time * @param array $dimensions Array of dimensions with array of ordered values * @param array $targetDimensions Array of dimensions used when creating / modifying content * @param boolean $invisibleContentShown If invisible content should be returned in query results * @param boolean $removedContentShown If removed content should be returned in query results * @param boolean $inaccessibleContentShown If inaccessible content should be returned in query results * @param Site $currentSite The current Site object * @param Domain $currentDomain The current Domain object * @see ContextFactoryInterface */ public function __construct($workspaceName, \DateTimeInterface $currentDateTime, array $dimensions, array $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown, Site $currentSite = null, Domain $currentDomain = null) { parent::__construct($workspaceName, $currentDateTime, $dimensions, $targetDimensions, $invisibleContentShown, $removedContentShown, $inaccessibleContentShown); $this->currentSite = $currentSite; $this->currentDomain = $currentDomain; $this->targetDimensions = $targetDimensions; }
/** * Create a node for the given NodeData, given that it is a variant of the current node * * @param NodeData $nodeData * @return Node */ protected function createNodeForVariant($nodeData) { $contextProperties = $this->context->getProperties(); $contextProperties['dimensions'] = $nodeData->getDimensionValues(); unset($contextProperties['targetDimensions']); $adjustedContext = $this->contextFactory->create($contextProperties); return $this->nodeFactory->createFromNodeData($nodeData, $adjustedContext); }
/** * @test */ public function sortByDateTimeDescending() { $nodesToSort = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array())]; $correctOrder = [$this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addd', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115addf', $this->context->getWorkspace(true), array()), $this->nodeDataRepository->findOneByIdentifier('c381f64d-4269-429a-9c21-6d846115adde', $this->context->getWorkspace(true), array())]; $flowQuery = new \TYPO3\Eel\FlowQuery\FlowQuery($nodesToSort); $operation = new SortOperation(); $operation->evaluate($flowQuery, ['_lastPublicationDateTime', 'DESC']); $this->assertEquals($correctOrder, $flowQuery->getContext()); }
/** * @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 getChildNodesWithNodeTypeFilterWorks() { $documentNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Document'); $headlineNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Headline'); $imageNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Image'); $node = $this->context->getRootNode()->createNode('node-with-child-node', $documentNodeType); $node->createNode('headline', $headlineNodeType); $node->createNode('text', $imageNodeType); $this->assertCount(1, $node->getChildNodes('TYPO3.TYPO3CR.Testing:Headline')); }
/** * @return void */ protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get(ContextFactory::class); $this->context = $this->contextFactory->create(array('workspaceName' => 'live')); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add(new Workspace('live')); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->rootNode = $this->context->getNode('/'); $this->persistenceManager->persistAll(); }
/** * @throws \TYPO3\TYPO3CR\Exception\NodeTypeNotFoundException */ protected function createNodesForNodeSearchTest() { $rootNode = $this->context->getRootNode(); $newNode1 = $rootNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeType')); $newNode1->setProperty('test1', 'simpleTestValue'); $newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeType')); $newNode2->setProperty('test2', 'simpleTestValue'); $newNode2 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeType')); $newNode2->setProperty('test1', 'otherValue'); $this->persistenceManager->persistAll(); }
/** * @return void */ protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactory'); $this->context = $this->contextFactory->create(array('workspaceName' => 'live')); $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository'); $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository'); $this->workspaceRepository->add(new Workspace('live')); $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $this->rootNode = $this->context->getNode('/'); $this->persistenceManager->persistAll(); }
/** * Creates some sample nodes to run tests against */ protected function createNodesForNodeSearchTest() { $rootNode = $this->context->getRootNode(); $newNode1 = $rootNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode1->setProperty('title', 'chicken'); $newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode2->setProperty('title', 'chicken'); $newNode2 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode2->setProperty('title', 'egg'); $this->persistenceManager->persistAll(); $this->nodeIndexCommandController->buildCommand(); }
public function setUp() { $this->convertUrisImplementation = $this->getAccessibleMock('TYPO3\\Neos\\TypoScript\\ConvertUrisImplementation', array('tsValue'), array(), '', false); $this->mockWorkspace = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace')->disableOriginalConstructor()->getMock(); $this->mockContext = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Service\\Context')->disableOriginalConstructor()->getMock(); $this->mockContext->expects($this->any())->method('getWorkspace')->will($this->returnValue($this->mockWorkspace)); $this->mockNode = $this->getMockBuilder('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface')->getMock(); $this->mockNode->expects($this->any())->method('getContext')->will($this->returnValue($this->mockContext)); $this->mockHttpUri = $this->getMockBuilder('TYPO3\\Flow\\Http\\Uri')->disableOriginalConstructor()->getMock(); $this->mockHttpUri->expects($this->any())->method('getHost')->will($this->returnValue('localhost')); $this->mockHttpRequest = $this->getMockBuilder('TYPO3\\Flow\\Http\\Request')->disableOriginalConstructor()->getMock(); $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockHttpUri)); $this->mockActionRequest = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\ActionRequest')->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest)); $this->mockControllerContext = $this->getMockBuilder('TYPO3\\Flow\\Mvc\\Controller\\ControllerContext')->disableOriginalConstructor()->getMock(); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockActionRequest)); $this->mockLinkingService = $this->createMock('TYPO3\\Neos\\Service\\LinkingService'); $this->convertUrisImplementation->_set('linkingService', $this->mockLinkingService); $this->mockTsRuntime = $this->getMockBuilder('TYPO3\\TypoScript\\Core\\Runtime')->disableOriginalConstructor()->getMock(); $this->mockTsRuntime->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->convertUrisImplementation->_set('tsRuntime', $this->mockTsRuntime); }
public function setUp() { $this->convertUrisImplementation = $this->getAccessibleMock(ConvertUrisImplementation::class, array('tsValue'), array(), '', false); $this->mockWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock(); $this->mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->mockContext->expects($this->any())->method('getWorkspace')->will($this->returnValue($this->mockWorkspace)); $this->mockNode = $this->getMockBuilder(NodeInterface::class)->getMock(); $this->mockNode->expects($this->any())->method('getContext')->will($this->returnValue($this->mockContext)); $this->mockHttpUri = $this->getMockBuilder(Uri::class)->disableOriginalConstructor()->getMock(); $this->mockHttpUri->expects($this->any())->method('getHost')->will($this->returnValue('localhost')); $this->mockHttpRequest = $this->getMockBuilder(Request::class)->disableOriginalConstructor()->getMock(); $this->mockHttpRequest->expects($this->any())->method('getUri')->will($this->returnValue($this->mockHttpUri)); $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock(); $this->mockActionRequest->expects($this->any())->method('getHttpRequest')->will($this->returnValue($this->mockHttpRequest)); $this->mockControllerContext = $this->getMockBuilder(ControllerContext::class)->disableOriginalConstructor()->getMock(); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockActionRequest)); $this->mockLinkingService = $this->createMock(LinkingService::class); $this->convertUrisImplementation->_set('linkingService', $this->mockLinkingService); $this->mockTsRuntime = $this->getMockBuilder(Runtime::class)->disableOriginalConstructor()->getMock(); $this->mockTsRuntime->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->convertUrisImplementation->_set('tsRuntime', $this->mockTsRuntime); }
/** * Convert raw value to references * * @param string $rawValue * @param Context $context * @return array<NodeInterface> */ protected function convertReferences($rawValue, Context $context) { $nodeIdentifiers = json_decode($rawValue); $result = []; if (is_array($nodeIdentifiers)) { foreach ($nodeIdentifiers as $nodeIdentifier) { $referencedNode = $context->getNodeByIdentifier($nodeIdentifier); if ($referencedNode !== null) { $result[] = $referencedNode; } } } return $result; }
/** * @test */ public function nodesCanHaveCustomImplementationClass() { $rootNode = $this->context->getRootNode(); $testingNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:NodeTypeWithReferences'); $happyNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:HappyTestingNode'); $headlineNodeType = $this->nodeTypeManager->getNodeType('TYPO3.TYPO3CR.Testing:Headline'); $fooNode = $rootNode->createNode('foo', $testingNodeType); $happyNode = $fooNode->createNode('bar', $happyNodeType); $bazNode = $happyNode->createNode('baz', $headlineNodeType); $this->assertNotInstanceOf('\\TYPO3\\TYPO3CR\\Tests\\Functional\\Domain\\Fixtures\\HappyNode', $fooNode); $this->assertInstanceOf('\\TYPO3\\TYPO3CR\\Tests\\Functional\\Domain\\Fixtures\\HappyNode', $happyNode); $this->assertNotInstanceOf('\\TYPO3\\TYPO3CR\\Tests\\Functional\\Domain\\Fixtures\\HappyNode', $bazNode); $this->assertEquals('bar claps hands!', $happyNode->clapsHands()); }
/** * @param Asset $asset * @param MetaDataCollection $metaDataCollection * @throws NodeTypeNotFoundException * @throws \TYPO3\Flow\Persistence\Exception\IllegalObjectTypeException * @return void */ public function mapMetaData(Asset $asset, MetaDataCollection $metaDataCollection) { $nodeType = $this->nodeTypeManager->getNodeType('Neos.MetaData:Image'); $asset = $metaDataCollection->get('asset'); $assetNodeData = $this->metaDataRepository->findOneByAssetIdentifier($asset->getIdentifier(), $this->context->getWorkspace()); if ($assetNodeData === null) { $assetNodeDataTemplate = $this->createAssetNodeTemplate($asset, $nodeType); $this->mapMetaDataToNodeData($assetNodeDataTemplate, $nodeType, $metaDataCollection); $this->nodeService->findOrCreateMetaDataRootNode($this->context)->createNodeFromTemplate($assetNodeDataTemplate); } else { $this->mapMetaDataToNodeData($assetNodeData, $nodeType, $metaDataCollection); $this->metaDataRepository->update($assetNodeData); } }
/** * Creates some sample nodes to run tests against */ protected function createNodesForNodeSearchTest() { $rootNode = $this->context->getRootNode(); $newNode1 = $rootNode->createNode('test-node-1', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode1->setProperty('title', 'chicken'); $newNode2 = $rootNode->createNode('test-node-2', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode2->setProperty('title', 'chicken'); $newNode3 = $rootNode->createNode('test-node-3', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page')); $newNode3->setProperty('title', 'egg'); $dimensionContext = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('de')))); $translatedNode3 = $dimensionContext->adoptNode($newNode3, TRUE); $translatedNode3->setProperty('title', 'Ei'); $this->persistenceManager->persistAll(); $this->nodeIndexCommandController->buildCommand(); }
/** * Repair votes action * * Compare number of votes between nodes and vote log and repair, if not dryRun * * @param boolean $dryRun Don't do anything, but report actions * @return string */ public function repairCommand($dryRun = TRUE) { if ($dryRun) { echo "Dry run, not making any changes\n"; } $q = new FlowQuery(array($this->context->getRootNode())); $answerNodes = $q->find('[instanceof Sfi.Encult:Answer]')->get(); foreach ($answerNodes as $answerNode) { /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */ $queryBuilder = $this->entityManager->createQueryBuilder(); $nodes = $queryBuilder->select('v')->from('Sfi\\Encult\\Domain\\Model\\Vote', 'v')->andWhere('v.answerIdentifier = :answerIdentifier')->setParameters(array('answerIdentifier' => $answerNode->getIdentifier()))->getQuery()->getArrayResult(); $dbCount = count($nodes); $crCount = $answerNode->getProperty('voteCount'); $path = $answerNode->getPath(); if ($dbCount !== $crCount) { echo "Found mistake for {$path} (db: {$dbCount} vs. cr: {$crCount})\n"; if (!$dryRun) { echo "Fixed\n"; $answerNode->setProperty('voteCount', $dbCount); } } } return "Done!\n"; }
/** * @test */ public function getPropertyReturnsReferencedNodesInCorrectWorkspace() { $nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager'); $nodeType = $nodeTypeManager->getNodeType('TYPO3.TYPO3CR:TestingNodeTypeWithReferences'); $identifier = '81c848ed-abb5-7608-a5db-7eea0331ccfa'; $rootNode = $this->context->getNode('/'); $referencedNode = $rootNode->createNode('referencedNode', $nodeType, $identifier); $node = $rootNode->createNode('node', $nodeType, '30e893c1-caef-0ca5-b53d-e5699bb8e506'); $node->setProperty('property2', $identifier); $testContext = $this->contextFactory->create(array('workspaceName' => 'test')); $testRootNode = $testContext->getNode('/'); $testReferencedNode = $testRootNode->createNode('testReferencedNode', $nodeType, $identifier); $testNode = $testRootNode->getNode('node'); $referencedNodeProperty = $node->getProperty('property2'); $this->assertNotSame($referencedNodeProperty->getWorkspace(), $testReferencedNode->getWorkspace()); $this->assertSame($referencedNodeProperty->getWorkspace(), $referencedNode->getWorkspace()); $testReferencedNodeProperty = $testNode->getProperty('property2'); $this->assertNotSame($testReferencedNodeProperty->getWorkspace(), $referencedNode->getWorkspace()); $this->assertSame($testReferencedNodeProperty->getWorkspace(), $testReferencedNode->getWorkspace()); }
/** * The dimension value of this node has to match the current target dimension value (must be higher in priority or equal) * * @return boolean */ protected function dimensionsAreMatchingTargetDimensionValues() { $dimensions = $this->getDimensions(); $contextDimensions = $this->context->getDimensions(); foreach ($this->context->getTargetDimensions() as $dimensionName => $targetDimensionValue) { if (!isset($dimensions[$dimensionName])) { return FALSE; } elseif (!in_array($targetDimensionValue, $dimensions[$dimensionName], TRUE)) { $contextDimensionValues = $contextDimensions[$dimensionName]; $targetPositionInContext = array_search($targetDimensionValue, $contextDimensionValues, TRUE); $nodePositionInContext = min(array_map(function ($value) use($contextDimensionValues) { return array_search($value, $contextDimensionValues, TRUE); }, $dimensions[$dimensionName])); $val = $targetPositionInContext !== FALSE && $nodePositionInContext !== FALSE && $targetPositionInContext >= $nodePositionInContext; if ($val === FALSE) { return FALSE; } } } return TRUE; }