public function testRender() { $d = new Dom(Dom::XHTML11, 'utf-8', new Child('p', 'This is another paragraph')); $d->addChild(new Child('p', 'This is a paragraph')); $code = $d->render(true); ob_start(); $d->render(); $output = ob_get_clean(); $this->assertContains('<p>', $code); $this->assertContains('<p>', $output); }
<?php require_once '../../bootstrap.php'; use Pop\Dom\Child; use Pop\Dom\Dom; try { $title = new Child('title', 'This is the title'); $meta = new Child('meta'); $meta->setAttributes(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8')); $head = new Child('head'); $head->addChildren(array($title, $meta)); $h1 = new Child('h1', 'This is a header'); $p = new Child('p', 'This is a paragraph.'); $div = new Child('div'); $div->setAttributes('id', 'contentDiv'); $div->addChildren(array($h1, $p)); $body = new Child('body'); $body->addChild($div); $html = new Child('html'); $html->setAttributes(array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en')); $html->addChildren(array($head, $body)); $doc = new Dom(Dom::XHTML11, 'utf-8', $html); $doc->render(); } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
/** * Method to render the feed and its items * * @param boolean $ret * @return mixed */ public function render($ret = false) { if ($this->feedType == Writer::JSON || $this->feedType == Writer::PHP) { $this->output = null; if ($this->feedType == Writer::JSON) { $this->output = json_encode($this->data); } else { if ($this->feedType == Writer::PHP) { $this->output = serialize($this->data); } } if ($ret) { return $this->output; } else { if (!headers_sent()) { header("HTTP/1.1 200 OK"); header("Content-type: " . $this->contentType); } echo $this->output; } } else { return parent::render($ret); } }