N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,13 +1,12 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Core\Sanitizer;
use HTMLDOMSanitizer;
use InlineImageMock;
require_once __DIR__.'/AbstractDOMSanitizerTest.php';
class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
{
/**
@@ -38,11 +37,11 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
public function DoSanitizeProvider()
{
return array(
array(
return [
[
'scripts.html',
),
);
],
];
}
/**
@@ -71,55 +70,55 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
{
// This is a copy of \HTMLDOMSanitizer::$aTagsWhiteList
// should stay a copy as we want to check we're not removing something by mistake as it was done with the CENTER tag (N°2558)
$aTagsWhiteList = array(
$aTagsWhiteList = [
// we don't test HTML and BODY as the parser removes them if context isn't appropriate
'a' => array('href', 'name', 'style', 'target', 'title'),
'p' => array('style'),
'blockquote' => array('style'),
'br' => array(),
'span' => array('style'),
'div' => array('style'),
'b' => array(),
'i' => array(),
'u' => array(),
'em' => array(),
'strong' => array(),
'img' => array('src', 'style', 'alt', 'title'),
'ul' => array('style'),
'ol' => array('reversed', 'start', 'style', 'type'),
'li' => array('style', 'value'),
'h1' => array('style'),
'h2' => array('style'),
'h3' => array('style'),
'h4' => array('style'),
'nav' => array('style'),
'section' => array('style'),
'code' => array('style'),
'table' => array('style', 'width', 'summary', 'align', 'border', 'cellpadding', 'cellspacing'),
'thead' => array('style'),
'tbody' => array('style'),
'tr' => array('style', 'colspan', 'rowspan'),
'td' => array('style', 'colspan', 'rowspan'),
'th' => array('style', 'colspan', 'rowspan'),
'fieldset' => array('style'),
'legend' => array('style'),
'font' => array('face', 'color', 'style', 'size'),
'big' => array(),
'small' => array(),
'tt' => array(),
'kbd' => array(),
'samp' => array(),
'var' => array(),
'del' => array(),
's' => array(), // strikethrough
'ins' => array(),
'cite' => array(),
'q' => array(),
'hr' => array('style'),
'pre' => array(),
'center' => array(),
);
$aTestCaseArray = array();
'a' => ['href', 'name', 'style', 'target', 'title'],
'p' => ['style'],
'blockquote' => ['style'],
'br' => [],
'span' => ['style'],
'div' => ['style'],
'b' => [],
'i' => [],
'u' => [],
'em' => [],
'strong' => [],
'img' => ['src', 'style', 'alt', 'title'],
'ul' => ['style'],
'ol' => ['reversed', 'start', 'style', 'type'],
'li' => ['style', 'value'],
'h1' => ['style'],
'h2' => ['style'],
'h3' => ['style'],
'h4' => ['style'],
'nav' => ['style'],
'section' => ['style'],
'code' => ['style'],
'table' => ['style', 'width', 'summary', 'align', 'border', 'cellpadding', 'cellspacing'],
'thead' => ['style'],
'tbody' => ['style'],
'tr' => ['style', 'colspan', 'rowspan'],
'td' => ['style', 'colspan', 'rowspan'],
'th' => ['style', 'colspan', 'rowspan'],
'fieldset' => ['style'],
'legend' => ['style'],
'font' => ['face', 'color', 'style', 'size'],
'big' => [],
'small' => [],
'tt' => [],
'kbd' => [],
'samp' => [],
'var' => [],
'del' => [],
's' => [], // strikethrough
'ins' => [],
'cite' => [],
'q' => [],
'hr' => ['style'],
'pre' => [],
'center' => [],
];
$aTestCaseArray = [];
$sInputText = $this->ReadTestFile('whitelist_test.html', self::INPUT_DIRECTORY);
foreach ($aTagsWhiteList as $sTag => $aTagAttributes) {
@@ -136,7 +135,7 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
$sClosingTag = $this->IsClosingTag($sTag) ? "</$sTag>" : '';
$sTestCaseText = str_replace('##END_TAG##', $sClosingTag, $sTestCaseText);
$aTestCaseArray[$sTag] = array($sTestCaseText);
$aTestCaseArray[$sTag] = [$sTestCaseText];
}
return $aTestCaseArray;
@@ -155,71 +154,71 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
public function RemoveBlackListedTagContentProvider()
{
return array(
'basic' => array(
return [
'basic' => [
'html' => 'foo<iframe>bar</iframe>baz',
'expected' => '<p>foobaz</p>',
),
'basic with body' => array(
],
'basic with body' => [
'html' => '<body>foo<iframe>bar</iframe>baz</body>',
'expected' => 'foobaz',
),
'basic with html and body tags' => array(
],
'basic with html and body tags' => [
'html' => '<html><body lang="EN-GB" link="#0563C1" vlink="#954F72">foo<iframe>bar</iframe>baz</body></html>',
'expected' => 'foobaz',
),
'basic with attributes' => array(
],
'basic with attributes' => [
'html' => 'foo<iframe baz="1">bar</iframe>baz',
'expected' => '<p>foobaz</p>',
),
'basic with comment' => array(
],
'basic with comment' => [
'html' => 'foo<iframe baz="1">bar<!-- foo --></iframe>baz',
'expected' => '<p>foobaz</p>',
),
'basic with contentRemovable tag' => array(
],
'basic with contentRemovable tag' => [
'html' => 'foo<iframe baz="1">bar<style>foo</style><script>boo</script></iframe>baz',
'expected' => '<p>foobaz</p>',
),
'nested' => array(
],
'nested' => [
'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(
],
'nested with not closed br' => [
'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(
],
'nested with allowed' => [
'html' => 'before<iframe><div><article><p>baz</p>zab</article></div>oof</iframe>after',
'expected' => '<p>beforeafter</p>',
),
'nested with spaces' => array(
],
'nested with spaces' => [
'html' => 'before<iframe><article>baz</article> oof</iframe>after',
'expected' => '<p>beforeafter</p>',
),
'nested with attributes' => array(
],
'nested with attributes' => [
'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(
],
'nested with allowed and attributes and spaces ' => [
'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(
],
'nested with allowed and contentRemovable tags' => [
'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(
'regression: if head present => body is not trimmed' => [
'html' => '<html><head></head><body lang="EN-GB" link="#0563C1" vlink="#954F72">bar</body></html>',
'expected' => 'bar',
),
'ordered list with attributes' => array(
],
'ordered list with attributes' => [
'html' => '<ol start="100" reversed="reversed" type="I" baz="1" biz="2"><li value="101" baz="1" biz="2">Some list item</li></ol>',
'expected' => '<ol start="100" reversed="reversed" type="I"><li value="101">Some list item</li></ol>',
),
);
],
];
}
/**
@@ -240,26 +239,25 @@ class HTMLDOMSanitizerTest extends AbstractDOMSanitizerTest
public function CallInlineImageProcessImageTagProvider()
{
return array(
'no image' => array(
return [
'no image' => [
'html' => '<p>bar</p>',
'expected' => 0,
),
'basic image' => array(
],
'basic image' => [
'html' => '<img />',
'expected' => 1,
),
'nested images within forbidden tags' => array(
],
'nested images within forbidden tags' => [
'html' => '<html><body><img /><iframe baz="1"><div baz="baz"><article baz="1" biz="2">baz<img /><img /></article>rab</div> oof<img /></iframe><img /></body></html>',
'expected' => 2,
),
],
// This test will be restored with the ticket n°2556
// 'nested images within forbidden and removed tags' => array(
// 'html' => '<html><body><img /><iframe baz="1"><div baz="baz"><object baz="1" biz="2">baz<img /><img /></object>rab</div> oof<img /></iframe><img /></body></html>',
// 'expected' => 2,
// ),
);
];
}
}