mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°5608 - Harmonize namespaces and merge duplicated test files
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* Time: 09:14
|
||||
*/
|
||||
|
||||
namespace coreExtensions;
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\AuthentLocal;
|
||||
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2010-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\iTopConfig;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use ConfigPlaceholdersResolver;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ConfigPlaceholdersResolverTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('core/config.class.inc.php');
|
||||
}
|
||||
/**
|
||||
* @dataProvider providerResolve
|
||||
*/
|
||||
public function testResolve($aEnv, $aServer, $sValue, $sExpected, $sExpectedExceptionClass = null)
|
||||
{
|
||||
if ($sExpectedExceptionClass)
|
||||
{
|
||||
$this->expectException($sExpectedExceptionClass);
|
||||
}
|
||||
|
||||
$oConfigPlaceholdersResolver = new ConfigPlaceholdersResolver($aEnv, $aServer);
|
||||
$sResult = $oConfigPlaceholdersResolver->Resolve($sValue);
|
||||
|
||||
$this->assertEquals($sExpected, $sResult);
|
||||
}
|
||||
|
||||
public function providerResolve()
|
||||
{
|
||||
$stdObj = (object) array('%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(),
|
||||
'sValue' => '%env(HTTP_PORT)%',
|
||||
'sExpected' => '443',
|
||||
),
|
||||
|
||||
'disabled if no ITOP_CONFIG_PLACEHOLDERS' => array(
|
||||
'aEnv' => array('HTTP_PORT' => '443'),
|
||||
'aServer' => array(),
|
||||
'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(),
|
||||
'sValue' => '%env(HTTP_PORT)?:foo%',
|
||||
'sExpected' => '443',
|
||||
),
|
||||
|
||||
'basic with default used' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, ),
|
||||
'aServer' => array(),
|
||||
'sValue' => '%env(HTTP_PORT)?:foo%',
|
||||
'sExpected' => 'foo',
|
||||
),
|
||||
|
||||
'basic with default used and empty' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, ),
|
||||
'aServer' => array(),
|
||||
'sValue' => '%env(HTTP_PORT)?:%',
|
||||
'sExpected' => '',
|
||||
),
|
||||
|
||||
'mixed with static' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
|
||||
'aServer' => array('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'),
|
||||
'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'),
|
||||
),
|
||||
|
||||
'invalid source' => array(
|
||||
'aEnv' => array('toto' => 'tutu'),
|
||||
'aServer' => array('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'),
|
||||
'sValue' => $stdObj,
|
||||
'sExpected' => $stdObj,
|
||||
),
|
||||
|
||||
'env matching port' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'HTTP_PORT' => '443'),
|
||||
'aServer' => array('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'),
|
||||
'sValue' => '%env(HTTP_PORT)?:8080%',
|
||||
'sExpected' => '8080',
|
||||
),
|
||||
'env no matching port' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'foo' => 'bar'),
|
||||
'aServer' => array('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'),
|
||||
'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'),
|
||||
'sValue' => '%server(HTTP_PORT)?:8080%',
|
||||
'sExpected' => '8080',
|
||||
),
|
||||
'server no matching port' => array(
|
||||
'aEnv' => array('ITOP_CONFIG_PLACEHOLDERS' => 1, 'toto' => 'tutu'),
|
||||
'aServer' => array('foo' => 'bar'),
|
||||
'sValue' => '%server(HTTP_PORT)%',
|
||||
'sExpected' => null,
|
||||
'sExpectedExceptionClass' => 'ConfigException',
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (C) 2010-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with iTop. If not, see <http: *www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\iTopConfig;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Config;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ConfigTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('core/config.class.inc.php');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider ProviderPreserveVarOnWriteToFile
|
||||
*
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*
|
||||
*/
|
||||
public function testPreserveVarOnWriteToFile($sConfigFile, $sExpectedContains, $aChanges)
|
||||
{
|
||||
$sTmpFile = tempnam(sys_get_temp_dir(), "target");
|
||||
|
||||
$oConfig = new Config($sConfigFile);
|
||||
|
||||
foreach ($aChanges as $key => $val)
|
||||
{
|
||||
$oConfig->Set($key, $val);
|
||||
}
|
||||
|
||||
$oConfig->WriteToFile($sTmpFile);
|
||||
|
||||
$this->assertFileExists($sTmpFile);
|
||||
$sFileContent = file_get_contents($sTmpFile);
|
||||
|
||||
$this->assertContains($sExpectedContains, $sFileContent);
|
||||
}
|
||||
|
||||
public function ProviderPreserveVarOnWriteToFile()
|
||||
{
|
||||
return array(
|
||||
'preserve var' => array(
|
||||
'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(
|
||||
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
|
||||
'sExpectedContains' => "'app_root_url' => 'http://%server(SERVER_NAME)?:localhost%/itop/iTop/'",
|
||||
'aChanges' => array(),
|
||||
),
|
||||
|
||||
'preserve set same value' => array(
|
||||
'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/'),
|
||||
),
|
||||
|
||||
'overwrite var' => array(
|
||||
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-var.php',
|
||||
'sExpectedContains' => "'app_root_url' => 'foo",
|
||||
'aChanges' => array('app_root_url' => 'foo'),
|
||||
),
|
||||
'overwrite joker' => array(
|
||||
'sConfigFile' => __DIR__.'/ConfigTest/config-itop-joker.php',
|
||||
'sExpectedContains' => "'app_root_url' => 'foo",
|
||||
'aChanges' => array('app_root_url' => 'foo'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Configuration file, generated for the unit tests
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$MySettings = array(
|
||||
|
||||
|
||||
|
||||
// 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(
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Data model modules to be loaded. Names are specified as relative paths
|
||||
*
|
||||
*/
|
||||
$MyModules = array(
|
||||
'addons' => array('user rights' => 'addons/userrights/userrightsprofile.class.inc.php'),
|
||||
);
|
||||
?>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Configuration file, generated for the unit tests
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$MySettings = array(
|
||||
|
||||
|
||||
|
||||
// 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/',
|
||||
|
||||
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Modules specific settings
|
||||
*
|
||||
*/
|
||||
$MyModuleSettings = array(
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Data model modules to be loaded. Names are specified as relative paths
|
||||
*
|
||||
*/
|
||||
$MyModules = array(
|
||||
'addons' => array('user rights' => 'addons/userrights/userrightsprofile.class.inc.php'),
|
||||
);
|
||||
?>
|
||||
@@ -5,7 +5,7 @@
|
||||
* Time: 12:31
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Config\Test\Validator;
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\iTopConfig\Validator;
|
||||
|
||||
use Combodo\iTop\Config\Validator\iTopConfigAstValidator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
@@ -43,7 +43,6 @@ class iTopConfigAstValidatorTest extends ItopTestCase
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function InvalidDataProvider()
|
||||
{
|
||||
return array(
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Time: 12:31
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Config\Test\Validator;
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\iTopConfig\Validator;
|
||||
|
||||
use Combodo\iTop\Config\Validator\iTopConfigAstValidator;
|
||||
use Combodo\iTop\Config\Validator\iTopConfigSyntaxValidator;
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
* Time: 13:34
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\iTopTickets;
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\iTopTickets;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Exception;
|
||||
|
||||
Reference in New Issue
Block a user