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()); }
public function testOnDocumentDoesNotLinkWithDoubleQuote() { $document = new Document(); $document->setPath('index.html'); $body = '<a href="https://google.com">"google.com"</a>'; $document->setBody($body); $event = new CarewEvent($document); $toc = new Toc(); $toc->onDocument($event); $this->assertSame($body, $document->getBody()); }
public function processDocumentDecoration(Document $document) { $event = new CarewEvent(array($document)); try { return $this->eventDispatcher->dispatch(Events::DOCUMENT_DECORATION, $event)->getSubject(); } catch (\Exception $e) { if ($document->getFile()) { throw new \LogicException(sprintf('Could not process "%s": "%s".', $document->getFile()->getRelativePathname(), $e->getMessage()), 0, $e); } throw new \LogicException(sprintf('Could not process "%s": "%s".', $document->getBody(), $e->getMessage()), 0, $e); } }
/** * @expectedException RuntimeException * @expectedExceptionMessage Unexpected "}" in a string template line 1. */ public function testPreRenderThrowExceptionOnRender() { $document = new Document(); $document->setLayout('default'); $document->setBody(<<<EOL Hello {{ foobar }} {% set text = '{{ foobar }' %} {{ template_from_string(text) }} EOL ); $event = new CarewEvent(array($document)); $this->twigListenner->preRender($event); $this->assertSame('foobar', $document->getBody()); }
private function enhanceTwigException(\Twig_Error $e, Document $document, $template = null) { if (-1 === $e->getTemplateLine()) { return new \RuntimeException($e->getRawMessage()); } $lines = explode(PHP_EOL, $document->getBody()); if (!$template || $template->getTemplateName() == $e->getTemplateFile()) { return new \RuntimeException(OutputFormatter::escape(sprintf('%s near "%s" near line %d.', $e->getRawMessage(), $lines[$e->getTemplateLine() - 1], $e->getTemplateLine()))); } return new \RuntimeException(OutputFormatter::escape(sprintf('%s in a string template line %d.', $e->getRawMessage(), $e->getTemplateLine()))); }