/** * Stores the WidgetContext inside the Context, and sets the * AjaxWidgetIdentifier inside the Widget Context correctly. * * @param \TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext * @return void */ public function store(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext $widgetContext) { $ajaxWidgetId = md5(uniqid(mt_rand(), true)); $widgetContext->setAjaxWidgetIdentifier($ajaxWidgetId); $this->widgetContexts[$ajaxWidgetId] = $widgetContext; $this->storeWidgetContexts(); }
/** * @test */ public function viewHelperChildNodesCanBeReadAgain() { $viewHelperChildNodes = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\SyntaxTree\\RootNode'); $renderingContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContextInterface'); $this->widgetContext->setViewHelperChildNodes($viewHelperChildNodes, $renderingContext); $this->assertSame($viewHelperChildNodes, $this->widgetContext->getViewHelperChildNodes()); $this->assertSame($renderingContext, $this->widgetContext->getViewHelperChildNodeRenderingContext()); }
/** * The widget identifier is unique on the current page, and is used * in the URI as a namespace for the widget's arguments. * * @return string the widget identifier for this widget * @return void * @todo clean up, and make it somehow more routing compatible. */ private function initializeWidgetIdentifier() { $widgetCounter = $this->viewHelperVariableContainer->get(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper::class, 'nextWidgetNumber', 0); $widgetIdentifier = '@widget_' . $widgetCounter; $this->viewHelperVariableContainer->addOrUpdate(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetViewHelper::class, 'nextWidgetNumber', $widgetCounter + 1); $this->widgetContext->setWidgetIdentifier($widgetIdentifier); }
/** * The widget identifier is unique on the current page, and is used * in the URI as a namespace for the widget's arguments. * * @return string the widget identifier for this widget * @return void * @todo clean up, and make it somehow more routing compatible. */ private function initializeWidgetIdentifier() { if (!$this->viewHelperVariableContainer->exists('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetViewHelper', 'nextWidgetNumber')) { $widgetCounter = 0; } else { $widgetCounter = $this->viewHelperVariableContainer->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetViewHelper', 'nextWidgetNumber'); } $widgetIdentifier = '@widget_' . $widgetCounter; $this->viewHelperVariableContainer->addOrUpdate('TYPO3\\CMS\\Fluid\\Core\\Widget\\AbstractWidgetViewHelper', 'nextWidgetNumber', $widgetCounter + 1); $this->widgetContext->setWidgetIdentifier($widgetIdentifier); }
/** * @test */ public function initiateSubRequestBuildsRequestProperly() { $controller = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, array(), array(), '', FALSE); $this->viewHelper->_set('controller', $controller); // Initial Setup $widgetRequest = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class); $response = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\Response::class); $this->objectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)->will($this->returnValue($widgetRequest)); $this->objectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Response::class)->will($this->returnValue($response)); // Widget Context is set $widgetRequest->expects($this->once())->method('setWidgetContext')->with($this->widgetContext); // The namespaced arguments are passed to the sub-request // and the action name is exctracted from the namespace. $this->controllerContext->expects($this->once())->method('getRequest')->will($this->returnValue($this->request)); $this->widgetContext->expects($this->once())->method('getWidgetIdentifier')->will($this->returnValue('widget-1')); $this->request->expects($this->once())->method('getArguments')->will($this->returnValue(array('k1' => 'k2', 'widget-1' => array('arg1' => 'val1', 'arg2' => 'val2', 'action' => 'myAction')))); $widgetRequest->expects($this->once())->method('setArguments')->with(array('arg1' => 'val1', 'arg2' => 'val2')); $widgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction'); // Controller is called $controller->expects($this->once())->method('processRequest')->with($widgetRequest, $response); $output = $this->viewHelper->_call('initiateSubRequest'); // SubResponse is returned $this->assertSame($response, $output); }
/** * Returns the unique URI namespace for this widget in the format pluginNamespace[widgetIdentifier] * * @return string */ public function getArgumentPrefix() { return $this->widgetContext->getParentPluginNamespace() . '[' . $this->widgetContext->getWidgetIdentifier() . ']'; }
/** * @test */ public function sleepReturnsExpectedPropertyNames() { $this->assertEquals(array('widgetIdentifier', 'ajaxWidgetIdentifier', 'widgetConfiguration', 'controllerObjectName', 'parentPluginNamespace', 'parentExtensionName', 'parentPluginName', 'widgetViewHelperClassName'), $this->widgetContext->__sleep()); }