From be20705449e360b5b664f50c5f9ea2b98f5a2b85 Mon Sep 17 00:00:00 2001 From: bruno DA SILVA Date: Mon, 22 Jun 2020 16:13:31 +0200 Subject: [PATCH] Add unit test. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit unit test the behaviour of the removal of the blacklisted html tags this is in fact an adaptation of the test added for the rolled-back feature of the n°2556. This feature has been postponed to the 2.8 due to performance scaling issues. --- test/core/HTMLDOMSanitizerTest.php | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/core/HTMLDOMSanitizerTest.php b/test/core/HTMLDOMSanitizerTest.php index 004b1cc74..e5c74db1a 100644 --- a/test/core/HTMLDOMSanitizerTest.php +++ b/test/core/HTMLDOMSanitizerTest.php @@ -202,5 +202,80 @@ class HTMLDOMSanitizerTest extends ItopTestCase return true; } + + /** + * @dataProvider RemoveBlackListedTagContentProvider + */ + public function testDoSanitizeRemoveBlackListedTagContent($html, $expected) + { + $oSanitizer = new HTMLDOMSanitizer(); + $sSanitizedHtml = $oSanitizer->DoSanitize($html); + + $this->assertEquals($expected, str_replace("\n", '', $sSanitizedHtml)); + } + + public function RemoveBlackListedTagContentProvider() + { + return array( + 'basic' => array( + 'html' => 'foobaz', + 'expected' => '

foobaz

', + ), + 'basic with body' => array( + 'html' => 'foobaz', + 'expected' => 'foobaz', + ), + 'basic with html and body tags' => array( + 'html' => 'foobaz', + 'expected' => 'foobaz', + ), + 'basic with attributes' => array( + 'html' => 'foobaz', + 'expected' => '

foobaz

', + ), + 'basic with comment' => array( + 'html' => 'foobaz', + 'expected' => '

foobaz

', + ), + 'basic with contentRemovable tag' => array( + 'html' => 'foobaz', + 'expected' => '

foobaz

', + ), + 'nested' => array( + 'html' => 'beforeoofafter', + 'expected' => '

beforeafter

', + ), + 'nested with not closed br' => array( + 'html' => 'beforeoofafter', + 'expected' => '

beforeafter

', + ), + 'nested with allowed' => array( + 'html' => 'beforeafter', + 'expected' => '

beforeafter

', + ), + 'nested with spaces' => array( + 'html' => 'beforeafter', + 'expected' => '

beforeafter

', + ), + 'nested with attributes' => array( + 'html' => 'beforeafter', + 'expected' => '

beforeafter

', + ), + 'nested with allowed and attributes and spaces ' => array( + 'html' => 'beforeafter', + 'expected' => 'beforeafter', + ), + 'nested with allowed and contentRemovable tags' => array( + 'html' => 'beforemiddleafter', + 'expected' => 'beforemiddleafter', + ), + + 'regression: if head present => body is not trimmed' => array( + 'html' => 'bar', + 'expected' => 'bar', + ), + ); + } + }