/** * @test */ public function layoutViewHelperCanContainIfCondition() { 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" />'); $this->view->setLayoutRootPath('vfs://MyLayouts'); $source = '<f:layout name="{f:if(condition: \'1 == 1\', then: \'foo\', else: \'bar\')}" /><f:section name="content">Content</f:section>'; $this->view->setTemplateSource($source); $uncompiledResult = $this->view->render(); $compiledResult = $this->view->render(); $this->assertSame($uncompiledResult, $compiledResult, 'The rendered compiled template did not match the rendered uncompiled template.'); $this->assertSame('foo: Content', $this->view->render()); }
/** * @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 xmlNamespacesCanBeIgnored() { $httpRequest = Request::create(new Uri('http://localhost')); $actionRequest = new ActionRequest($httpRequest); $actionRequest->setFormat('txt'); $standaloneView = new Fixtures\View\StandaloneView($actionRequest, $this->standaloneViewNonce); $standaloneView->setTemplatePathAndFilename(__DIR__ . '/Fixtures/TestTemplateWithCustomNamespaces.txt'); $standaloneView->setLayoutRootPath(__DIR__ . '/Fixtures/SpecialLayouts'); $expected = '<foo:bar /><bar:foo></bar:foo><foo.bar:baz />foobar'; $actual = $standaloneView->render(); $this->assertSame($expected, $actual); }
/** * @test */ public function explicitLayoutPathIsUsed() { $httpRequest = Request::create(new Uri('http://localhost')); $actionRequest = new ActionRequest($httpRequest); $actionRequest->setFormat('txt'); $standaloneView = new StandaloneView($actionRequest, $this->standaloneViewNonce); $standaloneView->setTemplatePathAndFilename(__DIR__ . '/Fixtures/TestTemplateWithLayout.txt'); $standaloneView->setLayoutRootPath(__DIR__ . '/Fixtures/SpecialLayouts'); $expected = 'Hey -- overridden -- HEY HO'; $actual = $standaloneView->render(); $this->assertSame($expected, $actual); }