<?php require_once ('lib/simpletest/unit_tester.php'); require_once ('html/HtmlLink.inc') ; require_once ('html/HtmlList.inc') ; require_once ('html/HtmlDocument.inc') ;
class HtmlDocumentTests extends UnitTestCase {
public function testEmptyDoc () {
$d = new HtmlDocument ("title") ; $s = $d->build() ;
$s = str_replace ("\n", "", $s) ; //print_r (htmlentities ($s)) ; echo "<hr>" ; $this->assertEqual ($s, HtmlDocument::DOCTYPE . HtmlDocument::PREAMBLE . "<head><title>title</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/></head><body></body></html>") ; }
public function testBody () {
$d = new HtmlDocument ("title") ; $d->setBody ("hello world") ; $s = $d->build () ; $s = str_replace ("\n", "", $s) ; //print_r (htmlentities ($s)) ; echo "<hr>" ; $this->assertEqual ($s, HtmlDocument::DOCTYPE . HtmlDocument::PREAMBLE . "<head><title>title</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/></head><body>hello world</body></html>") ;
$t = new HtmlUnorderedList () ; $t->setData (2, "tweede item") ; $t->setData (1, "eerste item") ; $t->setData (0, new HtmlImage ("/junit/data/good_avatar.jpg", "test image")) ;
$d->setBody ($t) ; $s = $d->build () ; $s = str_replace ("\n", "", $s) ; //print_array (str_split ($s)) ; $this->assertEqual ($s, HtmlDocument::DOCTYPE . HtmlDocument::PREAMBLE . "<head><title>title</title><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/></head><body>". "<ul><li><img src=\"/junit/data/good_avatar.jpg\" alt=\"test image\" /></li>". "<li>eerste item</li><li>tweede item</li></ul></body></html>") ; }
public function testHeader () {
$d = new HtmlDocument ("title") ; $d->addStylesheet ("global.css") ; $d->addStylesheet ("default.css") ;
$d->addStyle ("p", "bold") ; $d->addStyle (".dropcap", "font:12 px") ;
$d->addJavaScript ("http://script1.js") ; $d->addJavaScript ("http://script2.js") ;
$d->addMetaTag('DESCRIPTION', "big big website") ;
$s = $d->build() ; $s = str_replace ("\n", "", $s) ; //print_r (htmlentities ($s)) ; echo "<hr>" ; // print_array (str_split ($s)) ; $this->assertEqual ($s, HtmlDocument::DOCTYPE . HtmlDocument::PREAMBLE . "<head><title>title</title>". "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"/>". "<meta name=\"DESCRIPTION\" content=\"big big website\" />". "<link rel=\"stylesheet\" href=\"global.css\" type=\"text/css\" />". "<link rel=\"stylesheet\" href=\"default.css\" type=\"text/css\" />". "<style type=\"text/css\"> <!--p { bold } .dropcap { font:12 px } --></style>". "<script language=\"javascript\" src=\"http://script1.js\" type=\"text/javascript\"></script>". "<script language=\"javascript\" src=\"http://script2.js\" type=\"text/javascript\"></script>". "</head><body></body></html>") ; }
public function testAddComments () { $d = new HtmlDocument ("title") ; $d->addComment ('comment 1') ; $d->addComment ('comment 2') ; $d->addComment ('comment 3') ;
$s = $d->buildComments() ; //echo(htmlentities($s)."<br>"); $s = str_replace ("\n", "", $s) ; $this->assertEqual ($s, '<!-- comment 1 --><!-- comment 2 --><!-- comment 3 -->') ;
$s = $d->build() ; $s = str_replace ("\n", "", $s) ; //echo(htmlentities($s)."<br>"); $this->assertEqual($s, HtmlDocument::DOCTYPE . HtmlDocument::PREAMBLE . '<head><title>title</title><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><!-- comment 1 --><!-- comment 2 --><!-- comment 3 --></head><body></body></html>') ; } }
?>
|