/** * Evaluate a TypoScript path with a given context without content caching * * This is used to render uncached segments "out of band" in getCachedSegment of ContentCache. * * @param string $path * @param array $contextArray * @return mixed * * TODO Find another way of disabling the cache (especially to allow cached content inside uncached content) */ public function evaluateUncached($path, array $contextArray) { $previousEnableContentCache = $this->enableContentCache; $this->enableContentCache = FALSE; $this->runtime->pushContextArray($contextArray); $result = $this->runtime->evaluate($path); $this->runtime->popContext(); $this->enableContentCache = $previousEnableContentCache; return $result; }
/** * Render the given TypoScript and return the rendered page * * @return string */ protected function renderTypoScript() { $this->typoScriptRuntime->pushContextArray($this->variables); try { $output = $this->typoScriptRuntime->render($this->getTypoScriptPathForCurrentRequest()); } catch (RuntimeException $exception) { throw $exception->getPrevious(); } $this->typoScriptRuntime->popContext(); return $output; }
public function setUp() { parent::setUp(); $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository'); $domainRepository = $this->objectManager->get('TYPO3\\Neos\\Domain\\Repository\\DomainRepository'); $siteRepository = $this->objectManager->get('TYPO3\\Neos\\Domain\\Repository\\SiteRepository'); $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface'); $contextProperties = array('workspaceName' => 'live'); $contentContext = $this->contextFactory->create($contextProperties); $siteImportService = $this->objectManager->get('TYPO3\\Neos\\Domain\\Service\\SiteImportService'); $siteImportService->importFromFile(__DIR__ . '/../../Fixtures/NodeStructure.xml', $contentContext); $this->persistenceManager->persistAll(); $currentDomain = $domainRepository->findOneByActiveRequest(); if ($currentDomain !== NULL) { $contextProperties['currentSite'] = $currentDomain->getSite(); $contextProperties['currentDomain'] = $currentDomain; } else { $contextProperties['currentSite'] = $siteRepository->findFirst(); } $contentContext = $this->contextFactory->create($contextProperties); $this->contentContext = $contentContext; $this->propertyMapper = $this->objectManager->get('TYPO3\\Flow\\Property\\PropertyMapper'); $this->viewHelper = new \TYPO3\Neos\ViewHelpers\Uri\NodeViewHelper(); /** @var $requestHandler \TYPO3\Flow\Tests\FunctionalTestRequestHandler */ $requestHandler = self::$bootstrap->getActiveRequestHandler(); $httpRequest = $requestHandler->getHttpRequest(); $httpRequest->setBaseUri('http://neos.test/'); $controllerContext = new ControllerContext(new ActionRequest($httpRequest), $requestHandler->getHttpResponse(), new Arguments(array()), new UriBuilder()); $this->inject($this->viewHelper, 'controllerContext', $controllerContext); $typoScriptObject = $this->getAccessibleMock('\\TYPO3\\TypoScript\\TypoScriptObjects\\TemplateImplementation', array('dummy'), array(), '', FALSE); $this->tsRuntime = new Runtime(array(), $controllerContext); $this->tsRuntime->pushContextArray(array('documentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home'), 'alternativeDocumentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home/about-us/mission'))); $this->inject($typoScriptObject, 'tsRuntime', $this->tsRuntime); $mockView = $this->getAccessibleMock('TYPO3\\TypoScript\\TypoScriptObjects\\Helpers\\FluidView', array(), array(), '', FALSE); $mockView->expects($this->any())->method('getTypoScriptObject')->will($this->returnValue($typoScriptObject)); $viewHelperVariableContainer = new \TYPO3\Fluid\Core\ViewHelper\ViewHelperVariableContainer(); $viewHelperVariableContainer->setView($mockView); $this->inject($this->viewHelper, 'viewHelperVariableContainer', $viewHelperVariableContainer); }
public function setUp() { parent::setUp(); $this->router->setRoutesConfiguration(null); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $domainRepository = $this->objectManager->get(DomainRepository::class); $siteRepository = $this->objectManager->get(SiteRepository::class); $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $contextProperties = array('workspaceName' => 'live'); $contentContext = $this->contextFactory->create($contextProperties); $siteImportService = $this->objectManager->get(SiteImportService::class); $siteImportService->importFromFile(__DIR__ . '/../../Fixtures/NodeStructure.xml', $contentContext); $this->persistenceManager->persistAll(); /** @var Domain $currentDomain */ $currentDomain = $domainRepository->findOneByActiveRequest(); if ($currentDomain !== null) { $contextProperties['currentSite'] = $currentDomain->getSite(); $contextProperties['currentDomain'] = $currentDomain; } else { $contextProperties['currentSite'] = $siteRepository->findFirst(); } $contentContext = $this->contextFactory->create($contextProperties); $this->contentContext = $contentContext; $this->propertyMapper = $this->objectManager->get(PropertyMapper::class); $this->viewHelper = new NodeViewHelper(); /** @var $requestHandler FunctionalTestRequestHandler */ $requestHandler = self::$bootstrap->getActiveRequestHandler(); $httpRequest = $requestHandler->getHttpRequest(); $httpRequest->setBaseUri(new Uri('http://neos.test/')); $controllerContext = new ControllerContext(new ActionRequest($httpRequest), $requestHandler->getHttpResponse(), new Arguments(array()), new UriBuilder()); $this->inject($this->viewHelper, 'controllerContext', $controllerContext); $typoScriptObject = $this->getAccessibleMock(TemplateImplementation::class, array('dummy'), array(), '', false); $this->tsRuntime = new Runtime(array(), $controllerContext); $this->tsRuntime->pushContextArray(array('documentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home'), 'alternativeDocumentNode' => $this->contentContext->getCurrentSiteNode()->getNode('home/about-us/mission'))); $this->inject($typoScriptObject, 'tsRuntime', $this->tsRuntime); /** @var AbstractTemplateView|\PHPUnit_Framework_MockObject_MockObject $mockView */ $mockView = $this->getAccessibleMock(FluidView::class, array(), array(), '', false); $mockView->expects($this->any())->method('getTypoScriptObject')->will($this->returnValue($typoScriptObject)); $viewHelperVariableContainer = new ViewHelperVariableContainer(); $viewHelperVariableContainer->setView($mockView); $this->inject($this->viewHelper, 'viewHelperVariableContainer', $viewHelperVariableContainer); $templateVariableContainer = new TemplateVariableContainer(array()); $this->inject($this->viewHelper, 'templateVariableContainer', $templateVariableContainer); $this->viewHelper->setRenderChildrenClosure(function () use($templateVariableContainer) { $linkedNode = $templateVariableContainer->get('linkedNode'); return $linkedNode !== null ? $linkedNode->getLabel() : ''; }); $this->viewHelper->initialize(); }
/** * Renders the view * * @return string The rendered view * @throws \TYPO3\TYPO3\Exception if no node is given * @api */ public function render() { $currentNode = isset($this->variables['value']) ? $this->variables['value'] : NULL; if (!$currentNode instanceof \TYPO3\TYPO3CR\Domain\Model\NodeInterface) { throw new \TYPO3\TYPO3\Exception('TypoScriptView needs a node as argument.', 1329736456); } // TODO: find closest folder node from this node... $closestFolderNode = $currentNode; $currentSiteNode = $this->nodeRepository->getContext()->getCurrentSiteNode(); $typoScriptObjectTree = $this->typoScriptService->getMergedTypoScriptObjectTree($currentSiteNode, $closestFolderNode); $typoScriptRuntime = new Runtime($typoScriptObjectTree, $this->controllerContext); $typoScriptRuntime->pushContextArray(array('node' => $currentNode)); $output = $typoScriptRuntime->render($this->typoScriptPath); $typoScriptRuntime->popContext(); return $output; }