A difference in behavior of Tag::tagHtml()
bugged me:
$this->tag->setDocType(Phalcon\Tag::XHTML5);
echo $this->tag->tagHtml('div'); // yields <div>
$this->tag->setDocType(Phalcon\Tag::HTML5);
echo $this->tag->tagHtml('div'); // yields <div></div>
then I spotted what I thought to be the problem:
public static function tagHtml(string tagName, var parameters = null, boolean selfClose = false,
boolean onlyStart = false, boolean useEol = false) -> string
{
// [...]
/**
* Check if Doctype is XHTML
*/
if self::_documentType > self::HTML5 {
if selfClose {
let localCode .= " />";
} else {
let localCode .= ">";
}
} else {
if onlyStart {
let localCode .= ">";
} else {
let localCode .= "></" . tagName . ">";
}
}
So I patched it:
/**
* Check if Doctype is XHTML
*/
if self::_documentType > self::HTML5 {
if selfClose {
let localCode .= " />";
} elseif onlyStart {
let localCode .= ">";
} else {
let localCode .= "></" . tagName . ">";
}
} else {
if onlyStart {
let localCode .= ">";
} else {
let localCode .= "></" . tagName . ">";
}
}
recompiled the whole thing, ran ./run-tests.sh
and then:
There were 3 failures:
---------
1) Phalcon\Tests\unit\Phalcon\Tag\TagTagHtmlTest::testTagHtmlName | tagHtml with name parameter returns invalid HTML Strict
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<aside>'
+'<aside></aside>'
#1 /vagrant/webroot/vendor/phalcon/cphalcon/tests/_support/Verify.php:25
#2 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:48
#3 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:50
#4 /vagrant/webroot/vendor/phalcon/cphalcon/codecept.phar:7
---------
2) Phalcon\Tests\unit\Phalcon\Tag\TagTagHtmlTest::testTagHtmlNameEol | tagHtml with name parameter and EOL returns invalid HTML Strict
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<aside>
+'<aside></aside>
'
#1 /vagrant/webroot/vendor/phalcon/cphalcon/tests/_support/Verify.php:25
#2 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:165
#3 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:167
#4 /vagrant/webroot/vendor/phalcon/cphalcon/codecept.phar:7
---------
3) Phalcon\Tests\unit\Phalcon\Tag\TagTagHtmlTest::testTagHtmlWithArray | tagHtml with array parameter returns invalid HTML Strict
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<canvas id="canvas1" width="300" height="300">'
+'<canvas id="canvas1" width="300" height="300"></canvas>'
#1 /vagrant/webroot/vendor/phalcon/cphalcon/tests/_support/Verify.php:25
#2 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:209
#3 /vagrant/webroot/vendor/phalcon/cphalcon/tests/unit/Phalcon/Tag/TagTagHtmlTest.php:211
#4 /vagrant/webroot/vendor/phalcon/cphalcon/codecept.phar:7
so, is this difference in behavior intended? If so, why?