public function testRequestHtml() { $expectedResponse = new Response('some-html-string'); $this->templating->expects($this->once())->method('render')->will($this->returnValue($expectedResponse)); /** @var Response $response */ $response = $this->controller->indexAction('html', 'test'); $this->assertEquals($expectedResponse, $response->getContent()); }
public function testRender() { $view = $this->createView(); $view->setTemplateIdentifier('path/to/template.html.twig'); $this->eventDispatcherMock->expects($this->once())->method('dispatch')->with(MVCEvents::PRE_CONTENT_VIEW, $this->isInstanceOf('\\eZ\\Publish\\Core\\MVC\\Symfony\\Event\\PreContentViewEvent')); $this->templateEngineMock->expects($this->once())->method('render')->with('path/to/template.html.twig', $view->getParameters()); $this->renderer->render($view); }
/** * @dataProvider renderForContentTestProvider * * @param ContentInfo $contentInfo * @param Request $request * @param array $options * @param array $customOptions */ public function testRenderForContentTemplateOverride(ContentInfo $contentInfo, Request $request, array $options, array $customOptions = array()) { $renderedComments = "I'm a comments thread for {$contentInfo->id}!"; $template = 'override.html.twig'; $this->templateEngine->expects($this->once())->method('render')->with($template, $customOptions + $options)->will($this->returnValue($renderedComments)); $this->assertSame($renderedComments, $this->getCommentsProvider($this->templateEngine, $template)->renderForContent($contentInfo, $request, $customOptions + array('template' => $template))); }
/** * Test if sender is set on Swift_Message without a name */ public function testSetsHTMLPart() { $this->templateEngine->expects($this->any())->method('render')->willReturn($this->messageBody); $this->message->expects($this->atLeastOnce())->method('addPart')->with($this->equalTo($this->messageBody), $this->equalTo('text/html')); $this->addDefaultSender(); $this->defaultSend(); }
public function testRenderWidgetGroup() { $this->widgetsHandler->addWidget($this->getWidget('group-widget-1', 'SuluTestBundle:widget:widget1.html.twig', array('test' => '1')), 'group-widget-1'); $this->widgetsHandler->addWidget($this->getWidget('group-widget-3', 'SuluTestBundle:widget:widget3.html.twig', array('test' => '3')), 'group-widget-3'); $this->widgetsHandler->addWidget($this->getWidget('group-widget-2', 'SuluTestBundle:widget:widget2.html.twig', array('test' => '2')), 'group-widget-2'); $param = false; $template = false; $this->templateEngine->expects($this->any())->method('render')->will($this->returnCallback(function ($t, $p) use(&$template, &$param) { $param = $p; $template = $t; return true; })); $this->assertTrue($this->widgetsHandler->renderWidgetGroup('test-group', array('testParam' => 'super'))); $this->assertNotFalse($param); $this->assertNotFalse($template); $this->assertEquals('SuluAdminBundle:Widgets:widgets.html.twig', $template); $this->assertEquals(array('widgets' => array(array('name' => 'group-widget-1', 'template' => 'SuluTestBundle:widget:widget1.html.twig', 'data' => array('test' => 1)), array('name' => 'group-widget-1', 'template' => 'SuluTestBundle:widget:widget1.html.twig', 'data' => array('test' => 1)), array('name' => 'group-widget-3', 'template' => 'SuluTestBundle:widget:widget3.html.twig', 'data' => array('test' => 3)), array('name' => 'group-widget-2', 'template' => 'SuluTestBundle:widget:widget2.html.twig', 'data' => array('test' => 2))), 'parameters' => array('testParam' => 'super')), $param); }
public function testGetEmailBody() { $emailEntity = new Email(); $templatePath = 'template_path'; $body = 'body'; $this->emailCacheManager->expects($this->once())->method('ensureEmailBodyCached')->with($emailEntity); $this->templating->expects($this->once())->method('render')->with($templatePath, ['email' => $emailEntity])->willReturn($body); $result = $this->helper->getEmailBody($emailEntity, $templatePath); $this->assertEquals($body, $result); }
/** * @dataProvider generateResponseWithCustomLayoutProvider */ public function testGenerateResponseWithCustomLayout($customLayout, $content) { $contentWithLayout = "<div id=\"i-am-a-twig-layout\">{$content}</div>"; $moduleResult = array('content' => $content, 'errorCode' => 200); $this->configResolver->expects($this->any())->method('getParameter')->will($this->returnValueMap(array(array('module_default_layout', 'ezpublish_legacy', null, $customLayout), array('legacy_mode', null, null, false)))); $this->templateEngine->expects($this->once())->method('render')->with($customLayout, array('module_result' => $moduleResult))->will($this->returnValue($contentWithLayout)); $manager = new LegacyResponseManager($this->templateEngine, $this->configResolver); $kernelResult = new ezpKernelResult($content, array('module_result' => $moduleResult)); $response = $manager->generateResponseFromModuleResult($kernelResult); $this->assertInstanceOf('eZ\\Bundle\\EzPublishLegacyBundle\\LegacyResponse', $response); $this->assertSame($contentWithLayout, $response->getContent()); $this->assertSame($moduleResult['errorCode'], $response->getStatusCode()); $this->assertSame($moduleResult, $response->getModuleResult()); }
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); }