From: Tim Düsterhus
+ By default, HTML Purifier removes duplicate CSS properties,
+ like color:red; color:blue
. If this is set to
+ true, duplicate properties are allowed.
+
+ In HTML Purifier 4.8.0, this also supports NULL
,
+ which means that no chmod'ing or directory creation shall
+ occur.
+
Hello
'); - $emogrifiedHtml = $this->subject->emogrify(); + $result = $this->subject->emogrify(); - self::assertContains( - '', - $emogrifiedHtml - ); + self::assertContains('', $result); } /** @@ -118,12 +115,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase { $this->subject->setHtml('World
'); - $emogrifiedHtml = $this->subject->emogrify(); + $result = $this->subject->emogrify(); - self::assertContains( - '', - $emogrifiedHtml - ); + self::assertContains('', $result); } /** @@ -133,12 +127,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase { $this->subject->setHtml('Hello
'); - $emogrifiedHtml = $this->subject->emogrify(); + $result = $this->subject->emogrify(); - self::assertContains( - '', - $emogrifiedHtml - ); + self::assertContains('', $result); } /** @@ -148,12 +139,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase { $this->subject->setHtml('World
'); - $emogrifiedHtml = $this->subject->emogrify(); + $result = $this->subject->emogrify(); - self::assertContains( - '', - $emogrifiedHtml - ); + self::assertContains('', $result); } /** @@ -162,14 +150,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsDollarSignsAndSquareBrackets() { $templateMarker = '$[USER:NAME]$'; - $html = $this->html5DocumentType . '' . $templateMarker . '
'; $this->subject->setHtml($html); - self::assertContains( - $templateMarker, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($templateMarker, $result); } /** @@ -178,14 +164,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsInHtml5() { $umlautString = 'Küss die Hand, schöne Frau.'; - $html = $this->html5DocumentType . '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -194,14 +178,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsInXhtml() { $umlautString = 'Ãösel läks õunu täis ämber uhkelt ümber.'; - $html = $this->xhtml1StrictDocumentType . '' . $umlautString . ''; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -210,15 +192,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsInHtml4() { $umlautString = 'Ãösel läks õunu täis ämber uhkelt ümber.'; - $html = $this->html4TransitionalDocumentType . '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -227,14 +206,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsHtmlEntities() { $entityString = 'a & b > c'; - $html = $this->html5DocumentType . '' . $entityString . '
'; $this->subject->setHtml($html); - self::assertContains( - $entityString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($entityString, $result); } /** @@ -243,14 +220,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsHtmlEntitiesInXhtml() { $entityString = 'a & b > c'; - $html = $this->xhtml1StrictDocumentType . '' . $entityString . ''; $this->subject->setHtml($html); - self::assertContains( - $entityString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($entityString, $result); } /** @@ -259,15 +234,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsHtmlEntitiesInHtml4() { $entityString = 'a & b > c'; - $html = $this->html4TransitionalDocumentType . '' . $entityString . '
'; $this->subject->setHtml($html); - self::assertContains( - $entityString, - $entityString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($entityString, $result); } /** @@ -276,14 +248,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsWithoutDocumentType() { $umlautString = 'Küss die Hand, schöne Frau.'; - $html = '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -292,14 +262,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsWithoutDocumentTypeAndWithoutHtmlAndWithoutHead() { $umlautString = 'Küss die Hand, schöne Frau.'; - $html = '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -308,14 +276,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsWithoutDocumentTypeAndWithHtmlAndWithoutHead() { $umlautString = 'Küss die Hand, schöne Frau.'; - $html = '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -324,14 +290,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase public function emogrifyKeepsUtf8UmlautsWithoutDocumentTypeAndWithoutHtmlAndWithHead() { $umlautString = 'Küss die Hand, schöne Frau.'; - $html = '' . $umlautString . '
'; $this->subject->setHtml($html); - self::assertContains( - $umlautString, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($umlautString, $result); } /** @@ -343,10 +307,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $this->subject->setHtml($html); $this->subject->setCss(''); - self::assertContains( - $this->html5DocumentType, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($this->html5DocumentType, $result); } /** @@ -357,10 +320,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $html = $this->xhtml1StrictDocumentType . ''; $this->subject->setHtml($html); - self::assertContains( - $this->xhtml1StrictDocumentType, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($this->xhtml1StrictDocumentType, $result); } /** @@ -371,10 +333,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $html = $this->html5DocumentType . ''; $this->subject->setHtml($html); - self::assertContains( - $this->html5DocumentType, - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains($this->html5DocumentType, $result); } /** @@ -385,10 +346,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $html = $this->html5DocumentType . 'Hello
'; $this->subject->setHtml($html); - self::assertContains( - '', - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains('', $result); } /** @@ -402,10 +362,8 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $this->subject->setHtml($html); $numberOfContentTypeMetaTags = substr_count($this->subject->emogrify(), 'Content-Type'); - self::assertSame( - 1, - $numberOfContentTypeMetaTags - ); + + self::assertSame(1, $numberOfContentTypeMetaTags); } /** @@ -416,10 +374,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $html = $this->html5DocumentType . 'foo', - $this->subject->emogrify() - ); + $this->subject->addUnprocessableHtmlTag('p'); + $result = $this->subject->emogrify(); + + self::assertNotContains('
', $result); } /** @@ -443,15 +398,13 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase */ public function addUnprocessableTagNotRemovesGivenTagWithContent() { - $this->subject->addUnprocessableHtmlTag('p'); - $html = $this->html5DocumentType . '
foobar
'; $this->subject->setHtml($html); - self::assertContains( - '', - $this->subject->emogrify() - ); + $this->subject->addUnprocessableHtmlTag('p'); + $result = $this->subject->emogrify(); + + self::assertContains('
', $result); } /** @@ -459,16 +412,14 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase */ public function removeUnprocessableHtmlTagCausesTagToStayAgain() { - $this->subject->addUnprocessableHtmlTag('p'); - $this->subject->removeUnprocessableHtmlTag('p'); - $html = $this->html5DocumentType . '
foo
bar
', - $this->subject->emogrify() - ); + $this->subject->addUnprocessableHtmlTag('p'); + $this->subject->removeUnprocessableHtmlTag('p'); + $result = $this->subject->emogrify(); + + self::assertContains('
', $result); } /** @@ -481,9 +432,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $styleRule = 'color: #000;'; $this->subject->setCss('html {' . $styleRule . '}'); + $result = $this->subject->emogrify(); + self::assertContains( '', - $this->subject->emogrify() + $result ); } @@ -496,10 +449,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $this->subject->setHtml($html); $this->subject->setCss('p {color:#000;}'); - self::assertContains( - '', - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains('', $result); } /** @@ -512,9 +464,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $styleRule = 'color: #000;'; $this->subject->setCss('p {' . $styleRule . '}'); + $result = $this->subject->emogrify(); + self::assertSame( 2, - substr_count($this->subject->emogrify(), '
') + substr_count($result, '
') ); } @@ -526,12 +480,14 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $html = $this->html5DocumentType . '
'; $this->subject->setHtml($html); $styleRulesIn = 'color:#000; text-align:left;'; - $styleRulesOut = 'color: #000; text-align: left;'; $this->subject->setCss('p {' . $styleRulesIn . '}'); + $result = $this->subject->emogrify(); + + $styleRulesOut = 'color: #000; text-align: left;'; self::assertContains( '', - $this->subject->emogrify() + $result ); } @@ -544,10 +500,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $this->subject->setHtml($html); $this->subject->setCss('[hidden] { color:red; }'); - self::assertContains( - '
', - $this->subject->emogrify() - ); + $result = $this->subject->emogrify(); + + self::assertContains('
', $result); } /** @@ -561,9 +516,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $styleRule2 = 'text-align: left;'; $this->subject->setCss('p {' . $styleRule1 . '} p {' . $styleRule2 . '}'); + $result = $this->subject->emogrify(); + self::assertContains( '
', - $this->subject->emogrify() + $result ); } @@ -578,9 +535,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase $styleRule2 = 'text-align: left;'; $this->subject->setCss('p {' . $styleRule1 . '} .x {' . $styleRule2 . '}'); + $result = $this->subject->emogrify(); + self::assertContains( '
',
- $this->subject->emogrify()
+ $result
);
}
@@ -611,9 +570,13 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
=> ['body span {' . $styleRule . '} ', '##'],
'child selector P > SPAN matches direct child'
=> ['p > span {' . $styleRule . '} ', '##'],
- 'child selector BODY > SPAN not matches grandchild'
+ 'child selector P > SPAN matches direct child without space after >'
+ => ['p >span {' . $styleRule . '} ', '##'],
+ 'child selector P > SPAN matches direct child without space before >'
+ => ['p> span {' . $styleRule . '} ', '##'],
+ 'child selector BODY > SPAN does not match grandchild'
=> ['body > span {' . $styleRule . '} ', '##'],
- 'adjacent selector P + P not matches first P' => ['p + p {' . $styleRule . '} ', '# #'],
+ 'adjacent selector P + P does not match first P' => ['p + p {' . $styleRule . '} ', '# #'],
'adjacent selector P + P matches second P'
=> ['p + p {' . $styleRule . '} ', '# #'],
'adjacent selector P + P matches third P'
@@ -626,7 +589,7 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
=> ['p.p-1 {' . $styleRule . '} ', '# #'],
'attribute presence selector SPAN[title] matches element with matching attribute'
=> ['span[title] {' . $styleRule . '} ', '##'],
- 'attribute presence selector SPAN[title] not matches element without any attributes'
+ 'attribute presence selector SPAN[title] does not match element without any attributes'
=> ['span[title] {' . $styleRule . '} ', '##'],
'attribute value selector [id="html"] matches element with matching attribute value' => [
'[id="html"] {' . $styleRule . '} ', '##'
@@ -634,21 +597,85 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
'attribute value selector SPAN[title] matches element with matching attribute value' => [
'span[title="bonjour"] {' . $styleRule . '} ', '##'
],
- 'attribute value selector SPAN[title] not matches element with other attribute value'
+ 'attribute value selector SPAN[title] matches element with matching attribute value two words' => [
+ 'span[title="buenas dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title] matches element with matching attribute value four words' => [
+ 'span[title="buenas dias bom dia"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title~] matches element with an attribute value with just that word' => [
+ 'span[title~="bonjour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title~] matches element with attribute value with that word as 2nd of 2' => [
+ 'span[title~="dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title~] matches element with attribute value with that word as 1st of 2' => [
+ 'span[title~="buenas"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title*] matches element with an attribute value with just that word' => [
+ 'span[title*="bonjour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title*] matches element with attribute value with that word as 2nd of 2' => [
+ 'span[title*="dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title*] matches element with an attribute value with parts two words' => [
+ 'span[title*="enas di"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title^] matches element with attribute value that is exactly that word' => [
+ 'span[title^="bonjour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title^] matches element with an attribute value that begins that word' => [
+ 'span[title^="bonj"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title^] matches element with an attribute value that begins that word '
+ . 'and contains other words' => [
+ 'span[title^="buenas"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title$] matches element with attribute value that is exactly that word' => [
+ 'span[title$="bonjour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title$] matches element with an attribute value with two words' => [
+ 'span[title$="buenas dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title$] matches element with an attribute value that end that word' => [
+ 'span[title$="jour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title$] matches element with an attribute value that end that word '
+ . 'and contains other words' => [
+ 'span[title$="dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title|] matches element with attribute value that is exactly that word' => [
+ 'span[title|="bonjour"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title|] matches element with an attribute value with two words' => [
+ 'span[title|="buenas dias"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title|] matches element with an attribute value with 2 words with hypen' => [
+ 'span[title|="avez"] {' . $styleRule . '} ', '##'
+ ],
+ 'attribute value selector SPAN[title] does not match element with other attribute value'
=> ['span[title="bonjour"] {' . $styleRule . '} ', '##'],
- 'attribute value selector SPAN[title] not matches element without any attributes'
+ 'attribute value selector SPAN[title] does not match element without any attributes'
=> ['span[title="bonjour"] {' . $styleRule . '} ', '##'],
- 'BODY:first-child matches first child'
- => ['body:first-child {' . $styleRule . '} ', '# #'],
- 'BODY:first-child not matches middle child'
- => ['body:first-child {' . $styleRule . '} ', '# #'],
- 'BODY:first-child not matches last child'
- => ['body:first-child {' . $styleRule . '} ', '# #'],
- 'BODY:last-child not matches first child' => ['body:last-child {' . $styleRule . '} ', '# #'],
- 'BODY:last-child not matches middle child'
- => ['body:last-child {' . $styleRule . '} ', '# #'],
- 'BODY:last-child matches last child'
- => ['body:last-child {' . $styleRule . '} ', '# #'],
+ 'P:first-child matches first child with matching tag'
+ => ['p:first-child {' . $styleRule . '} ', '# #'],
+ 'DIV:first-child does not match first child with mismatching tag'
+ => ['div:first-child {' . $styleRule . '} ', '# #'],
+ 'P:first-child does not match middle child'
+ => ['p:first-child {' . $styleRule . '} ', '# #'],
+ 'P:first-child does not match last child'
+ => ['p:first-child {' . $styleRule . '} ', '# #'],
+ 'P:last-child does not match first child' => ['p:last-child {' . $styleRule . '} ', '# #'],
+ 'P:last-child does not match middle child'
+ => ['p:last-child {' . $styleRule . '} ', '# #'],
+ 'P:last-child matches last child'
+ => ['p:last-child {' . $styleRule . '} ', '# #'],
+ 'DIV:last-child does not match last child with mismatching tag'
+ => ['div:last-child {' . $styleRule . '} ', '# #'],
];
}
@@ -668,6 +695,8 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
' some text some text some more text some more text some more text target target target paragraph ';
$this->subject->setHtml($html);
$this->subject->disableStyleBlocksParsing();
+ $result = $this->subject->emogrify();
+
self::assertContains(
- $expected,
- $this->subject->emogrify()
+ ' ',
+ $result
);
}
@@ -1370,10 +1413,9 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
$this->subject->setHtml($html);
$this->subject->disableInlineStyleAttributesParsing();
- self::assertNotContains(
- 'subject->emogrify()
- );
+ $result = $this->subject->emogrify();
+
+ self::assertNotContains('html5DocumentType .
' paragraph ';
$this->subject->setHtml($html);
$this->subject->disableInlineStyleAttributesParsing();
+ $result = $this->subject->emogrify();
+
self::assertContains(
- $expected,
- $this->subject->emogrify()
+ ' ',
+ $result
);
}
@@ -1402,13 +1445,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
{
$html = $this->html5DocumentType .
' paragraph ';
$this->subject->setHtml($html);
- self::assertContains(
- $expected,
- $this->subject->emogrify()
- );
+ $result = $this->subject->emogrify();
+
+ self::assertContains(' ', $result);
}
/**
@@ -1420,13 +1461,11 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
$html = $this->html5DocumentType .
' some content ';
$this->subject->setHtml($html);
- self::assertContains(
- $expected,
- $this->subject->emogrify()
- );
+ $result = $this->subject->emogrify();
+
+ self::assertContains(' ', $result);
}
/**
@@ -1439,13 +1478,14 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
$html = $this->html5DocumentType .
' some content ';
$this->subject->setHtml($html);
$this->subject->setCss($css);
+ $result = $this->subject->emogrify();
+
self::assertContains(
- $expected,
- $this->subject->emogrify()
+ ' ',
+ $result
);
}
@@ -1458,14 +1498,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
$html = $this->html5DocumentType .
' some content ';
$this->subject->setHtml($html);
$this->subject->setCss($css);
- self::assertContains(
- $expected,
- $this->subject->emogrify()
- );
+ $result = $this->subject->emogrify();
+
+ self::assertContains(' ', $result);
}
/**
@@ -1475,16 +1513,12 @@ class EmogrifierTest extends \PHPUnit_Framework_TestCase
{
$css = 'div.foo { display: none; }';
$html = $this->html5DocumentType . '