0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 18:55:19 +00:00

Update ExtractStyleBlocks tests for modern CSSTidy at https://github.com/Cerdic/CSSTidy

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
This commit is contained in:
Edward Z. Yang 2016-03-23 23:39:38 -07:00
parent 45161b4fb1
commit 72123e23c9
2 changed files with 30 additions and 27 deletions

View File

@ -29,7 +29,10 @@ These optional extensions can enhance the capabilities of HTML Purifier:
These optional libraries can enhance the capabilities of HTML Purifier: These optional libraries can enhance the capabilities of HTML Purifier:
* CSSTidy : Clean CSS stylesheets using %Core.ExtractStyleBlocks * CSSTidy : Clean CSS stylesheets using %Core.ExtractStyleBlocks
Note: You should use the modernized fork of CSSTidy available
at https://github.com/Cerdic/CSSTidy
* Net_IDNA2 (PEAR) : IRI support using %Core.EnableIDNA * Net_IDNA2 (PEAR) : IRI support using %Core.EnableIDNA
Note: This is not necessary for PHP 5.3 or later
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
2. Reconnaissance 2. Reconnaissance

View File

@ -15,8 +15,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
$this->assertIdentical($result, 'Test'); $this->assertIdentical($result, 'Test');
$this->assertIdentical($purifier->context->get('StyleBlocks'), $this->assertIdentical($purifier->context->get('StyleBlocks'),
array( array(
".foo {\ntext-align:center;\n}", ".foo {\ntext-align:center\n}",
"* {\nfont-size:12pt;\n}" "* {\nfont-size:12pt\n}"
) )
); );
} }
@ -85,7 +85,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
public function test_cleanCSS_selector() public function test_cleanCSS_selector()
{ {
$this->assertCleanCSS("a .foo #id div.cl#foo {\nfont-weight:700;\n}"); $this->assertCleanCSS("a .foo #id div.cl#foo {\nfont-weight:700\n}");
} }
public function test_cleanCSS_angledBrackets() public function test_cleanCSS_angledBrackets()
@ -110,7 +110,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
public function test_cleanCSS_bogus() public function test_cleanCSS_bogus()
{ {
$this->assertCleanCSS("div {bogus:tree;}", "div {\n}"); $this->assertCleanCSS("div {bogus:tree}", "div {\n}");
} }
/* [CONTENT] /* [CONTENT]
@ -134,8 +134,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS( $this->assertCleanCSS(
"p {\ntext-indent:1em;\n}", "p {\ntext-indent:1em\n}",
"#foo p {\ntext-indent:1em;\n}" "#foo p {\ntext-indent:1em\n}"
); );
} }
@ -143,29 +143,29 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS( $this->assertCleanCSS(
"b, i {\ntext-decoration:underline;\n}", "b, i {\ntext-decoration:underline\n}",
"#foo b, #foo i {\ntext-decoration:underline;\n}" "#foo b, #foo i {\ntext-decoration:underline\n}"
); );
} }
public function test_cleanCSS_scopeWithNaughtySelector() public function test_cleanCSS_scopeWithNaughtySelector()
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" + p {\ntext-indent:1em;\n}", ''); $this->assertCleanCSS(" + p {\ntext-indent:1em\n}", "#foo p {\ntext-indent:1em\n}");
} }
public function test_cleanCSS_scopeWithMultipleNaughtySelectors() public function test_cleanCSS_scopeWithMultipleNaughtySelectors()
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo');
$this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em;\n}", ''); $this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em\n}", "#foo p {\ntext-indent:1em\n}");
} }
public function test_cleanCSS_scopeWithCommas() public function test_cleanCSS_scopeWithCommas()
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS( $this->assertCleanCSS(
"p {\ntext-indent:1em;\n}", "p {\ntext-indent:1em\n}",
"#foo p, .bar p {\ntext-indent:1em;\n}" "#foo p, .bar p {\ntext-indent:1em\n}"
); );
} }
@ -173,8 +173,8 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
{ {
$this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar'); $this->config->set('Filter.ExtractStyleBlocks.Scope', '#foo, .bar');
$this->assertCleanCSS( $this->assertCleanCSS(
"p, div {\ntext-indent:1em;\n}", "p, div {\ntext-indent:1em\n}",
"#foo p, .bar p, #foo div, .bar div {\ntext-indent:1em;\n}" "#foo p, .bar p, #foo div, .bar div {\ntext-indent:1em\n}"
); );
} }
@ -183,19 +183,19 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness
$this->config->set('Filter.ExtractStyleBlocks.Scope', 'p'); $this->config->set('Filter.ExtractStyleBlocks.Scope', 'p');
$this->assertCleanCSS( $this->assertCleanCSS(
"div { "div {
text-align:right; text-align:right
} }
p div { p div {
text-align:left; text-align:left
}", }",
"p div { "p div {
text-align:right; text-align:right
} }
p p div { p p div {
text-align:left; text-align:left
}" }"
); );
} }
@ -205,11 +205,11 @@ text-align:left;
$this->assertCleanCSS( $this->assertCleanCSS(
"<!-- "<!--
div { div {
text-align:right; text-align:right
} }
-->", -->",
"div { "div {
text-align:right; text-align:right
}" }"
); );
} }
@ -218,7 +218,7 @@ text-align:right;
{ {
$this->assertCleanCSS( $this->assertCleanCSS(
"{ "{
b { text-align: center; } b { text-align: center }
}", }",
"" ""
); );
@ -228,24 +228,24 @@ text-align:right;
{ {
$this->assertCleanCSS( $this->assertCleanCSS(
"&, & { "&, & {
text-align: center; text-align: center
}", }",
"" ""
); );
$this->assertCleanCSS( $this->assertCleanCSS(
"&, b { "&, b {
text-align:center; text-align:center
}", }",
"b { "b {
text-align:center; text-align:center
}" }"
); );
$this->assertCleanCSS( $this->assertCleanCSS(
"& a #foo:hover.bar +b > i { "& a #foo:hover.bar +b > i {
text-align:center; text-align:center
}", }",
"a #foo:hover.bar + b \\3E i { "a #foo:hover.bar + b \\3E i {
text-align:center; text-align:center
}" }"
); );
$this->assertCleanCSS("doesnt-exist { text-align:center }", ""); $this->assertCleanCSS("doesnt-exist { text-align:center }", "");
@ -253,7 +253,7 @@ text-align:center;
public function test_cleanCSS_caseSensitive() public function test_cleanCSS_caseSensitive()
{ {
$this->assertCleanCSS("a .foo #ID div.cl#foo {\nbackground:url(\"http://foo/BAR\");\n}"); $this->assertCleanCSS("a .foo #ID div.cl#foo {\nbackground:url(\"http://foo/BAR\")\n}");
} }
} }