$content and $location will be injected in the selected template.
public renderLocation ( eZ\Publish\API\Repository\Values\Content\Location $location, string $viewType = ViewManagerInterface::VIEW_TYPE_FULL, array $parameters = [] ) : string | ||
$location | eZ\Publish\API\Repository\Values\Content\Location | |
$viewType | string | Variation of display for your content. Default is 'full'. |
$parameters | array | Parameters to pass to the template called to render the view. By default, it's empty. 'location' and 'content' entries are reserved for the Location (and its Content) that is viewed. |
Результат | string |
public function testRenderLocationWithClosure() { $viewProvider = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\View\\Provider\\Location'); $this->viewManager->addLocationViewProvider($viewProvider); $location = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Location'); $content = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Content'); $contentInfo = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo'); // Configuring view provider behaviour $closure = function ($params) { return serialize(array_keys($params)); }; $params = array('foo' => 'bar'); $viewProvider->expects($this->once())->method('getView')->with($location)->will($this->returnValue(new ContentView($closure, $params))); $contentService = $this->getMockBuilder("eZ\\Publish\\Core\\Repository\\ContentService")->disableOriginalConstructor()->getMock(); $contentService->expects($this->any())->method("loadContentByContentInfo")->with($contentInfo)->will($this->returnValue($content)); $this->repositoryMock->expects($this->any())->method("getContentService")->will($this->returnValue($contentService)); $location->expects($this->any())->method("getContentInfo")->will($this->returnValue($contentInfo)); // Configuring template engine behaviour $params += array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout); $expectedTemplateResult = serialize(array_keys($params)); $this->templateEngineMock->expects($this->never())->method('render'); self::assertSame($expectedTemplateResult, $this->viewManager->renderLocation($location)); }
public function testRenderLocationWithClosure() { $content = new Content(['versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo()])]); $location = new Location(['contentInfo' => new ContentInfo()]); // Configuring view provider behaviour $closure = function ($params) { return serialize(array_keys($params)); }; $params = array('foo' => 'bar'); $this->viewConfigurator->expects($this->once())->method('configure')->will($this->returnCallback(function (View $view) use($closure) { $view->setTemplateIdentifier($closure); })); $contentService = $this->getMockBuilder('eZ\\Publish\\Core\\Repository\\ContentService')->disableOriginalConstructor()->getMock(); $contentService->expects($this->any())->method('loadContentByContentInfo')->with($content->contentInfo)->will($this->returnValue($content)); $this->repositoryMock->expects($this->any())->method('getContentService')->will($this->returnValue($contentService)); // Configuring template engine behaviour $params += array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout); $this->templateEngineMock->expects($this->never())->method('render'); $expectedTemplateResult = array_keys($params); $templateResult = unserialize($this->viewManager->renderLocation($location, 'full', $params)); sort($expectedTemplateResult); sort($templateResult); self::assertSame($expectedTemplateResult, $templateResult); }