2
0
forked from Wavyzz/dolibarr

FIX empty with hasRight and add phpunit to avoid this in future

This commit is contained in:
Laurent Destailleur
2022-08-14 16:38:20 +02:00
parent 0bd33ae338
commit 72c010622b
8 changed files with 36 additions and 25 deletions

View File

@@ -513,7 +513,7 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
$this->assertTrue($ok, 'Found a forbidden string sequence into '.$file['relativename'].' : name="token" value="\'.$_SESSION[..., you must use a newToken() instead of $_SESSION[\'newtoken\'].');
// Test we don't have @var array(
// Test we don't have preg_grep with a param without preg_quote
$ok=true;
$matches=array();
preg_match_all('/preg_grep\(.*\$/', $filecontent, $matches, PREG_SET_ORDER);
@@ -526,6 +526,17 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
$this->assertTrue($ok, 'Found a preg_grep with a param that is a $var but without preg_quote in file '.$file['relativename'].'.');
// Test we don't have empty($user->hasRight
$ok=true;
$matches=array();
preg_match_all('/empty\(\$user->hasRight/', $filecontent, $matches, PREG_SET_ORDER);
foreach ($matches as $key => $val) {
$ok=false;
break;
}
$this->assertTrue($ok, 'Found code empty($user->hasRight in file '.$file['relativename'].'. empty() must not be used with hasRight.');
// Test we don't have @var array(
$ok=true;
$matches=array();