Merge branch 'support/3.2' into develop

This commit is contained in:
odain
2025-11-07 20:33:14 +01:00
1837 changed files with 33034 additions and 34549 deletions

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

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