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

@@ -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', '<')) {