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,4 +1,5 @@
<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 21/11/2019
@@ -7,7 +8,6 @@
namespace Combodo\iTop\Test\UnitTest\Module\AuthentLocal;
use AttributeDate;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Config;
@@ -27,7 +27,6 @@ use utils;
*/
class UserLocalTest extends ItopDataTestCase
{
public function setUp(): void
{
parent::setUp();
@@ -52,17 +51,16 @@ class UserLocalTest extends ItopDataTestCase
}
/** @var UserLocal $oUserLocal */
$oUserLocal = MetaModel::NewObject(UserLocal::class, array('login' => 'john'));
$oUserLocal = MetaModel::NewObject(UserLocal::class, ['login' => 'john']);
/** @var ormLinkSet $oProfileSet */
$oProfileSet = $oUserLocal->Get('profile_list');
$oProfileSet->AddItem(
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
MetaModel::NewObject(URP_UserProfile::class, ['profileid' => 1])
);
$aValidatorCollection = array();
foreach ($aValidatorNames as $class)
{
$aValidatorCollection = [];
foreach ($aValidatorNames as $class) {
$aValidatorCollection[] = new $class();
}
@@ -79,168 +77,167 @@ class UserLocalTest extends ItopDataTestCase
public function ProviderValidatePassword()
{
return array(
'validPattern' => array(
return [
'validPattern' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{1,10}'),
),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{1,10}'],
],
'expectedCheckStatus' => true,
),
'notValidPattern' => array(
],
'notValidPattern' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
],
'expectedCheckStatus' => false,
),
'noPattern' => array(
],
'noPattern' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '')
),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, ''],
],
'expectedCheckStatus' => true,
),
'validClass' => array(
],
'validClass' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockValid',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => true,
),
'notValidClass' => array(
],
'notValidClass' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockNotValid',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => false,
),
],
'validation_composition_10' => array(
'validation_composition_10' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockValid',
'UserLocalPasswordPolicyMockNotValid',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'UserLocalPasswordPolicyMockNotValid',
),
],
'validation_composition_01' => array(
'validation_composition_01' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockNotValid',
'UserLocalPasswordPolicyMockValid',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'UserLocalPasswordPolicyMockNotValid',
),
],
'validation_composition_11' => array(
'validation_composition_11' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockValid',
'UserLocalPasswordPolicyMockValidBis',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => true,
),
'validation_composition_00' => array(
],
'validation_composition_00' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserLocalPasswordPolicyMockNotValid',
'UserLocalPasswordPolicyMockNotValidBis',
),
'valueMap' => array(),
],
'valueMap' => [],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'UserLocalPasswordPolicyMockNotValid',
),
],
'notValidPattern custom message FR' => array(
'notValidPattern custom message FR' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('FR FR' => 'fr message', 'EN US' => 'en message')),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
['authent-local', 'password_validation.message', null, ['FR FR' => 'fr message', 'EN US' => 'en message']],
),
],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'fr message',
'userLanguage' => 'FR FR',
),
'notValidPattern custom message EN' => array(
],
'notValidPattern custom message EN' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('FR FR' => 'fr message', 'EN US' => 'en message')),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
['authent-local', 'password_validation.message', null, ['FR FR' => 'fr message', 'EN US' => 'en message']],
),
],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'en message',
'userLanguage' => 'EN US',
),
'notValidPattern custom message Fallback' => array(
],
'notValidPattern custom message Fallback' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array('EN US' => 'en message')),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
['authent-local', 'password_validation.message', null, ['EN US' => 'en message']],
),
],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'en message',
'userLanguage' => 'FR FR',
),
'notValidPattern custom message empty array' => array(
],
'notValidPattern custom message empty array' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, array()),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
['authent-local', 'password_validation.message', null, []],
),
],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'Password must be at least 8 characters and include uppercase, lowercase, numeric and special characters.',
'userLanguage' => 'EN US',
),
'notValidPattern custom message string not array' => array(
],
'notValidPattern custom message string not array' => [
'password' => 'foo',
'aValidatorCollection' => array(
'aValidatorCollection' => [
'UserPasswordPolicyRegex',
),
'valueMap' => array(
array('authent-local', 'password_validation.pattern', null, '.{6,10}'),
array('authent-local', 'password_validation.message', null, 'not an array'),
],
'valueMap' => [
['authent-local', 'password_validation.pattern', null, '.{6,10}'],
['authent-local', 'password_validation.message', null, 'not an array'],
),
],
'expectedCheckStatus' => false,
'expectedCheckIssues' => 'not an array',
'userLanguage' => 'EN US',
),
);
],
];
}
/**
@@ -254,9 +251,8 @@ class UserLocalTest extends ItopDataTestCase
$oNow = date($sDateFormat);
$oExpectedAfter = is_null($sExpectedAfter) ? null : date($sDateFormat, strtotime($sExpectedAfter));
$aUserLocalValues = array('login' => 'john');
if (!is_null($oBefore))
{
$aUserLocalValues = ['login' => 'john'];
if (!is_null($oBefore)) {
$aUserLocalValues['password_renewed_date'] = $oBefore;
}
@@ -266,7 +262,7 @@ class UserLocalTest extends ItopDataTestCase
$oProfileSet = $oUserLocal->Get('profile_list');
$oProfileSet->AddItem(
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
MetaModel::NewObject(URP_UserProfile::class, ['profileid' => 1])
);
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'));
@@ -298,20 +294,20 @@ class UserLocalTest extends ItopDataTestCase
public function ProviderPasswordRenewal()
{
return array(
'nominal case' => array(
return [
'nominal case' => [
'oExpectedBefore' => null,
'oExpectedAfter' => 'now',
),
'date initiated' => array(
],
'date initiated' => [
'oBefore' => '-1 day',
'oExpectedAfter' => 'now',
),
'date initiated in the future' => array(
],
'date initiated in the future' => [
'oBefore' => '+1 day',
'oExpectedAfter' => 'now',
),
);
],
];
}
/**
@@ -324,9 +320,8 @@ class UserLocalTest extends ItopDataTestCase
$oNow = date(AttributeDate::GetInternalFormat());
$oExpectedAfter = $bRenewedDateTouched ? $oNow : $oBefore;
$aUserLocalValues = array('login' => 'john');
if (!is_null($oBefore))
{
$aUserLocalValues = ['login' => 'john'];
if (!is_null($oBefore)) {
$aUserLocalValues['password_renewed_date'] = $oBefore;
}
@@ -336,7 +331,7 @@ class UserLocalTest extends ItopDataTestCase
$oProfileSet = $oUserLocal->Get('profile_list');
$oProfileSet->AddItem(
MetaModel::NewObject(URP_UserProfile::class, array('profileid' => 1))
MetaModel::NewObject(URP_UserProfile::class, ['profileid' => 1])
);
$this->assertEquals($oBefore, $oUserLocal->Get('password_renewed_date'));
@@ -360,38 +355,38 @@ class UserLocalTest extends ItopDataTestCase
public function CanExpireFixProvider()
{
return array(
'EXPIRE_CAN: nominal case' => array(
return [
'EXPIRE_CAN: nominal case' => [
'sExpirationMode' => 'can_expire',
'oExpectedBefore' => null,
'bRenewedDateTouched' => true,
),
'EXPIRE_NEVER (default mode): nothing changed on UserLocal' => array(
],
'EXPIRE_NEVER (default mode): nothing changed on UserLocal' => [
'sExpirationMode' => 'never_expire',
'oExpectedBefore' => null,
'bRenewedDateTouched' => false,
),
'EXPIRE_FORCE: nominal case' => array(
],
'EXPIRE_FORCE: nominal case' => [
'sExpirationMode' => 'force_expire',
'oExpectedBefore' => null,
'bRenewedDateTouched' => true,
),
'EXPIRE_ONE_TIME_PWD: nominal case' => array(
],
'EXPIRE_ONE_TIME_PWD: nominal case' => [
'sExpirationMode' => 'otp_expire',
'oExpectedBefore' => null,
'bRenewedDateTouched' => true,
),
'date initiated' => array(
],
'date initiated' => [
'sExpirationMode' => 'can_expire',
'oBefore' => '-1 day',
'bRenewedDateTouched' => false,
),
'date initiated in the future' => array(
],
'date initiated in the future' => [
'sExpirationMode' => 'can_expire',
'oBefore' => '+1 day',
'bRenewedDateTouched' => false,
),
);
],
];
}
/**
@@ -454,4 +449,3 @@ class UserLocalTest extends ItopDataTestCase
return $oUser->Get('profile_list');
}
}