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');
}
}

View File

@@ -1,8 +1,9 @@
<?php
class UserLocalPasswordPolicyMockValid implements \UserLocalPasswordValidator
{
const CHECK_STATUS = true;
const MESSAGE = null;
public const CHECK_STATUS = true;
public const MESSAGE = null;
public function __construct()
{
@@ -23,8 +24,8 @@ class UserLocalPasswordPolicyMockValid implements \UserLocalPasswordValidator
class UserLocalPasswordPolicyMockNotValid extends UserLocalPasswordPolicyMockValid
{
const CHECK_STATUS = false;
const MESSAGE = 'UserLocalPasswordPolicyMockNotValid';
public const CHECK_STATUS = false;
public const MESSAGE = 'UserLocalPasswordPolicyMockNotValid';
}
class UserLocalPasswordPolicyMockValidBis extends UserLocalPasswordPolicyMockValid
@@ -33,5 +34,5 @@ class UserLocalPasswordPolicyMockValidBis extends UserLocalPasswordPolicyMockVal
class UserLocalPasswordPolicyMockNotValidBis extends UserLocalPasswordPolicyMockNotValid
{
const MESSAGE = 'UserLocalPasswordPolicyMockNotValidBis';
}
public const MESSAGE = 'UserLocalPasswordPolicyMockNotValidBis';
}

View File

@@ -1,8 +1,10 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Test\UnitTest\Module\ItopAttachment;
use Combodo\iTop\Service\Events\EventData;
@@ -13,7 +15,7 @@ class TestAttachment extends ItopDataTestCase
{
private string $sAddAttachmentName;
private string $sRemoveAttachmentName;
const CREATE_TEST_ORG = true;
public const CREATE_TEST_ORG = true;
public function setUp(): void
{

View File

@@ -6,7 +6,6 @@ use CMDBSource;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use MetaModel;
/**
* created a dedicated test for external keys imports.
*
@@ -14,28 +13,31 @@ use MetaModel;
*
* @package Combodo\iTop\Test\UnitTest\Core
*/
class BulkChangeExtKeyTest extends ItopDataTestCase {
const CREATE_TEST_ORG = true;
class BulkChangeExtKeyTest extends ItopDataTestCase
{
public const CREATE_TEST_ORG = true;
/**
* this test may delete Person objects to cover all usecases
* DO NOT CHANGE USE_TRANSACTION value to avoid any DB loss!
*/
const USE_TRANSACTION = true;
public const USE_TRANSACTION = true;
private $sUid;
protected function setUp() : void {
protected function setUp(): void
{
parent::setUp();
require_once(APPROOT.'core/bulkchange.class.inc.php');
}
private function deleteAllRacks(){
private function deleteAllRacks()
{
$oSearch = \DBSearch::FromOQL("SELECT Rack");
$oSet = new \DBObjectSet($oSearch);
$iCount = $oSet->Count();
if ($iCount != 0){
while ($oRack = $oSet->Fetch()){
if ($iCount != 0) {
while ($oRack = $oSet->Fetch()) {
$oRack->DBDelete();
}
}
@@ -44,7 +46,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_NoObjectAtAll($bIsRackReconKey){
public function testExternalFieldIssueImportFail_NoObjectAtAll($bIsRackReconKey)
{
$this->deleteAllRacks();
$this->performBulkChangeTest(
@@ -55,7 +58,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
);
}
public function createRackObjects($aRackDict) {
public function createRackObjects($aRackDict)
{
foreach ($aRackDict as $iOrgId => $aRackNames) {
foreach ($aRackNames as $sRackName) {
$this->createObject('Rack', ['name' => $sRackName, 'description' => "{$sRackName}Desc", 'org_id' => $iOrgId]);
@@ -63,9 +67,10 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
}
}
private function createAnotherUserInAnotherOrg() {
private function createAnotherUserInAnotherOrg()
{
$oOrg2 = $this->CreateOrganization('UnitTestOrganization2');
$oProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'Configuration Manager'), true);
$oProfile = \MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", ['name' => 'Configuration Manager'], true);
$sUid = $this->GetUid();
@@ -75,13 +80,13 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
$oSet = \DBObjectSet::FromObject($oUserProfile);
$oPerson = $this->CreatePerson('666', $oOrg2->GetKey());
$oUser = $this->createObject('UserLocal', array(
$oUser = $this->createObject('UserLocal', [
'contactid' => $oPerson->GetKey(),
'login' => $sUid,
'password' => "ABCdef$sUid@12345",
'language' => 'EN US',
'profile_list' => $oSet,
));
]);
$oAllowedOrgList = $oUser->Get('allowed_org_list');
/** @var \URP_UserOrg $oUserOrg */
@@ -92,22 +97,23 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
return [$oOrg2, $oUser];
}
public function ReconciliationKeyProvider(){
public function ReconciliationKeyProvider()
{
return [
'rack_id NOT a reconcilication key' => [ false ],
'rack_id reconcilication key' => [ true ],
];
}
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_NoObjectVisibleByCurrentUser($bIsRackReconKey){
public function testExternalFieldIssueImportFail_NoObjectVisibleByCurrentUser($bIsRackReconKey)
{
$this->deleteAllRacks();
$this->createRackObjects(
[
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4']
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4'],
]
);
@@ -125,7 +131,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_SomeObjectVisibleByCurrentUser($bIsRackReconKey){
public function testExternalFieldIssueImportFail_SomeObjectVisibleByCurrentUser($bIsRackReconKey)
{
$this->deleteAllRacks();
[$oOrg2, $oUser] = $this->createAnotherUserInAnotherOrg();
$this->createRackObjects(
@@ -148,11 +155,12 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser($bIsRackReconKey){
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser($bIsRackReconKey)
{
$this->deleteAllRacks();
$this->createRackObjects(
[
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4']
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4'],
]
);
@@ -167,11 +175,12 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser_AmbigousMatch($bIsRackReconKey){
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser_AmbigousMatch($bIsRackReconKey)
{
$this->deleteAllRacks();
$this->createRackObjects(
[
$this->getTestOrgId() => ['UnexistingRack', 'UnexistingRack']
$this->getTestOrgId() => ['UnexistingRack', 'UnexistingRack'],
]
);
@@ -187,15 +196,15 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
);
}
/**
* @dataProvider ReconciliationKeyProvider
*/
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser_FurtherExtKeyForRack($bIsRackReconKey){
public function testExternalFieldIssueImportFail_AllObjectsVisibleByCurrentUser_FurtherExtKeyForRack($bIsRackReconKey)
{
$this->deleteAllRacks();
$this->createRackObjects(
[
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4']
$this->getTestOrgId() => ['RackTest1', 'RackTest2', 'RackTest3', 'RackTest4'],
]
);
@@ -214,24 +223,32 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
);
}
private function GetUid(){
if (is_null($this->sUid)){
private function GetUid()
{
if (is_null($this->sUid)) {
$this->sUid = uniqid('test');
}
return $this->sUid;
}
public function performBulkChangeTest($sExpectedDisplayableValue, $sExpectedDescription, $oOrg, $bIsRackReconKey,
$aAdditionalCsvData=null, $aExtKeys=null, $sSearchLinkUrl=null, $sError="Object not found") {
if ($sSearchLinkUrl===null){
public function performBulkChangeTest(
$sExpectedDisplayableValue,
$sExpectedDescription,
$oOrg,
$bIsRackReconKey,
$aAdditionalCsvData = null,
$aExtKeys = null,
$sSearchLinkUrl = null,
$sError = "Object not found"
) {
if ($sSearchLinkUrl === null) {
$sSearchLinkUrl = 'UI.php?operation=search&filter='.rawurlencode('%5B%22SELECT+%60Rack%60+FROM+Rack+AS+%60Rack%60+WHERE+%28%60Rack%60.%60name%60+%3D+%3Aname%29%22%2C%7B%22name%22%3A%22UnexistingRack%22%7D%2C%5B%5D%5D');
}
if (is_null($oOrg)){
if (is_null($oOrg)) {
$iOrgId = $this->getTestOrgId();
$sOrgName = "UnitTestOrganization";
}else{
} else {
$iOrgId = $oOrg->GetKey();
$sOrgName = $oOrg->Get('name');
}
@@ -239,15 +256,15 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
$sUid = $this->GetUid();
$aCsvData = [[$sOrgName, "UnexistingRack", "$sUid"]];
if ($aAdditionalCsvData !== null){
foreach ($aAdditionalCsvData as $i => $aData){
foreach ($aData as $sData){
if ($aAdditionalCsvData !== null) {
foreach ($aAdditionalCsvData as $i => $aData) {
foreach ($aData as $sData) {
$aCsvData[$i][] = $sData;
}
}
}
$aAttributes = ["name" => 2];
if ($aExtKeys == null){
if ($aExtKeys == null) {
$aExtKeys = ["org_id" => ["name" => 0], "rack_id" => ["name" => 1]];
}
$aReconcilKeys = [ "name" ];
@@ -259,19 +276,18 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
2 => "\"$sUid\"",
"rack_id" => [
$sExpectedDisplayableValue,
$sExpectedDescription
$sExpectedDescription,
],
"__STATUS__" => "Issue: Unexpected attribute value(s)",
"__ERRORS__" => $sError,
];
if ($bIsRackReconKey){
if ($bIsRackReconKey) {
$aReconcilKeys[] = "rack_id";
$aResult[2] = $sUid;
$aResult["__STATUS__"] = "Issue: failed to reconcile";
}
CMDBSource::Query('START TRANSACTION');
try {
@@ -279,8 +295,8 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
$db_core_transactions_enabled = MetaModel::GetConfig()->Get('db_core_transactions_enabled');
MetaModel::GetConfig()->Set('db_core_transactions_enabled', false);
$this->debug("aCsvData:" . json_encode($aCsvData[0]));
$this->debug("aReconcilKeys:" . var_export($aReconcilKeys));
$this->debug("aCsvData:".json_encode($aCsvData[0]));
$this->debug("aReconcilKeys:".var_export($aReconcilKeys));
$oBulk = new \BulkChange(
"Server",
$aCsvData,
@@ -302,24 +318,33 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
foreach ($aRes as $aRow) {
if (array_key_exists('__STATUS__', $aRow)) {
$sStatus = $aRow['__STATUS__'];
$this->debug("sStatus:" . $sStatus->GetDescription());
$this->debug("sStatus:".$sStatus->GetDescription());
$this->assertEquals($aResult["__STATUS__"], $sStatus->GetDescription());
foreach ($aRow as $i => $oCell) {
if ($i != "finalclass" && $i != "__STATUS__" && $i != "__ERRORS__") {
$this->debug("i:" . $i);
$this->debug("i:".$i);
if (array_key_exists($i, $aResult)) {
$this->debug("aResult:" . var_export($aResult[$i]));
$this->debug("aResult:".var_export($aResult[$i]));
if ($oCell instanceof \CellStatus_SearchIssue ||
$oCell instanceof \CellStatus_Ambiguous) {
$this->assertEquals($aResult[$i][0], $oCell->GetCLIValue(),
"failure on " . get_class($oCell) . ' cell type');
$this->assertEquals($sSearchLinkUrl, $oCell->GetSearchLinkUrl(),
"failure on " . get_class($oCell) . ' cell type');
$this->assertEquals($aResult[$i][1], $oCell->GetDescription(),
"failure on " . get_class($oCell) . ' cell type');
$this->assertEquals(
$aResult[$i][0],
$oCell->GetCLIValue(),
"failure on ".get_class($oCell).' cell type'
);
$this->assertEquals(
$sSearchLinkUrl,
$oCell->GetSearchLinkUrl(),
"failure on ".get_class($oCell).' cell type'
);
$this->assertEquals(
$aResult[$i][1],
$oCell->GetDescription(),
"failure on ".get_class($oCell).' cell type'
);
}
}
} else if ($i === "__ERRORS__") {
} elseif ($i === "__ERRORS__") {
$sErrors = array_key_exists("__ERRORS__", $aResult) ? $aResult["__ERRORS__"] : "";
$this->assertEquals($sErrors, $oCell->GetDescription());
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -12,10 +13,9 @@ use MetaModel;
class DBObjectTest extends ItopDataTestCase
{
const USE_TRANSACTION = true;
const CREATE_TEST_ORG = true;
const DEBUG_UNIT_TEST = false;
public const USE_TRANSACTION = true;
public const CREATE_TEST_ORG = true;
public const DEBUG_UNIT_TEST = false;
public function testReloadNotNecessaryForInsert()
{
@@ -170,8 +170,7 @@ class DBObjectTest extends ItopDataTestCase
try {
$oPerson->Set('email', 'test1@combodo.com');
$this->assertTrue(false, 'Set() should have raised a CoreException');
}
catch (\CoreException $e) {
} catch (\CoreException $e) {
$this->assertEquals($sMessage, $e->getMessage());
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -36,8 +37,7 @@ class ConfigPlaceholdersResolverTest extends ItopTestCase
*/
public function testResolve($aEnv, $aServer, $sValue, $sExpected, $sExpectedExceptionClass = null)
{
if ($sExpectedExceptionClass)
{
if ($sExpectedExceptionClass) {
$this->expectException($sExpectedExceptionClass);
}
@@ -49,118 +49,118 @@ class ConfigPlaceholdersResolverTest extends ItopTestCase
public function providerResolve()
{
$stdObj = (object) array('%env(HTTP_PORT)?:8080%', '%server(toto)?:8080%', '%foo(toto)?:8080%');
$stdObj = (object) ['%env(HTTP_PORT)?:8080%', '%server(toto)?:8080%', '%foo(toto)?:8080%'];
return array(
'basic behaviour' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array(),
return [
'basic behaviour' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => [],
'sValue' => '%env(HTTP_PORT)%',
'sExpected' => '443',
),
],
'disabled if no ITOP_CONFIG_PLACEHOLDERS' => array(
'aEnv' => array('HTTP_PORT' => '443'),
'aServer' => array(),
'disabled if no ITOP_CONFIG_PLACEHOLDERS' => [
'aEnv' => ['HTTP_PORT' => '443'],
'aServer' => [],
'sValue' => '%env(HTTP_PORT)%',
'sExpected' => '%env(HTTP_PORT)%',
),
],
'basic with default not used' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array(),
'basic with default not used' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => [],
'sValue' => '%env(HTTP_PORT)?:foo%',
'sExpected' => '443',
),
],
'basic with default used' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, ),
'aServer' => array(),
'basic with default used' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, ],
'aServer' => [],
'sValue' => '%env(HTTP_PORT)?:foo%',
'sExpected' => 'foo',
),
],
'basic with default used and empty' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, ),
'aServer' => array(),
'basic with default used and empty' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, ],
'aServer' => [],
'sValue' => '%env(HTTP_PORT)?:%',
'sExpected' => '',
),
],
'mixed with static' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array('toto' => 'tutu'),
'mixed with static' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => ['toto' => 'tutu'],
'sValue' => 'http://localhost:%env(HTTP_PORT)?:8080%/',
'sExpected' => 'http://localhost:443/',
),
],
'multiple occurrences' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array('SERVER_NAME' => 'localhost'),
'multiple occurrences' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => ['SERVER_NAME' => 'localhost'],
'sValue' => 'http://%server(SERVER_NAME)%:%env(HTTP_PORT)%/',
'sExpected' => 'http://localhost:443/',
),
],
'array as source' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array('toto' => 'tutu'),
'sValue' => array('http://localhost:%env(HTTP_PORT)?:8080%/', '%foo(HTTP_PORT)?:8080%', '%server(toto)?:8080%'),
'sExpected' => array('http://localhost:443/', '%foo(HTTP_PORT)?:8080%', 'tutu'),
),
'array as source' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => ['toto' => 'tutu'],
'sValue' => ['http://localhost:%env(HTTP_PORT)?:8080%/', '%foo(HTTP_PORT)?:8080%', '%server(toto)?:8080%'],
'sExpected' => ['http://localhost:443/', '%foo(HTTP_PORT)?:8080%', 'tutu'],
],
'invalid source' => array(
'aEnv' => array('toto' => 'tutu'),
'aServer' => array('HTTP_PORT' => '443'),
'invalid source' => [
'aEnv' => ['toto' => 'tutu'],
'aServer' => ['HTTP_PORT' => '443'],
'sValue' => '%foo(HTTP_PORT)?:8080%',
'sExpected' => '%foo(HTTP_PORT)?:8080%',
),
],
'ignored source' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array('toto' => 'tutu'),
'ignored source' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => ['toto' => 'tutu'],
'sValue' => $stdObj,
'sExpected' => $stdObj,
),
],
'env matching port' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
'aServer' => array('toto' => 'tutu'),
'env matching port' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'],
'aServer' => ['toto' => 'tutu'],
'sValue' => '%env(HTTP_PORT)?:8080%',
'sExpected' => '443',
),
'env no matching port with default ' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'foo' => 'bar'),
'aServer' => array('toto' => 'tutu'),
],
'env no matching port with default ' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'foo' => 'bar'],
'aServer' => ['toto' => 'tutu'],
'sValue' => '%env(HTTP_PORT)?:8080%',
'sExpected' => '8080',
),
'env no matching port' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'foo' => 'bar'),
'aServer' => array('toto' => 'tutu'),
],
'env no matching port' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'foo' => 'bar'],
'aServer' => ['toto' => 'tutu'],
'sValue' => '%env(HTTP_PORT)%',
'sExpected' => null,
'sExpectedExceptionClass' => 'ConfigException',
),
],
'server matching port' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'),
'aServer' => array('HTTP_PORT' => '443'),
'server matching port' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'],
'aServer' => ['HTTP_PORT' => '443'],
'sValue' => '%server(HTTP_PORT)?:8080%',
'sExpected' => '443',
),
'server no matching port with default ' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'),
'aServer' => array('foo' => 'bar'),
],
'server no matching port with default ' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'],
'aServer' => ['foo' => 'bar'],
'sValue' => '%server(HTTP_PORT)?:8080%',
'sExpected' => '8080',
),
'server no matching port' => array(
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'),
'aServer' => array('foo' => 'bar'),
],
'server no matching port' => [
'aEnv' => ['ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'],
'aServer' => ['foo' => 'bar'],
'sValue' => '%server(HTTP_PORT)%',
'sExpected' => null,
'sExpectedExceptionClass' => 'ConfigException',
),
);
],
];
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -60,34 +61,34 @@ class ConfigTest extends ItopTestCase
public function ProviderPreserveVarOnWriteToFile()
{
return array(
'preserve var' => array(
return [
'preserve var' => [
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
'sExpectedContains' => "'app_root_url' => 'http://' . (isset(\$_SERVER['SERVER_NAME']) ? \$_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/'",
'aChanges' => array(),
),
'preserve joker' => array(
'aChanges' => [],
],
'preserve joker' => [
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
'sExpectedContains' => "'app_root_url' => 'http://%server(SERVER_NAME)?:localhost%/itop/iTop/'",
'aChanges' => array(),
),
'aChanges' => [],
],
'preserve set same value' => array(
'preserve set same value' => [
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
'sExpectedContains' => "'app_root_url' => 'http://' . (isset(\$_SERVER['SERVER_NAME']) ? \$_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/'",
'aChanges' => array('app_root_url' => 'http://localhost/itop/iTop/'),
),
'aChanges' => ['app_root_url' => 'http://localhost/itop/iTop/'],
],
'overwrite var' => array(
'overwrite var' => [
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
'sExpectedContains' => "'app_root_url' => 'foo",
'aChanges' => array('app_root_url' => 'foo'),
),
'overwrite joker' => array(
'aChanges' => ['app_root_url' => 'foo'],
],
'overwrite joker' => [
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
'sExpectedContains' => "'app_root_url' => 'foo",
'aChanges' => array('app_root_url' => 'foo'),
),
);
'aChanges' => ['app_root_url' => 'foo'],
],
];
}
}

View File

@@ -7,31 +7,27 @@
*
*
*/
$MySettings = array(
$MySettings = [
// app_root_url: Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server's name)
// default: ''
'app_root_url' => 'http://%server(SERVER_NAME)?:localhost%/itop/iTop/',
);
];
/**
*
* Modules specific settings
*
*/
$MyModuleSettings = array(
);
$MyModuleSettings = [
];
/**
*
* Data model modules to be loaded. Names are specified as relative paths
*
*/
$MyModules = array(
'addons' => array('user rights' => 'addons/userrights/userrightsprofile.class.inc.php'),
);
?>
$MyModules = [
'addons' => ['user rights' => 'addons/userrights/userrightsprofile.class.inc.php'],
];

View File

@@ -7,31 +7,27 @@
*
*
*/
$MySettings = array(
$MySettings = [
// app_root_url: Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server's name)
// default: ''
'app_root_url' => 'http://' . (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost') . '/itop/iTop/',
'app_root_url' => 'http://'.(isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost').'/itop/iTop/',
);
];
/**
*
* Modules specific settings
*
*/
$MyModuleSettings = array(
);
$MyModuleSettings = [
];
/**
*
* Data model modules to be loaded. Names are specified as relative paths
*
*/
$MyModules = array(
'addons' => array('user rights' => 'addons/userrights/userrightsprofile.class.inc.php'),
);
?>
$MyModules = [
'addons' => ['user rights' => 'addons/userrights/userrightsprofile.class.inc.php'],
];

View File

@@ -1,4 +1,5 @@
<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 31/12/2019
@@ -14,7 +15,6 @@ use PhpParser\PrettyPrinter\Standard;
class iTopConfigAstValidatorTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
@@ -23,7 +23,6 @@ class iTopConfigAstValidatorTest extends ItopTestCase
$this->RequireOnceItopFile('env-production/itop-config/src/Validator/iTopConfigAstValidator.php');
}
/**
* @dataProvider InvalidDataProvider
* @param $sConf
@@ -34,10 +33,9 @@ class iTopConfigAstValidatorTest extends ItopTestCase
{
$oiTopConfigValidator = new iTopConfigAstValidator();
$this->expectException(\Exception::class);
try{
try {
$oiTopConfigValidator->Validate($sConf);
}catch (\Exception $e)
{
} catch (\Exception $e) {
$this->assertStringStartsWith('Invalid configuration:', $e->getMessage());
throw $e;
}
@@ -45,29 +43,28 @@ class iTopConfigAstValidatorTest extends ItopTestCase
public function InvalidDataProvider()
{
return array(
'invalid PHP' => array(
'sConf' => '<?php fiction Method(){}'
),
'function call' => array(
'sConf' => '<?php FunctionCall();'
),
'function declaration' => array(
'sConf' => '<?php function foo() {};'
),
'class instantiation' => array(
'sConf' => '<?php new Class {};'
),
'Class declaration' => array(
'sConf' => '<?php class foo {};'
),
'echo' => array(
'sConf' => '<?php echo "toto"; ?>'
),
);
return [
'invalid PHP' => [
'sConf' => '<?php fiction Method(){}',
],
'function call' => [
'sConf' => '<?php FunctionCall();',
],
'function declaration' => [
'sConf' => '<?php function foo() {};',
],
'class instantiation' => [
'sConf' => '<?php new Class {};',
],
'Class declaration' => [
'sConf' => '<?php class foo {};',
],
'echo' => [
'sConf' => '<?php echo "toto"; ?>',
],
];
}
/**
* @dataProvider ValidDataProvider
* @doesNotPerformAssertions
@@ -85,13 +82,13 @@ class iTopConfigAstValidatorTest extends ItopTestCase
public function ValidDataProvider()
{
return array(
'simple code' => array(
'sConf' => '<?php $var = array("toto"); ?>'
),
'class constant' => array(
'sConf' => '<?php $var = array(foo::bar);'
),
);
return [
'simple code' => [
'sConf' => '<?php $var = array("toto"); ?>',
],
'class constant' => [
'sConf' => '<?php $var = array(foo::bar);',
],
];
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Created by Bruno DA SILVA, working for Combodo
* Date: 31/12/2019
@@ -15,7 +16,6 @@ use PhpParser\PrettyPrinter\Standard;
class iTopConfigSyntaxValidatorTest extends ItopTestCase
{
public function setUp(): void
{
parent::setUp();
@@ -24,7 +24,6 @@ class iTopConfigSyntaxValidatorTest extends ItopTestCase
$this->RequireOnceItopFile('env-production/itop-config/src/Validator/iTopConfigSyntaxValidator.php');
}
/**
* @throws \Exception
* @doesNotPerformAssertions
@@ -40,7 +39,7 @@ class iTopConfigSyntaxValidatorTest extends ItopTestCase
$oiTopConfigValidator = new iTopConfigSyntaxValidator();
$this->expectException(\Exception::class);
try{
try {
$oiTopConfigValidator->Validate("<?php \n zef;zefzef \n zdadz = azdazd \n zerfgzaezerfgzef>");
} catch (\Exception $e) {
if (version_compare(phpversion(), '8.0.0', '<')) {

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Combodo\iTop\Test\UnitTest\Module\LaunchTest;
@@ -8,38 +9,38 @@ use TokenValidation;
class TokenValidationTest extends ItopDataTestCase
{
/**
* @param string $sSetupToken
*
* @return string
*/
public function createSetupTokenFile(string $sSetupToken): string
{
$sSetupTokenFile = APPROOT . 'data/.setup';
file_put_contents($sSetupTokenFile, $sSetupToken);
/**
* @param string $sSetupToken
*
* @return string
*/
public function createSetupTokenFile(string $sSetupToken): string
{
$sSetupTokenFile = APPROOT.'data/.setup';
file_put_contents($sSetupTokenFile, $sSetupToken);
return $sSetupTokenFile;
}
return $sSetupTokenFile;
}
/**
* @group itop-community
* @return void
*/
public function testLaunch()
{
$this->RequireOnceItopFile('datamodels/2.x/itop-hub-connector/TokenValidation.php');
/**
* @group itop-community
* @return void
*/
public function testLaunch()
{
$this->RequireOnceItopFile('datamodels/2.x/itop-hub-connector/TokenValidation.php');
$oTokenValidation = new TokenValidation();
$oTokenValidation = new TokenValidation();
$sSetupToken = bin2hex(random_bytes(12));
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->assertFalse($oTokenValidation->isSetupTokenValid($sSetupToken));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->createSetupTokenFile($sSetupToken);
$this->assertTrue($oTokenValidation->isSetupTokenValid($sSetupToken));
}
$sSetupToken = bin2hex(random_bytes(12));
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->assertFalse($oTokenValidation->isSetupTokenValid($sSetupToken));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid('lol'));
$this->createSetupTokenFile($sSetupToken);
$this->assertFalse($oTokenValidation->isSetupTokenValid(''));
$this->createSetupTokenFile($sSetupToken);
$this->assertTrue($oTokenValidation->isSetupTokenValid($sSetupToken));
}
}

View File

@@ -1,6 +1,7 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Module\iTopPortalBase;
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -30,7 +31,7 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
*/
class ApplicationHelperTest extends ItopDataTestCase
{
const PASSWORD = "aBCDEFG@123456789";
public const PASSWORD = "aBCDEFG@123456789";
protected function LoadRequiredItopFiles(): void
{
@@ -64,7 +65,7 @@ class ApplicationHelperTest extends ItopDataTestCase
->willReturn("Administrator");
$_SESSION = [];
$oUser = $this->CreateContactlessUser("$sAssociatedProfileName-" . uniqid(), self::$aURP_Profiles[$sAssociatedProfileName], self::PASSWORD);
$oUser = $this->CreateContactlessUser("$sAssociatedProfileName-".uniqid(), self::$aURP_Profiles[$sAssociatedProfileName], self::PASSWORD);
\UserRights::Login($oUser->Get('login'));
$this->InvokeNonPublicStaticMethod(ApplicationHelper::class, 'LoadBrickSecurity', [$oBrick]);
@@ -85,11 +86,10 @@ class ApplicationHelperTest extends ItopDataTestCase
->willReturn("Administrator");
$_SESSION = [];
$oUser = $this->CreateContactlessUser("$sAssociatedProfileName-" . uniqid(), self::$aURP_Profiles[$sAssociatedProfileName], self::PASSWORD);
$oUser = $this->CreateContactlessUser("$sAssociatedProfileName-".uniqid(), self::$aURP_Profiles[$sAssociatedProfileName], self::PASSWORD);
\UserRights::Login($oUser->Get('login'));
$this->InvokeNonPublicStaticMethod(ApplicationHelper::class, 'LoadBrickSecurity', [$oBrick]);
}
}

View File

@@ -1,4 +1,5 @@
<?php
/**
* Copyright (C) 2010-2024 Combodo SAS
*
@@ -32,7 +33,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
class RequestManipulatorTest extends ItopDataTestCase
{
protected function LoadRequiredItopFiles(): void
{
parent::LoadRequiredItopFiles();
@@ -53,7 +53,7 @@ class RequestManipulatorTest extends ItopDataTestCase
$oRequestManipulatorHelper = new RequestManipulatorHelper($oRequestStack);
// I - default null value
$oNullArrayValue = $oRequestManipulatorHelper->ReadParam('null_array_value', null, FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY);
$oNullArrayValue = $oRequestManipulatorHelper->ReadParam('null_array_value', null, FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY);
$this->assertNull($oNullArrayValue);
// II - default empty array value
@@ -69,5 +69,4 @@ class RequestManipulatorTest extends ItopDataTestCase
$this->assertEquals($aValue, $aReadValue);
}
}

View File

@@ -1,4 +1,5 @@
<?php
// Copyright (c) 2010-2024 Combodo SAS
//
// This file is part of iTop.
@@ -25,7 +26,6 @@ use MetaModel;
use Organization;
use UserRights;
/**
* @group itopVirtualizationMgmt
* @group itopConfigMgmt
@@ -33,7 +33,7 @@ use UserRights;
*/
class UpdateImpactedItemsTest extends ItopDataTestCase
{
const CREATE_TEST_ORG = true;
public const CREATE_TEST_ORG = true;
/**
* @var Object Names to Ids
*/
@@ -63,7 +63,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
Server_1 <-> Person_1
EOF);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual'
'Server_1' => 'manual',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -71,7 +71,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertCIsOrPersonsListEquals($oTicket, [
'Server_1' => 'manual',
'Hypervisor_1' => 'computed',
'Test Person_1' => 'computed'
'Test Person_1' => 'computed',
]);
}
@@ -84,7 +84,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
Hypervisor_1 -> Server_1
EOF);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Hypervisor_1' => 'manual'
'Hypervisor_1' => 'manual',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -104,7 +104,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
Farm_1 <-> Person_1
EOF);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual'
'Server_1' => 'manual',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -113,7 +113,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
'Server_1' => 'manual',
'Hypervisor_1' => 'computed',
'Farm_1' => 'computed',
'Test Person_1' => 'computed'
'Test Person_1' => 'computed',
]);
}
@@ -127,7 +127,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
EOF);
$this->GivenCINotAllowedToCurrentUser('Hypervisor_1');
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual'
'Server_1' => 'manual',
]);
MetaModel::GetConfig()->Set('relations.complete_analysis', false);
@@ -149,7 +149,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
EOF);
$this->GivenCINotAllowedToCurrentUser('Hypervisor_1');
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual'
'Server_1' => 'manual',
]);
MetaModel::GetConfig()->Set('relations.complete_analysis', true);
@@ -210,7 +210,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
'Hypervisor_1' => 'manual',
'Hypervisor_2' => 'manual',
'Farm_1' => 'computed',
'Test Person_1' => 'computed'
'Test Person_1' => 'computed',
]);
}
public function testPreviouslyComputedNodesShouldBeIgnored()
@@ -228,7 +228,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual',
'Server_2' => 'computed',
'Person_2' => 'computed'
'Person_2' => 'computed',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -236,7 +236,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertCIsOrPersonsListEquals($oTicket, [
'Server_1' => 'manual',
'Hypervisor_1' => 'computed',
'Test Person_1' => 'computed'
'Test Person_1' => 'computed',
]);
}
@@ -251,7 +251,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
EOF);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Hypervisor_1' => 'computed',
'Person_1' => 'computed'
'Person_1' => 'computed',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -259,7 +259,6 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertCIsOrPersonsListEquals($oTicket, []);
}
public function testNoImpactWhenNoCI()
{
$oTicket = $this->GivenTicketWithCIsOrPersons([]);
@@ -281,13 +280,13 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
Hypervisor_2 -> Farm_1
DOT);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Hypervisor_1' => 'manual'
'Hypervisor_1' => 'manual',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
$this->assertCIsOrPersonsListEquals($oTicket, [
'Hypervisor_1' => 'manual'
'Hypervisor_1' => 'manual',
]);
}
@@ -304,7 +303,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
DOT);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Hypervisor_1' => 'manual',
'Hypervisor_2' => 'manual'
'Hypervisor_2' => 'manual',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -312,7 +311,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertCIsOrPersonsListEquals($oTicket, [
'Hypervisor_1' => 'manual',
'Hypervisor_2' => 'manual',
'Farm_1' => 'computed'
'Farm_1' => 'computed',
]);
}
@@ -329,7 +328,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Server_1' => 'manual',
'Hypervisor_1' => 'not_impacted',
'Person_1' => 'do_not_notify'
'Person_1' => 'do_not_notify',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
@@ -337,7 +336,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertCIsOrPersonsListEquals($oTicket, [
'Server_1' => 'manual',
'Hypervisor_1' => 'not_impacted',
'Test Person_1' => 'do_not_notify'
'Test Person_1' => 'do_not_notify',
]);
}
@@ -351,14 +350,14 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
DOT);
$oTicket = $this->GivenTicketWithCIsOrPersons([
'Hypervisor_1' => 'not_impacted',
'Person_1' => 'do_not_notify'
'Person_1' => 'do_not_notify',
]);
$oTicket->UpdateImpactedItems(); // impact analysis
$this->assertCIsOrPersonsListEquals($oTicket, [
'Hypervisor_1' => 'not_impacted',
'Test Person_1' => 'do_not_notify'
'Test Person_1' => 'do_not_notify',
]);
}
@@ -415,7 +414,6 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
$this->assertEquals($aExpected, $aActual, 'Unexpected value for functionalcis_list');
}
/**
* @param int|string|null $sTicketId
*
@@ -489,7 +487,7 @@ class UpdateImpactedItemsTest extends ItopDataTestCase
return $this->aCIs[$sDescriptor];
}
private function GivenTicketWithCIsOrPersons(array $aLinkedObjects) : \UserRequest
private function GivenTicketWithCIsOrPersons(array $aLinkedObjects): \UserRequest
{
$oTicket = $this->GivenTicketObject(1);
foreach ($aLinkedObjects as $sObjectDescriptor => $sRole) {