mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Add unit test.
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.
This commit is contained in:
@@ -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' => 'foo<iframe>bar</iframe>baz',
|
||||
'expected' => '<p>foobaz</p>',
|
||||
),
|
||||
'basic with body' => array(
|
||||
'html' => '<body>foo<iframe>bar</iframe>baz</body>',
|
||||
'expected' => 'foobaz',
|
||||
),
|
||||
'basic with html and body tags' => array(
|
||||
'html' => '<html><body lang="EN-GB" link="#0563C1" vlink="#954F72">foo<iframe>bar</iframe>baz</body></html>',
|
||||
'expected' => 'foobaz',
|
||||
),
|
||||
'basic with attributes' => array(
|
||||
'html' => 'foo<iframe baz="1">bar</iframe>baz',
|
||||
'expected' => '<p>foobaz</p>',
|
||||
),
|
||||
'basic with comment' => array(
|
||||
'html' => 'foo<iframe baz="1">bar<!-- foo --></iframe>baz',
|
||||
'expected' => '<p>foobaz</p>',
|
||||
),
|
||||
'basic with contentRemovable tag' => array(
|
||||
'html' => 'foo<iframe baz="1">bar<style>foo</style><script>boo</script></iframe>baz',
|
||||
'expected' => '<p>foobaz</p>',
|
||||
),
|
||||
'nested' => array(
|
||||
'html' => 'before<iframe>foo<article>baz</article>oof<article><iframe>bar</iframe>oof</article></iframe>after',
|
||||
'expected' => '<p>beforeafter</p>',
|
||||
),
|
||||
'nested with not closed br' => array(
|
||||
'html' => 'before<iframe>foo<article>baz</article>oof<br><article><iframe>bar</iframe>oof</article></iframe>after',
|
||||
'expected' => '<p>beforeafter</p>',
|
||||
),
|
||||
'nested with allowed' => array(
|
||||
'html' => 'before<iframe><div><article><p>baz</p>zab</article></div>oof</iframe>after',
|
||||
'expected' => '<p>beforeafter</p>',
|
||||
),
|
||||
'nested with spaces' => array(
|
||||
'html' => 'before<iframe><article>baz</article> oof</iframe>after',
|
||||
'expected' => '<p>beforeafter</p>',
|
||||
),
|
||||
'nested with attributes' => array(
|
||||
'html' => 'before<iframe baz="1"><article baz="1" biz="2">baz</article>oof</iframe>after',
|
||||
'expected' => '<p>beforeafter</p>',
|
||||
),
|
||||
'nested with allowed and attributes and spaces ' => array(
|
||||
'html' => '<html><body>before<iframe baz="1"><div baz="baz"><article baz="1" biz="2">baz</article>rab</div> oof</iframe>after</body></html>',
|
||||
'expected' => 'beforeafter',
|
||||
),
|
||||
'nested with allowed and contentRemovable tags' => array(
|
||||
'html' => '<html><body>before<iframe baz="1"><div ><article>baz</article>rab</div> oof<embed>embedTExt</embed></iframe>middle<style>foo</style>after<script>boo</script></body></html>',
|
||||
'expected' => 'beforemiddleafter',
|
||||
),
|
||||
|
||||
'regression: if head present => body is not trimmed' => array(
|
||||
'html' => '<html><head></head><body lang="EN-GB" link="#0563C1" vlink="#954F72">bar</body></html>',
|
||||
'expected' => 'bar',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user