public function testConstructor() { $document = new Document(new SplFileInfo(__FILE__, '.', '.')); $this->assertSame(file_get_contents(__FILE__), $document->getBody()); $this->assertSame(file_get_contents(__FILE__), $document->getBodyDecorated()); $this->assertSame('DocumentTest.php', $document->getPath()); }
/** * @dataProvider getPostRenderWithLayoutTests */ public function testPostRenderWithLayout($layout) { $document = new Document(); $document->setBody('Hello {{ name }}'); $document->setLayout($layout); $document->setVars(array('key' => 'value', 'currentPath' => 'should not appear')); $template = <<<EOL "{{ carew.document.body }}" "{{ carew.relativeRoot }}" "{{ carew.currentPath }}" "{{ carew.extra.foo }}" "{{ carew.extra.key }}" EOL; $this->twigLoader->setTemplate('default.html.twig', $template); $event = new CarewEvent(array($document)); $this->getTwigGlobals()->fromArray(array('foo' => 'bar', 'relativeRoot' => 'should not appear')); $this->twigListenner->postRender($event); $expected = <<<EOL "Hello {{ name }}" "." "" "bar" "value" EOL; $this->assertSame($expected, $document->getBodyDecorated()); }
public function write(Document $document, $webDir) { $target = $webDir . '/' . $document->getPath(); $this->filesystem->mkdir(dirname($target)); file_put_contents($target, $document->getBodyDecorated()); }