From 30a3339653007be1d562c6d21ed9b569c716ab0f Mon Sep 17 00:00:00 2001 From: Klaus Weidenbach Date: Tue, 21 Mar 2017 00:13:43 +0100 Subject: :white_check_mark: Some more tests for purify_html(). Add some generic HTML, JS, CSS expectations for purify_html(). Also cover our own configuration for HTMLPurifier. --- tests/unit/includes/TextTest.php | 57 ++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'tests/unit/includes/TextTest.php') diff --git a/tests/unit/includes/TextTest.php b/tests/unit/includes/TextTest.php index 2b4cb19ea..85ed6a4fd 100644 --- a/tests/unit/includes/TextTest.php +++ b/tests/unit/includes/TextTest.php @@ -5,7 +5,7 @@ namespace Zotlabs\Tests\Unit\includes; use Zotlabs\Tests\Unit\UnitTestCase; /** - * @brief Unit Test case for texter. + * @brief Unit Test case for include/texter.php file. * * @author ken restivo */ @@ -24,14 +24,55 @@ class TextTest extends UnitTestCase { } public function testPurifyHTML() { - $html = '

text
b

'; - $html_expect = '

text
b

'; - $html5elements = '
section
'; - $htmldata = '
text
'; + // linebreaks + $htmlbr = 'first line
+ one tab preserved + +empty line above'; + $this->assertEquals($htmlbr, purify_html($htmlbr)); - $this->assertEquals($html_expect, purify_html($html)); + // HTML5 is not supported by HTMLPurifier yet, test our own configuration + $html5elements = '
section
'; $this->assertEquals($html5elements, purify_html($html5elements)); - $this->assertEquals($htmldata, purify_html($htmldata)); + $this->assertEquals('', purify_html('')); + + // preserve f6 and bootstrap additional data attributes from our own configuration + $this->assertEquals('
text
', purify_html('
text
')); + $this->assertEquals('', purify_html('')); + $this->assertEquals('', purify_html('')); + } + + public function testPurifyHTML_html() { + $this->assertEquals('

ids und classes

', purify_html('

ids und classes

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

close missing tags

', purify_html('

close missing tags')); + $this->assertEquals('

deprecated tag
', purify_html('
deprecated tag
')); + $this->assertEquals('
illegal nesting
', purify_html('
illegal nesting
')); + $this->assertEquals('link with target', purify_html('link with target')); + $this->assertEquals('link with rel="nofollow"', purify_html('link with rel="nofollow"')); + $this->assertEquals('a b', purify_html('a b')); + $this->assertEquals('ä ä € €', purify_html('ä ä € €')); } -} + public function testPurifyHTML_js() { + $this->assertEquals('
', purify_html('
')); + $this->assertEquals('link', purify_html('link')); + $this->assertEquals('', purify_html('')); + $this->assertEquals('', purify_html('')); + } + + public function testPurifyHTML_css() { + $this->assertEquals('

red

', purify_html('

red

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

invalid color

', purify_html('

invalid color

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

invalid style

', purify_html('

invalid style

')); + + // test our own CSS configuration + $this->assertEquals('
position removed
', purify_html('
position removed
')); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + + $this->assertEquals('
position removed
', purify_html('
position removed
')); + $this->assertEquals('
position preserved
', purify_html('
position preserved
', true)); + $this->assertEquals('
invalid position removed
', purify_html('
invalid position removed
', true)); + } + +} -- cgit v1.2.3