* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: HTML5ModeTest.php 974 2010-06-30 12:52:12Z kornel $ * @link http://phptal.org/ */ class HTML5ModeTest extends PHPTAL_TestCase { function testCDATAScript() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource(''); $this->assertEquals(normalize_html(''), normalize_html($tpl->execute())); } function testCDATAContent() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource('

]]>

'); $this->assertEquals(normalize_html('

<hello>

'), normalize_html($tpl->execute())); } function testRemovesXHTMLNS() { $tpl = $this->newPHPTAL()->setOutputMode(PHPTAL::HTML5)->setSource(' '); $this->assertEquals(normalize_html(''), normalize_html($tpl->execute())); } function testDoctype() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource('

]]>

'); $this->assertEquals(normalize_html('

<hello>

'), normalize_html($tpl->execute())); } function testProlog() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource('

]]>

'); $this->assertEquals(normalize_html('

<hello>

'), normalize_html($tpl->execute())); } function testAttr() { $this->assertEquals('', $this->newPHPTAL()->setOutputMode(PHPTAL::HTML5)->setSource('')->execute()); } function testEmpty() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource(' <base href="http://example.com/"></base> <basefont face="Helvetica" /> <meta name="test" content=""></meta> <link rel="test"></link> </head> <body> <br/> <br /> <br></br> <hr/> <img src="test"></img> <form> <textarea /> <textarea tal:content="\'\'" /> <textarea tal:content="nonexistant | nothing" /> </form> </body> </html>'); $res = $tpl->execute(); $res = normalize_html($res); $exp = normalize_html('<!DOCTYPE html><html> <head> <title>



'); $this->assertEquals($exp, $res); } function testBoolean() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource(' '); $res = $tpl->execute(); $res = normalize_html($res); $exp = normalize_html(' '); $this->assertEquals($exp, $res); } function testMixedModes() { $tpl = $this->newPHPTAL(); $tpl->setOutputMode(PHPTAL::HTML5); $tpl->setSource(''); $this->assertEquals('',$tpl->execute()); $tpl->setOutputMode(PHPTAL::XHTML); $this->assertEquals('',$tpl->execute()); } private function decodeNumericEntities($str) { return normalize_html(preg_replace('/&#x?[a-f0-9]+;/ie','htmlspecialchars(html_entity_decode("\\0"))', $str)); } function testAttributeQuotes() { $res = $this->newPHPTAL()->setSource('contact me')->execute(); $this->assertEquals($this->decodeNumericEntities(''),$this->decodeNumericEntities($res)); } }