/** * Render the block * * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block * @param array $params * @param array $cacheSettings settings for the HTTP cache, 'smax-age' and * 'max-age' are checked. * * @return \Symfony\Component\HttpFoundation\Response */ public function viewBlock(Block $block, array $params = array(), array $cacheSettings = array()) { $response = new Response(); if ($this->getParameter('content.view_cache') === true) { $response->setPublic(); if (isset($cacheSettings['smax-age']) && is_int($cacheSettings['smax-age'])) { $response->setSharedMaxAge((int) $cacheSettings['smax-age']); } if (isset($cacheSettings['max-age']) && is_int($cacheSettings['max-age'])) { $response->setMaxAge((int) $cacheSettings['max-age']); } } $response->setContent($this->viewManager->renderBlock($block, $params + array('pageService' => $this->pageService, 'valid_items' => $this->pageService->getValidBlockItems($block)))); return $response; }
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); }