/** * @test */ public function propertiesThatStartWithIsAreStillAccessedNormally() { $post = new Post(); $post->setPrivate(true); $this->view->assignMultiple(array('post' => $post)); $this->view->setTemplateSource('<f:if condition="{post.isprivate}">Private!</f:if>'); $actual = $this->view->render(); $this->assertSame('', $actual); }
/** * @test */ public function nonExistingIsMethodWillNotThrowError() { $post = new Post(); $post->setPrivate(true); $this->view->assignMultiple(array('post' => $post)); $this->view->setTemplateSource('<f:if condition="{post.isNonExisting}">Wrong!</f:if>'); $actual = $this->view->render(); $this->assertSame('', $actual); }
/** * @test */ public function renderSectionIsEvaluatedCorrectly() { $httpRequest = Request::create(new Uri('http://localhost')); $actionRequest = new ActionRequest($httpRequest); $standaloneView = new StandaloneView($actionRequest, $this->standaloneViewNonce); $standaloneView->assign('foo', 'bar'); $standaloneView->setTemplateSource('Around stuff... <f:section name="innerSection">test {foo}</f:section> after it'); $expected = 'test bar'; $actual = $standaloneView->renderSection('innerSection'); $this->assertSame($expected, $actual); }
/** * @test */ public function layoutViewHelperCanContainIfCondition() { $request = Request::create(new Uri('http://localhost')); $actionRequest = $request->createActionRequest(); $standaloneView = new StandaloneView($actionRequest, uniqid()); vfsStreamWrapper::register(); mkdir('vfs://MyLayouts'); \file_put_contents('vfs://MyLayouts/foo', 'foo: <f:render section="content" />'); \file_put_contents('vfs://MyLayouts/bar', 'bar: <f:render section="content" />'); $standaloneView->setLayoutRootPath('vfs://MyLayouts'); $source = '<f:layout name="{f:if(condition: \'1 == 1\', then: \'foo\', else: \'bar\')}" /><f:section name="content">Content</f:section>'; $standaloneView->setTemplateSource($source); $uncompiledResult = $standaloneView->render(); $compiledResult = $standaloneView->render(); $this->assertSame($uncompiledResult, $compiledResult, 'The rendered compiled template did not match the rendered uncompiled template.'); $this->assertSame('foo: Content', $standaloneView->render()); }
/** * @test */ public function variablesAreNotEscapedIfEscapingIsDisabled() { $standaloneView = new StandaloneView(null, $this->standaloneViewNonce); $standaloneView->assign('name', 'Sebastian <script>alert("dangerous");</script>'); $standaloneView->setTemplateSource('{escapingEnabled=false}Hello {name}.'); $expected = 'Hello Sebastian <script>alert("dangerous");</script>.'; $actual = $standaloneView->render(); $this->assertSame($expected, $actual); }