mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°6658 - Boost PHPUnit tests execution
This commit is contained in:
@@ -59,9 +59,16 @@ class DbConnectionWrapper
|
||||
* Use this to register a mock that will handle {@see mysqli::query()}
|
||||
*
|
||||
* @param \mysqli|null $oMysqli
|
||||
* @since 3.0.4 3.1.1 3.2.0 Param $oMysqli becomes nullable
|
||||
*/
|
||||
public static function SetDbConnectionMockForQuery(?mysqli $oMysqli): void
|
||||
public static function SetDbConnectionMockForQuery(?mysqli $oMysqli = null): void
|
||||
{
|
||||
static::$oDbCnxMockableForQuery = $oMysqli;
|
||||
if (is_null($oMysqli)) {
|
||||
// Reset to standard connection
|
||||
static::$oDbCnxMockableForQuery = static::$oDbCnxStandard;
|
||||
}
|
||||
else {
|
||||
static::$oDbCnxMockableForQuery = $oMysqli;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +56,11 @@ class Dict
|
||||
* @param $sLanguageCode
|
||||
*
|
||||
* @throws \DictExceptionUnknownLanguage
|
||||
* @since 3.0.4 3.1.1 3.2.0 Param $sLanguageCode becomes nullable
|
||||
*/
|
||||
public static function SetUserLanguage($sLanguageCode)
|
||||
public static function SetUserLanguage($sLanguageCode = null)
|
||||
{
|
||||
if (!array_key_exists($sLanguageCode, self::$m_aLanguages))
|
||||
if (!is_null($sLanguageCode) && !array_key_exists($sLanguageCode, self::$m_aLanguages))
|
||||
{
|
||||
throw new DictExceptionUnknownLanguage($sLanguageCode);
|
||||
}
|
||||
|
||||
@@ -1080,7 +1080,7 @@ class DeprecatedCallsLog extends LogAPI
|
||||
parent::Enable($sTargetFile);
|
||||
|
||||
if (
|
||||
(false === defined(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME))
|
||||
(false === defined('ITOP_PHPUNIT_RUNNING_CONSTANT_NAME'))
|
||||
&& static::IsLogLevelEnabledSafe(self::LEVEL_WARNING, self::ENUM_CHANNEL_PHP_LIBMETHOD)
|
||||
) {
|
||||
set_error_handler([static::class, 'DeprecatedNoticesErrorHandler'], E_DEPRECATED | E_USER_DEPRECATED);
|
||||
|
||||
@@ -6486,6 +6486,13 @@ abstract class MetaModel
|
||||
*/
|
||||
public static function Startup($config, $bModelOnly = false, $bAllowCache = true, $bTraceSourceFiles = false, $sEnvironment = 'production')
|
||||
{
|
||||
// Startup on a new environment is not supported
|
||||
static $bStarted = false;
|
||||
if ($bStarted) {
|
||||
return;
|
||||
}
|
||||
$bStarted = true;
|
||||
|
||||
self::$m_sEnvironment = $sEnvironment;
|
||||
|
||||
if (!defined('MODULESROOT'))
|
||||
@@ -6722,6 +6729,19 @@ abstract class MetaModel
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Used for resetting the configuration during automated tests
|
||||
|
||||
* @param \Config $oConfiguration
|
||||
*
|
||||
* @return void
|
||||
* @since 3.0.4 3.1.1 3.2.0
|
||||
*/
|
||||
public static function SetConfig(Config $oConfiguration)
|
||||
{
|
||||
self::$m_oConfig = $oConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Config
|
||||
*/
|
||||
|
||||
@@ -750,14 +750,25 @@ class UserRights
|
||||
protected static $m_aCacheContactPictureAbsUrl = [];
|
||||
/** @var UserRightsAddOnAPI $m_oAddOn */
|
||||
protected static $m_oAddOn;
|
||||
protected static $m_oUser;
|
||||
protected static $m_oRealUser;
|
||||
protected static $m_oUser = null;
|
||||
protected static $m_oRealUser = null;
|
||||
protected static $m_sSelfRegisterAddOn = null;
|
||||
protected static $m_aAdmins = array();
|
||||
protected static $m_aPortalUsers = array();
|
||||
/** @var array array('sName' => $sName, 'bSuccess' => $bSuccess); */
|
||||
private static $m_sLastLoginStatus = null;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @since 3.0.4 3.1.1 3.2.0
|
||||
*/
|
||||
protected static function ResetCurrentUserData()
|
||||
{
|
||||
self::$m_oUser = null;
|
||||
self::$m_oRealUser = null;
|
||||
self::$m_sLastLoginStatus = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sModuleName
|
||||
*
|
||||
@@ -776,8 +787,7 @@ class UserRights
|
||||
}
|
||||
self::$m_oAddOn = new $sModuleName;
|
||||
self::$m_oAddOn->Init();
|
||||
self::$m_oUser = null;
|
||||
self::$m_oRealUser = null;
|
||||
self::ResetCurrentUserData();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -844,6 +854,8 @@ class UserRights
|
||||
*/
|
||||
public static function Login($sLogin, $sAuthentication = 'any')
|
||||
{
|
||||
static::Logoff();
|
||||
|
||||
$oUser = self::FindUser($sLogin, $sAuthentication);
|
||||
if (is_null($oUser))
|
||||
{
|
||||
@@ -861,6 +873,17 @@ class UserRights
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @since 3.0.4 3.1.1 3.2.0
|
||||
*/
|
||||
public static function Logoff()
|
||||
{
|
||||
self::ResetCurrentUserData();
|
||||
Dict::SetUserLanguage(null);
|
||||
self::_ResetSessionCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLogin Login of the user to check the credentials for
|
||||
* @param string $sPassword
|
||||
|
||||
@@ -1,7 +1,118 @@
|
||||
# PHP unitary tests
|
||||
|
||||
## Where should I add my test?
|
||||
|
||||
- Covers an iTop PHP class or method?
|
||||
- Most likely in "unitary-tests".
|
||||
- Covers the consistency of some data through the app?
|
||||
- Most likely in "integration-tests".
|
||||
- Most likely in "integration-tests".
|
||||
|
||||
## How do I make sure that my tests are efficient?
|
||||
|
||||
|
||||
### Derive from the relevant test class
|
||||
|
||||
Whenever possible keep it the most simple, hence you should first
|
||||
attempt to derive from `TestCase`.
|
||||
|
||||
Then, you might need to derive from `ItopTestCase`.
|
||||
|
||||
Finally, as a last resort, you will use `ItopDataTestCase`.
|
||||
|
||||
### Determine the most relevant isolation configuration
|
||||
|
||||
Should you have opted for `ItopDataTestCase`, then you will have to follow these steps:
|
||||
|
||||
1) Build you test class until it is successfull, without process isolation.
|
||||
2) Run the whole test suite [unitary-tests](unitary-tests)
|
||||
3) If a false-positive appears, then you will start troubleshooting. One advise: be positive!
|
||||
|
||||
### Leave the place clean
|
||||
|
||||
To check your code against polluting coding patterns, run the test [integration-tests/DetectStaticPollutionTest.php](integration-tests/DetectStaticPollutionTest.php)
|
||||
It will tell you if something is wrong, either in your code, or anywhere else in the tests.
|
||||
Fortunately, it will give you an alternative.
|
||||
|
||||
Detected patterns:
|
||||
* ContextTag::addTag()
|
||||
* EventService::RegisterListener()
|
||||
* Dict::Add()
|
||||
|
||||
|
||||
By the way, some patterns do not pollute, because they are handled by the test framework:
|
||||
* Configuration : automatically reset after test class execution
|
||||
* UserRights : a logoff is performed after each test execution
|
||||
* Dict::SetUserLanguage: the user language is reset after each test execution
|
||||
|
||||
See also `@beforeClass` and `@afterClass` to handle cleanup.
|
||||
|
||||
If you can't, then ok you will have to isolate it!
|
||||
|
||||
## Tips
|
||||
### Memory limit
|
||||
|
||||
As the tests are run in the same process, memory usage
|
||||
may become an issue as soon as tests are all executed at once.
|
||||
|
||||
Fix that in the XML configuration in the PHP section
|
||||
```xml
|
||||
<ini name="memory_limit" value="512M"/>
|
||||
```
|
||||
|
||||
### Understand tests interactions
|
||||
|
||||
With PHPStorm, select two tests, right click to get the context menu, then `run`.
|
||||
|
||||
You will have both tests executed and you will be able to figure out if the first one has an impact on the second one.
|
||||
|
||||
### About process isolation
|
||||
#### Isolation with PHPUnit
|
||||
|
||||
By default, tests are run in a single process launched by PHPUnit.
|
||||
|
||||
If process isolation is configured for some tests, then those tests
|
||||
will be executed in a separate process. The main process will
|
||||
continue executing non isolated tests.
|
||||
|
||||
#### Cost of isolation
|
||||
|
||||
The cost of isolating a very basic `TestCase` is approximately 4 ms.
|
||||
|
||||
The cost of isolating an `ItopDataTestCase` is approximately 800 ms.
|
||||
|
||||
### Isolation within iTop
|
||||
|
||||
#### At the test level (preferred)
|
||||
Add annotation `@runInSeparateProcess`
|
||||
Each and every test case will run in a separate
|
||||
process.
|
||||
|
||||
#### At the test class level
|
||||
Add annotation `@runTestsInSeparateProcesses`
|
||||
Each and every test case in the class will run in a separate
|
||||
process.
|
||||
|
||||
#### Globally (never do that)
|
||||
Set it into [phpunit.xml.dist](phpunit.xml.dist)
|
||||
|
||||
### Further enhancements
|
||||
The annotation [`@runClassInSeparateProcess`](https://docs.phpunit.de/en/10.0/attributes.html?highlight=runclassinseparateprocess#runclassinseparateprocess) is supposed to do the perfect job, but it is buggy [(See Issue 5230)](https://github.com/sebastianbergmann/phpunit/issues/5230) and it has
|
||||
the exact same effect as `@runTestsInSeparateProcesses`.
|
||||
|
||||
Note : this option is documented only in the [attributes part of the documentation](https://docs.phpunit.de/en/10.0/attributes.html).
|
||||
|
||||
### Traps
|
||||
#### When it is a matter of stars
|
||||
```php
|
||||
/*
|
||||
* @runTestsInSeparateProcesses
|
||||
```
|
||||
This won't work because the comment MUST start with `/**` (two stars) to be considerer by PHPUnit.
|
||||
|
||||
#### SetupBeforeClass called more often than expected
|
||||
|
||||
`setupBeforeClass` is called once for the class **in a given process**.
|
||||
|
||||
Therefore, if the tests are isolated, then `setupBeforeClass` will be called as often as `setUp`.
|
||||
|
||||
This has been proven with [`runClassInSeparateProcessTest.php`](experiments/runClassInSeparateProcessTest.php)
|
||||
1
tests/php-unit-tests/experiments/README.md
Normal file
1
tests/php-unit-tests/experiments/README.md
Normal file
@@ -0,0 +1 @@
|
||||
This directory aims at providing experimental proof of the mechanics of PHPUnit
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
|
||||
/**
|
||||
* Shows that
|
||||
* 1) the option runClassInSeparateProcess is equivalent to runTestsInSeparateProcesses
|
||||
* 2) setUpBeforeClass is called within each spawned process (the main one, then in eventuel subprocesses)
|
||||
* 3) setUp behaves as expected, i.e. called one within the same process as the test itself
|
||||
*
|
||||
* @preserveGlobalState disabled
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class runClassInSeparateProcessTest extends ItopDataTestCase
|
||||
{
|
||||
static public function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass(); // TODO: Change the autogenerated stub
|
||||
|
||||
file_put_contents(
|
||||
dirname(__FILE__).'/pid.txt',
|
||||
getmypid().';'.static::class.';'.__METHOD__."\n",
|
||||
FILE_APPEND);
|
||||
}
|
||||
|
||||
protected function LogPid()
|
||||
{
|
||||
file_put_contents(
|
||||
dirname(__FILE__).'/pid.txt',
|
||||
getmypid().';'.static::class.';'.$this->getName()."\n",
|
||||
FILE_APPEND);
|
||||
}
|
||||
|
||||
function testA()
|
||||
{
|
||||
$this->LogPid();
|
||||
static::assertTrue(true);
|
||||
}
|
||||
|
||||
function testB()
|
||||
{
|
||||
$this->LogPid();
|
||||
static::assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider CProvider
|
||||
*/
|
||||
function testC($i)
|
||||
{
|
||||
$this->LogPid();
|
||||
static::assertTrue(true);
|
||||
}
|
||||
|
||||
function CProvider()
|
||||
{
|
||||
return [
|
||||
[1],
|
||||
[1],
|
||||
[1],
|
||||
[1],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Shows that tearDown is called after a fatal error within a test
|
||||
*/
|
||||
class tearDownAfterFailureTest extends TestCase
|
||||
{
|
||||
static $bIsCorrectlyInitialized = true;
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
static::$bIsCorrectlyInitialized = true;
|
||||
}
|
||||
|
||||
function testIsInitializedAndChangeIt()
|
||||
{
|
||||
static::assertTrue(static::$bIsCorrectlyInitialized);
|
||||
|
||||
static::$bIsCorrectlyInitialized = false;
|
||||
|
||||
$this->expectException('Exception');
|
||||
throw new \Exception('hello');
|
||||
}
|
||||
|
||||
function testIsStillInitialized()
|
||||
{
|
||||
static::assertTrue(static::$bIsCorrectlyInitialized);
|
||||
}
|
||||
|
||||
function testFailingDueToUnexpectedException()
|
||||
{
|
||||
static::$bIsCorrectlyInitialized = false;
|
||||
This_Is_Not_A_Function_And_Causes_A_Fatal_Error();
|
||||
}
|
||||
|
||||
function testIsStillInitializedAnyway()
|
||||
{
|
||||
static::assertTrue(static::$bIsCorrectlyInitialized);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use GlobIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use RecursiveRegexIterator;
|
||||
use RegexIterator;
|
||||
|
||||
/**
|
||||
* Performs code static analysis to detect patterns that will change the values of static data and therefor could affect other tests while running them in a single process
|
||||
*
|
||||
* @runClassInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class detectStaticPollutionTest extends TestCase
|
||||
{
|
||||
protected function FindMatches($sFile, $sFileContents, $sRegexp)
|
||||
{
|
||||
$aRes = [];
|
||||
foreach (explode("\n", $sFileContents) as $iLine => $sLine) {
|
||||
if (preg_match_all($sRegexp, $sLine, $aMatches, PREG_PATTERN_ORDER)) {
|
||||
$sLine = $iLine + 1;
|
||||
$aRes[] = "$sFile:$sLine";
|
||||
}
|
||||
}
|
||||
return $aRes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider PollutingPatterns
|
||||
* @param $sPattern
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testDetectPolluters($sPattern, $sFix)
|
||||
{
|
||||
$sScannedDir = dirname(__FILE__).'/../unitary-tests';
|
||||
|
||||
$aPolluters = [];
|
||||
$oDirectory = new RecursiveDirectoryIterator($sScannedDir);
|
||||
$Iterator = new RecursiveIteratorIterator($oDirectory);
|
||||
foreach (new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $aMatch) {
|
||||
$sFile = $aMatch[0];
|
||||
if(is_file($sFile)) {
|
||||
$sFileContents = file_get_contents($sFile);
|
||||
if (preg_match_all($sPattern, $sFileContents, $keys, PREG_PATTERN_ORDER)) {
|
||||
$aPolluters = array_merge($aPolluters, $this->FindMatches($sFile, $sFileContents, $sPattern));
|
||||
}
|
||||
}
|
||||
}
|
||||
$iPolluters = count($aPolluters);
|
||||
static::assertTrue($iPolluters === 0, "Found polluter(s) for pattern $sPattern, $sFix:\n".implode("\n", $aPolluters));
|
||||
|
||||
}
|
||||
|
||||
public function PollutingPatterns()
|
||||
{
|
||||
return [
|
||||
'ContextTags' => ['/ContextTag::AddContext/i', 'Use new ContextTag() instead'],
|
||||
'Dict::Add' => ['/Dict::Add/i', 'TODO: implement a facade into ItopDataTestCase'],
|
||||
'EventService::RegisterListener' => ['/EventService::RegisterListener/i', 'Use ItopDataTestCase::EventService_RegisterListener instead'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -98,10 +98,12 @@ class DictionariesConsistencyTest extends ItopTestCase
|
||||
{
|
||||
$this->setUp();
|
||||
|
||||
$sAppRoot = $this->GetAppRoot();
|
||||
|
||||
$aDictFiles = array_merge(
|
||||
glob(APPROOT.'datamodels/2.x/*/*.dict*.php'), // legacy form in modules
|
||||
glob(APPROOT.'datamodels/2.x/*/dictionaries/*.dict*.php'), // modern form in modules
|
||||
glob(APPROOT.'dictionaries/*.dict*.php') // framework
|
||||
glob($sAppRoot.'datamodels/2.x/*/*.dict*.php'), // legacy form in modules
|
||||
glob($sAppRoot.'datamodels/2.x/*/dictionaries/*.dict*.php'), // modern form in modules
|
||||
glob($sAppRoot.'dictionaries/*.dict*.php') // framework
|
||||
);
|
||||
$aTestCases = array();
|
||||
foreach ($aDictFiles as $sDictFile) {
|
||||
|
||||
@@ -72,11 +72,13 @@ class iTopModulesXmlVersionIntegrationTest extends ItopTestCase
|
||||
{
|
||||
static::setUp();
|
||||
|
||||
$sPath = APPROOT.'datamodels/2.x/*/datamodel.*.xml';
|
||||
$sAppRoot = $this->GetAppRoot();
|
||||
|
||||
$sPath = $sAppRoot.'datamodels/2.x/*/datamodel.*.xml';
|
||||
$aXmlFiles = glob($sPath);
|
||||
|
||||
$aXmlFiles[] = APPROOT.'core/datamodel.core.xml';
|
||||
$aXmlFiles[] = APPROOT.'application/datamodel.application.xml';
|
||||
$aXmlFiles[] = $sAppRoot.'core/datamodel.core.xml';
|
||||
$aXmlFiles[] = $sAppRoot.'application/datamodel.application.xml';
|
||||
|
||||
$aTestCases = array();
|
||||
foreach ($aXmlFiles as $sXmlFile) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
>
|
||||
|
||||
<php>
|
||||
<ini name="memory_limit" value="512M"/>
|
||||
<ini name="error_reporting" value="E_ALL"/>
|
||||
<ini name="display_errors" value="On"/>
|
||||
<ini name="log_errors" value="On"/>
|
||||
|
||||
@@ -51,12 +51,6 @@ define('TAG_ATTCODE', 'domains');
|
||||
*
|
||||
* Helper class to extend for tests needing access to iTop's metamodel
|
||||
*
|
||||
* **⚠ Warning** Each class extending this one needs to add the following annotations :
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @since 2.7.7 3.0.1 3.1.0 N°4624 processIsolation is disabled by default and must be enabled in each test needing it (basically all tests using
|
||||
* iTop datamodel)
|
||||
*/
|
||||
@@ -64,7 +58,8 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
{
|
||||
private $iTestOrgId;
|
||||
// For cleanup
|
||||
private $aCreatedObjects = array();
|
||||
private $aCreatedObjects = [];
|
||||
private $aEventListeners = [];
|
||||
|
||||
/**
|
||||
* @var string Default environment to use for test cases
|
||||
@@ -73,6 +68,23 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
const USE_TRANSACTION = true;
|
||||
const CREATE_TEST_ORG = false;
|
||||
|
||||
/**
|
||||
* This method is called before the first test of this test class is run (in the current process).
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called after the last test of this test class is run (in the current process).
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
\UserRights::FlushPrivileges();
|
||||
parent::tearDownAfterClass();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -118,6 +130,15 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
// As soon as a rollback has been performed, each object memoized should be discarded
|
||||
CMDBObject::SetCurrentChange(null);
|
||||
|
||||
// Leave the place clean
|
||||
\UserRights::Logoff();
|
||||
|
||||
foreach ($this->aEventListeners as $sListenerId) {
|
||||
EventService::UnRegisterListener($sListenerId);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
@@ -890,6 +911,17 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
}
|
||||
}
|
||||
|
||||
protected function assertDBChangeOpCount(string $sClass, $iId, int $iExpectedCount)
|
||||
{
|
||||
$oSearch = new \DBObjectSearch('CMDBChangeOp');
|
||||
$oSearch->AddCondition('objclass', $sClass);
|
||||
$oSearch->AddCondition('objkey', $iId);
|
||||
$oSearch->AllowAllData();
|
||||
$oSet = new \DBObjectSet($oSearch);
|
||||
$iCount = $oSet->Count();
|
||||
$this->assertEquals($iExpectedCount, $iCount, "Found $iCount changes for object $sClass::$iId");
|
||||
}
|
||||
|
||||
/**
|
||||
* Import a set of XML files describing a consistent set of iTop objects
|
||||
* @param string[] $aFiles
|
||||
|
||||
@@ -24,23 +24,53 @@ define('DEBUG_UNIT_TEST', true);
|
||||
abstract class ItopTestCase extends TestCase
|
||||
{
|
||||
public const TEST_LOG_DIR = 'test';
|
||||
public static $DEBUG_UNIT_TEST = false;
|
||||
|
||||
/**
|
||||
* Override the default value to disable the backup of globals in case of tests run in a separate process
|
||||
*/
|
||||
protected $preserveGlobalState = false;
|
||||
|
||||
/**
|
||||
* This method is called before the first test of this test class is run (in the current process).
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
static::$DEBUG_UNIT_TEST = getenv('DEBUG_UNIT_TEST');
|
||||
|
||||
require_once static::GetAppRoot() . 'approot.inc.php';
|
||||
|
||||
if (false === defined('ITOP_PHPUNIT_RUNNING_CONSTANT_NAME')) {
|
||||
// setUp might be called multiple times, so protecting the define() call !
|
||||
define('ITOP_PHPUNIT_RUNNING_CONSTANT_NAME', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called after the last test of this test class is run (in the current process).
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
parent::tearDownAfterClass();
|
||||
|
||||
if (method_exists('utils', 'GetConfig')) {
|
||||
// Reset the config by forcing the load from disk
|
||||
$oConfig = \utils::GetConfig(true);
|
||||
if (method_exists('MetaModel', 'SetConfig')) {
|
||||
\MetaModel::SetConfig($oConfig);
|
||||
}
|
||||
}
|
||||
if (method_exists('Dict', 'SetUserLanguage')) {
|
||||
\Dict::SetUserLanguage();
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void {
|
||||
$sAppRootRelPath = 'approot.inc.php';
|
||||
$sDepthSeparator = '../';
|
||||
for ($iDepth = 0; $iDepth < 8; $iDepth++) {
|
||||
if (file_exists($sAppRootRelPath)) {
|
||||
require_once $sAppRootRelPath;
|
||||
break;
|
||||
}
|
||||
parent::setUp();
|
||||
|
||||
$sAppRootRelPath = $sDepthSeparator.$sAppRootRelPath;
|
||||
}
|
||||
|
||||
if (false === defined(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME)) {
|
||||
// setUp might be called multiple times, so protecting the define() call !
|
||||
define(ITOP_PHPUNIT_RUNNING_CONSTANT_NAME, true);
|
||||
}
|
||||
$this->debug("\n----------\n---------- ".$this->getName()."\n----------\n");
|
||||
|
||||
$this->LoadRequiredItopFiles();
|
||||
$this->LoadRequiredTestFiles();
|
||||
@@ -56,10 +86,38 @@ abstract class ItopTestCase extends TestCase
|
||||
|
||||
if (CMDBSource::IsInsideTransaction()) {
|
||||
// Nested transactions were opened but not finished !
|
||||
// Rollback to avoid side effects on next tests
|
||||
while (CMDBSource::IsInsideTransaction()) {
|
||||
CMDBSource::Query('ROLLBACK');
|
||||
}
|
||||
throw new MySQLTransactionNotClosedException('Some DB transactions were opened but not closed ! Fix the code by adding ROLLBACK or COMMIT statements !', []);
|
||||
}
|
||||
}
|
||||
|
||||
/** Helper than can be called in the context of a data provider */
|
||||
public static function GetAppRoot()
|
||||
{
|
||||
if (defined('APPROOT')) {
|
||||
return APPROOT;
|
||||
}
|
||||
$sSearchPath = __DIR__;
|
||||
for ($iDepth = 0; $iDepth < 8; $iDepth++) {
|
||||
if (file_exists($sSearchPath.'/approot.inc.php')) {
|
||||
break;
|
||||
}
|
||||
$iOffsetSep = strrpos($sSearchPath, '/');
|
||||
if ($iOffsetSep === false) {
|
||||
$iOffsetSep = strrpos($sSearchPath, '\\');
|
||||
if ($iOffsetSep === false) {
|
||||
// Do not throw an exception here as PHPUnit will not show it clearly when determing the list of test to perform
|
||||
return 'Could not find the approot file in '.$sSearchPath;
|
||||
}
|
||||
}
|
||||
$sSearchPath = substr($sSearchPath, 0, $iOffsetSep);
|
||||
}
|
||||
return $sSearchPath.'/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Overload this method to require necessary files through {@see \Combodo\iTop\Test\UnitTest\ItopTestCase::RequireOnceItopFile()}
|
||||
*
|
||||
@@ -93,7 +151,7 @@ abstract class ItopTestCase extends TestCase
|
||||
*/
|
||||
protected function RequireOnceItopFile(string $sFileRelPath): void
|
||||
{
|
||||
require_once APPROOT . $sFileRelPath;
|
||||
require_once $this->GetAppRoot() . $sFileRelPath;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +219,7 @@ abstract class ItopTestCase extends TestCase
|
||||
/**
|
||||
* @since 2.7.4 3.0.0
|
||||
*/
|
||||
public function InvokeNonPublicStaticMethod($sObjectClass, $sMethodName, $aArgs)
|
||||
public function InvokeNonPublicStaticMethod($sObjectClass, $sMethodName, $aArgs = [])
|
||||
{
|
||||
return $this->InvokeNonPublicMethod($sObjectClass, $sMethodName, null, $aArgs);
|
||||
}
|
||||
@@ -178,7 +236,7 @@ abstract class ItopTestCase extends TestCase
|
||||
*
|
||||
* @since 2.7.4 3.0.0
|
||||
*/
|
||||
public function InvokeNonPublicMethod($sObjectClass, $sMethodName, $oObject, $aArgs)
|
||||
public function InvokeNonPublicMethod($sObjectClass, $sMethodName, $oObject, $aArgs = [])
|
||||
{
|
||||
$class = new \ReflectionClass($sObjectClass);
|
||||
$method = $class->getMethod($sMethodName);
|
||||
|
||||
64
tests/php-unit-tests/tools/run_class_by_class.php
Normal file
64
tests/php-unit-tests/tools/run_class_by_class.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* Usage: php run_class_by_class.php
|
||||
*
|
||||
* Execute the whole test suite (as declared in phpunit.xml.dist) one class at a time.
|
||||
* This is to ensure that test class are still independant from each other, after a rework of ItopTestCase, for instance.
|
||||
*/
|
||||
const PHP_EXE = 'php';
|
||||
const ITOP_ROOT = __DIR__.'/../../dev-itop';
|
||||
|
||||
const ITOP_PHPUNIT = ITOP_ROOT.'/tests/php-unit-tests';
|
||||
const PHPUNIT_COMMAND = PHP_EXE.' '.ITOP_PHPUNIT.'/vendor/phpunit/phpunit/phpunit';
|
||||
|
||||
function ListTests($sUnitaryTestsDir = '')
|
||||
{
|
||||
$sConfigFile = ITOP_PHPUNIT."/phpunit.xml.dist";
|
||||
$sCommand = PHPUNIT_COMMAND." --configuration $sConfigFile --list-tests $sUnitaryTestsDir";
|
||||
exec($sCommand, $aOutput, $iResultCode);
|
||||
//passthru($sCommand, $iResultCode);
|
||||
if ($iResultCode != 0) { // or 1 in case of a failing test
|
||||
echo "Failed executing command: $sCommand\n";
|
||||
return [];
|
||||
}
|
||||
$aClasses = [];
|
||||
foreach ($aOutput as $iLine => $sLine) {
|
||||
// Example of formats to be filtered
|
||||
//- DatamodelsXmlFilesTest::testAllItopXmlFilesCovered
|
||||
//- Combodo\iTop\Test\UnitTest\Application\DashboardLayoutTest::testGetDashletCoordinates"OneColLayout-Cell0"
|
||||
//if (preg_match('@^- ([a-z]+\\\\)*([a-z]+::[a-z0-9]+)@i', $sLine, $aMatches)) {
|
||||
if (preg_match('@([a-z0-9]+)::test@i', $sLine, $aMatches)) {
|
||||
$sTestClass = $aMatches[1];
|
||||
$aClasses[$sTestClass] = $sTestClass;
|
||||
}
|
||||
}
|
||||
return array_keys($aClasses);
|
||||
}
|
||||
|
||||
function RunTests($sFilterRegExp, $sUnitaryTestsDir = '', $bPassthru = false)
|
||||
{
|
||||
$sRegExpShellArg = '"'.str_replace('"', '\\"', $sFilterRegExp).'"';
|
||||
$sConfigFile = ITOP_PHPUNIT."/phpunit.xml.dist";
|
||||
$sCommand = PHPUNIT_COMMAND." --configuration $sConfigFile --filter $sRegExpShellArg $sUnitaryTestsDir";
|
||||
///echo "executing <<<$sCommand>>>\n";
|
||||
if ($bPassthru) {
|
||||
passthru($sCommand, $iResultCode);
|
||||
}
|
||||
else {
|
||||
exec($sCommand, $aTrashedOutput, $iResultCode);
|
||||
}
|
||||
$bTestSuccess = ($iResultCode == 0); // or 1 in case of a failing test
|
||||
return $bTestSuccess;
|
||||
}
|
||||
|
||||
$sUnitaryTestsDir = '';
|
||||
|
||||
$aTestClasses = ListTests($sUnitaryTestsDir);
|
||||
echo "Found ".count($aTestClasses)." to execute: ".implode(", ", $aTestClasses)."\n";
|
||||
echo "Testing...\n";
|
||||
foreach ($aTestClasses as $sTestClass) {
|
||||
$fStarted = microtime(true);
|
||||
$bSuccess = RunTests($sTestClass);
|
||||
$sDuration = round(microtime(true) - $fStarted, 3);
|
||||
echo "$sTestClass: ".($bSuccess ? 'Ok' : "FAILURE")." [$sDuration s]\n";
|
||||
}
|
||||
@@ -7,8 +7,6 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class SessionTest extends ItopTestCase
|
||||
{
|
||||
|
||||
@@ -7,9 +7,6 @@ use FindStylesheetObject;
|
||||
use ThemeHandler;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @covers ThemeHandler
|
||||
*/
|
||||
class ThemeHandlerTest extends ItopTestCase
|
||||
|
||||
@@ -25,10 +25,6 @@ use privUITransactionFile;
|
||||
use UserRights;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @covers utils
|
||||
* @group sampleDataNeeded
|
||||
* @group defaultProfiles
|
||||
@@ -180,7 +176,7 @@ class privUITransactionFileTest extends ItopDataTestCase
|
||||
$this->assertTrue($bResult, 'Token created by support user must be removed in the support user context');
|
||||
|
||||
// test when no user logged (combodo-unauthenticated-form module for example)
|
||||
UserRights::_ResetSessionCache();
|
||||
UserRights::Logoff();
|
||||
$sTransactionIdUnauthenticatedUser = privUITransactionFile::GetNewTransactionId();
|
||||
$bResult = privUITransactionFile::IsTransactionValid($sTransactionIdUnauthenticatedUser, false);
|
||||
$this->assertTrue($bResult, 'Token created by unauthenticated user must be valid when no user logged');
|
||||
|
||||
@@ -25,6 +25,7 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runClassInSeparateProcess
|
||||
* @covers utils
|
||||
*/
|
||||
class utilsTest extends ItopTestCase
|
||||
@@ -68,36 +69,36 @@ class utilsTest extends ItopTestCase
|
||||
|
||||
public function realPathDataProvider()
|
||||
{
|
||||
parent::setUp(); // if not called, APPROOT won't be defined :(
|
||||
$sAppRoot = static::GetAppRoot();
|
||||
|
||||
$sSep = DIRECTORY_SEPARATOR;
|
||||
$sItopRootRealPath = realpath(APPROOT).$sSep;
|
||||
$sItopRootRealPath = realpath($sAppRoot).$sSep;
|
||||
$sLicenseFileName = 'license.txt';
|
||||
if (!is_file(APPROOT.$sLicenseFileName))
|
||||
if (!is_file($sAppRoot.$sLicenseFileName))
|
||||
{
|
||||
$sLicenseFileName = 'LICENSE';
|
||||
}
|
||||
|
||||
return [
|
||||
$sLicenseFileName => [APPROOT.$sLicenseFileName, APPROOT, $sItopRootRealPath.$sLicenseFileName],
|
||||
'unexisting file' => [APPROOT.'license_DOES_NOT_EXIST.txt', APPROOT, false],
|
||||
'/'.$sLicenseFileName => [APPROOT.$sSep.$sLicenseFileName, APPROOT, $sItopRootRealPath.$sLicenseFileName],
|
||||
'%2f'.$sLicenseFileName => [APPROOT.'%2f'. $sLicenseFileName, APPROOT, false],
|
||||
'../'.$sLicenseFileName => [APPROOT.'..'.$sSep.$sLicenseFileName, APPROOT, false],
|
||||
'%2e%2e%2f'.$sLicenseFileName => [APPROOT.'%2e%2e%2f'.$sLicenseFileName, APPROOT, false],
|
||||
$sLicenseFileName => [$sAppRoot.$sLicenseFileName, $sAppRoot, $sItopRootRealPath.$sLicenseFileName],
|
||||
'unexisting file' => [$sAppRoot.'license_DOES_NOT_EXIST.txt', $sAppRoot, false],
|
||||
'/'.$sLicenseFileName => [$sAppRoot.$sSep.$sLicenseFileName, $sAppRoot, $sItopRootRealPath.$sLicenseFileName],
|
||||
'%2f'.$sLicenseFileName => [$sAppRoot.'%2f'. $sLicenseFileName, $sAppRoot, false],
|
||||
'../'.$sLicenseFileName => [$sAppRoot.'..'.$sSep.$sLicenseFileName, $sAppRoot, false],
|
||||
'%2e%2e%2f'.$sLicenseFileName => [$sAppRoot.'%2e%2e%2f'.$sLicenseFileName, $sAppRoot, false],
|
||||
'application/utils.inc.php with basepath=APPROOT' => [
|
||||
APPROOT.'application/utils.inc.php',
|
||||
APPROOT,
|
||||
$sAppRoot.'application/utils.inc.php',
|
||||
$sAppRoot,
|
||||
$sItopRootRealPath.'application'.$sSep.'utils.inc.php',
|
||||
],
|
||||
'application/utils.inc.php with basepath=APPROOT/application' => [
|
||||
APPROOT.'application/utils.inc.php',
|
||||
APPROOT.'application',
|
||||
$sAppRoot.'application/utils.inc.php',
|
||||
$sAppRoot.'application',
|
||||
$sItopRootRealPath.'application'.$sSep.'utils.inc.php',
|
||||
],
|
||||
'basepath containing / and \\' => [
|
||||
APPROOT.'sources/Form/Form.php',
|
||||
APPROOT.'sources/Form\\Form.php',
|
||||
$sAppRoot.'sources/Form/Form.php',
|
||||
$sAppRoot.'sources/Form\\Form.php',
|
||||
$sItopRootRealPath.'sources'.$sSep.'Form'.$sSep.'Form.php',
|
||||
],
|
||||
];
|
||||
@@ -117,13 +118,14 @@ class utilsTest extends ItopTestCase
|
||||
|
||||
public function LocalPathProvider()
|
||||
{
|
||||
$sAppRoot = static::GetAppRoot();
|
||||
return array(
|
||||
'index.php' => array(
|
||||
'sAbsolutePath' => APPROOT.'index.php',
|
||||
'sAbsolutePath' => $sAppRoot.'index.php',
|
||||
'expected' => 'index.php',
|
||||
),
|
||||
'non existing' => array(
|
||||
'sAbsolutePath' => APPROOT.'nonexisting/nonexisting',
|
||||
'sAbsolutePath' => $sAppRoot.'nonexisting/nonexisting',
|
||||
'expected' => false,
|
||||
),
|
||||
'outside' => array(
|
||||
@@ -131,15 +133,15 @@ class utilsTest extends ItopTestCase
|
||||
'expected' => false,
|
||||
),
|
||||
'application/cmdbabstract.class.inc.php' => array(
|
||||
'sAbsolutePath' => APPROOT.'application/cmdbabstract.class.inc.php',
|
||||
'sAbsolutePath' => $sAppRoot.'application/cmdbabstract.class.inc.php',
|
||||
'expected' => 'application/cmdbabstract.class.inc.php',
|
||||
),
|
||||
'dir' => array(
|
||||
'sAbsolutePath' => APPROOT.'application/.',
|
||||
'sAbsolutePath' => $sAppRoot.'application/.',
|
||||
'expected' => 'application',
|
||||
),
|
||||
'root' => array(
|
||||
'sAbsolutePath' => APPROOT.'.',
|
||||
'sAbsolutePath' => $sAppRoot.'.',
|
||||
'expected' => '',
|
||||
),
|
||||
);
|
||||
@@ -288,7 +290,7 @@ class utilsTest extends ItopTestCase
|
||||
|
||||
public function GetDefaultUrlAppRootProvider()
|
||||
{
|
||||
$this->setUp();
|
||||
$sAppRoot = static::GetAppRoot();
|
||||
|
||||
$baseServerVar = [
|
||||
'REMOTE_ADDR' => '127.0.0.1', //is not set, disable IsProxyTrusted
|
||||
@@ -298,7 +300,7 @@ class utilsTest extends ItopTestCase
|
||||
'HTTP_X_FORWARDED_PORT' => null,
|
||||
'REQUEST_URI' => '/index.php?baz=1',
|
||||
'SCRIPT_NAME' => '/index.php',
|
||||
'SCRIPT_FILENAME' => APPROOT.'index.php',
|
||||
'SCRIPT_FILENAME' => $sAppRoot.'index.php',
|
||||
'QUERY_STRING' => 'baz=1',
|
||||
'HTTP_X_FORWARDED_PROTO' => null,
|
||||
'HTTP_X_FORWARDED_PROTOCOL' => null,
|
||||
@@ -486,23 +488,21 @@ class utilsTest extends ItopTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetMentionedObjectsFromTextProvider
|
||||
* @covers utils::GetMentionedObjectsFromText
|
||||
*
|
||||
* @param string $sInput
|
||||
* @param string $sFormat
|
||||
* @param array $aExceptedMentionedObjects
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testGetMentionedObjectsFromText(string $sInput, string $sFormat, array $aExceptedMentionedObjects)
|
||||
public function testGetMentionedObjectsFromText()
|
||||
{
|
||||
$aTestedMentionedObjects = utils::GetMentionedObjectsFromText($sInput, $sFormat);
|
||||
// Emulate the "Case provider mechanism" (reason: the data provider requires utils constants not available before the application startup)
|
||||
foreach ($this->GetMentionedObjectsFromTextProvider() as $sCase => list($sInput, $sFormat, $aExceptedMentionedObjects)) {
|
||||
$aTestedMentionedObjects = utils::GetMentionedObjectsFromText($sInput, $sFormat);
|
||||
|
||||
$sExpectedAsString = print_r($aExceptedMentionedObjects, true);
|
||||
$sTestedAsString = print_r($aTestedMentionedObjects, true);
|
||||
$sExpectedAsString = print_r($aExceptedMentionedObjects, true);
|
||||
$sTestedAsString = print_r($aTestedMentionedObjects, true);
|
||||
|
||||
$this->assertEquals($sTestedAsString, $sExpectedAsString, "Found mentioned objects don't match. Got: $sTestedAsString, expected $sExpectedAsString");
|
||||
$this->assertEquals($sTestedAsString, $sExpectedAsString, "Case '$sCase': Found mentioned objects don't match. Got: $sTestedAsString, expected $sExpectedAsString");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -636,17 +636,13 @@ class utilsTest extends ItopTestCase
|
||||
/**
|
||||
* Test sanitizer.
|
||||
*
|
||||
* @param $type string type of sanitizer
|
||||
* @param $valueToSanitize ? value to sanitize
|
||||
* @param $expectedResult ? expected result
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider sanitizerDataProvider
|
||||
*/
|
||||
public function testSanitizer($type, $valueToSanitize, $expectedResult)
|
||||
public function testSanitizer()
|
||||
{
|
||||
$this->assertEquals($expectedResult, utils::Sanitize($valueToSanitize, null, $type), 'url sanitize failed');
|
||||
// Emulate the "Case provider mechanism" (reason: the data provider requires utils constants not available before the application startup)
|
||||
foreach ($this->sanitizerDataProvider() as $sCase => list($type, $valueToSanitize, $expectedResult)) {
|
||||
$this->assertEquals($expectedResult, utils::Sanitize($valueToSanitize, null, $type), "Case '$sCase': url sanitize failed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,9 +9,6 @@ use MetaModel;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @covers \ActionEmail
|
||||
*/
|
||||
class ActionEmailTest extends ItopDataTestCase
|
||||
|
||||
@@ -5,11 +5,6 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class AttributeDefinitionTest extends ItopDataTestCase {
|
||||
const CREATE_TEST_ORG = true;
|
||||
|
||||
|
||||
@@ -7,9 +7,7 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use MetaModel;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class BulkChangeTest extends ItopDataTestCase {
|
||||
const CREATE_TEST_ORG = true;
|
||||
|
||||
@@ -15,11 +15,6 @@ use MetaModel;
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class CMDBObjectTest extends ItopDataTestCase
|
||||
{
|
||||
private $sAdminLogin;
|
||||
@@ -99,6 +94,7 @@ class CMDBObjectTest extends ItopDataTestCase
|
||||
* @covers CMDBObject::SetCurrentChange
|
||||
* @since 3.0.1 N°5135 - Impersonate: history of changes versus log entries
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
* @dataProvider CurrentChangeUnderImpersonationProvider
|
||||
*/
|
||||
public function testCurrentChangeUnderImpersonation($sTrackInfo=null, $sExpectedChangeLogWhenImpersonation=null) {
|
||||
|
||||
@@ -17,11 +17,6 @@ use utils;
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*/
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class CMDBSourceTest extends ItopTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
@@ -126,6 +121,8 @@ class CMDBSourceTest extends ItopTestCase
|
||||
* @throws \CoreException
|
||||
* @throws \MySQLException
|
||||
* @since 3.0.0 N°4215
|
||||
*
|
||||
* @runInSeparateProcess Resetting DB connection, thus making other tests to fail!
|
||||
*/
|
||||
public function testIsOpenedDbConnectionUsingTls()
|
||||
{
|
||||
|
||||
@@ -14,10 +14,6 @@ use MetaModel;
|
||||
use MySQLTransactionNotClosedException;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @group itopRequestMgmt
|
||||
* @group specificOrgInSampleData
|
||||
* Class TransactionsTest
|
||||
@@ -108,6 +104,15 @@ class TransactionsTest extends ItopTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test case was originaly in DBInsertProvider
|
||||
* @runInSeparateProcess Failing when run in the same process as other...
|
||||
*/
|
||||
public function testDBInsertCaseHistory38()
|
||||
{
|
||||
$this->testDBInsert(40, false);
|
||||
}
|
||||
|
||||
public function DBInsertProvider()
|
||||
{
|
||||
return [
|
||||
@@ -151,7 +156,6 @@ class TransactionsTest extends ItopTestCase
|
||||
"History 35" => ['iFailAt' => 37, 'bIsInDB' => false],
|
||||
"History 36" => ['iFailAt' => 38, 'bIsInDB' => false],
|
||||
"History 37" => ['iFailAt' => 39, 'bIsInDB' => false],
|
||||
"History 38" => ['iFailAt' => 40, 'bIsInDB' => false],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -276,6 +280,7 @@ class TransactionsTest extends ItopTestCase
|
||||
protected function tearDown(): void
|
||||
{
|
||||
try {
|
||||
DbConnectionWrapper::SetDbConnectionMockForQuery();
|
||||
parent::tearDown();
|
||||
}
|
||||
catch (MySQLTransactionNotClosedException $e) {
|
||||
|
||||
@@ -33,10 +33,6 @@ use MetaModel;
|
||||
|
||||
/**
|
||||
* @group specificOrgInSampleData
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBObjectTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -17,10 +17,6 @@ use DBSearch;
|
||||
* <ul>
|
||||
* <li>MakeGroupByQuery</li>
|
||||
* </ul>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBSearchCommitTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -11,10 +11,6 @@ use DBSearch;
|
||||
* Class DBSearchIntersectTest
|
||||
*
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBSearchIntersectTest extends ItopTestCase
|
||||
{
|
||||
@@ -72,16 +68,16 @@ class DBSearchIntersectTest extends ItopTestCase
|
||||
'result' => "SELECT `L`, `P` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id WHERE (`P`.`org_id` = 3)");
|
||||
|
||||
$aTests['Multiple selected classes inverted 1'] = array(
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE 1",
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE 1",
|
||||
'right' => "SELECT Location WHERE org_id = 3",
|
||||
'alias' => "L",
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE (`L`.`org_id` = 3)");
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE (`L`.`org_id` = 3)");
|
||||
|
||||
$aTests['Multiple selected classes inverted 2'] = array(
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE (`L`.`org_id` = 3)",
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE (`L`.`org_id` = 3)",
|
||||
'right' => "SELECT Person WHERE org_id = 3",
|
||||
'alias' => "P",
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE ((`L`.`org_id` = 3) AND (`P`.`org_id` = 3))");
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE ((`L`.`org_id` = 3) AND (`P`.`org_id` = 3))");
|
||||
|
||||
$aTests['Same class'] = array(
|
||||
'left' => "SELECT Contact WHERE name = 'Christie'",
|
||||
@@ -192,9 +188,9 @@ class DBSearchIntersectTest extends ItopTestCase
|
||||
'result' => "SELECT `L`, `P` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id WHERE (`P`.`org_id` = 3)");
|
||||
|
||||
$aTests['Multiple selected classes inverted 2'] = array(
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE (`L`.`org_id` = 3)",
|
||||
'left' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS D ON D.location_id = L.id JOIN Person AS P2 ON P.manager_id = P2.id WHERE (`L`.`org_id` = 3)",
|
||||
'right' => "SELECT Person WHERE org_id = 3",
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN PC AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE ((`L`.`org_id` = 3) AND (`P`.`org_id` = 3))");
|
||||
'result' => "SELECT `L`, `P`, `D` FROM Person AS `P` JOIN Location AS `L` ON `P`.location_id = `L`.id JOIN Server AS `D` ON `D`.location_id = `L`.id JOIN Person AS `P2` ON `P`.manager_id = `P2`.id WHERE ((`L`.`org_id` = 3) AND (`P`.`org_id` = 3))");
|
||||
|
||||
$aTests['Same class'] = array(
|
||||
'left' => "SELECT Contact WHERE name = 'Christie'",
|
||||
|
||||
@@ -11,10 +11,6 @@ use DBSearch;
|
||||
* Class DBSearchIntersectTest
|
||||
*
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBSearchJoinTest extends ItopDataTestCase {
|
||||
|
||||
|
||||
@@ -42,10 +42,6 @@ use FunctionExpression;
|
||||
* <ul>
|
||||
* <li>MakeGroupByQuery</li>
|
||||
* </ul>
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBSearchTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -10,10 +10,6 @@ use DBObjectSearch;
|
||||
* Class DBSearchUpdateRealiasingMapTest
|
||||
*
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBSearchUpdateRealiasingMapTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -7,11 +7,6 @@
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBUnionSearchTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
|
||||
@@ -13,11 +13,6 @@ use FunctionExpression;
|
||||
use MetaModel;
|
||||
use ScalarExpression;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ExpressionEvaluateTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
@@ -5,11 +5,6 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Expression;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ExpressionTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
@@ -17,10 +17,6 @@ use utils;
|
||||
* @group specificOrgInSampleData
|
||||
* Class GetSelectFilterTest
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @package Combodo\iTop\Test\UnitTest\Webservices
|
||||
*/
|
||||
class GetSelectFilterTest extends ItopDataTestCase
|
||||
|
||||
@@ -10,12 +10,6 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use InlineImage;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class InlineImageTest extends ItopDataTestCase
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,8 @@ class DeprecatedCallsLogTest extends ItopTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess Necessary, due to the DeprecatedCallsLog being enabled (no mean to reset)
|
||||
*
|
||||
* The error handler set by DeprecatedCallsLog during startup was causing PHPUnit to miss PHP notices like "undefined offset"
|
||||
*
|
||||
* The error handler is now disabled when running PHPUnit
|
||||
|
||||
@@ -21,11 +21,6 @@ use ExceptionLog;
|
||||
|
||||
require_once(__DIR__.'/ExceptionLogTest/Exceptions.php');
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ExceptionLogTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
@@ -35,6 +30,8 @@ class ExceptionLogTest extends ItopDataTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @dataProvider logProvider
|
||||
*/
|
||||
public function testLogInFile($aLevels, $aExceptions, $sChannel, $aExpectedWriteNumber, $logLevelMin, $aExpectedDbWriteNumber, $logLevelMinWriteInDb)
|
||||
|
||||
@@ -16,11 +16,6 @@ namespace Combodo\iTop\Test\UnitTest\Core\Log;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class LogAPITest extends ItopDataTestCase
|
||||
{
|
||||
private $mockFileLog;
|
||||
@@ -38,7 +33,6 @@ class LogAPITest extends ItopDataTestCase
|
||||
/**
|
||||
* @dataProvider LogApiProvider
|
||||
* @test
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
public function TestLogApi($oConfigObject, $sMessage, $Channel, $sExpectedLevel, $sExpectedMessage, $sExpectedChannel = '')
|
||||
{
|
||||
@@ -63,7 +57,6 @@ class LogAPITest extends ItopDataTestCase
|
||||
/**
|
||||
* @dataProvider LogWarningWithASpecificChannelProvider
|
||||
* @test
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
public function TestLogWarningWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false)
|
||||
{
|
||||
@@ -110,7 +103,6 @@ class LogAPITest extends ItopDataTestCase
|
||||
/**
|
||||
* @dataProvider LogOkWithASpecificChannel
|
||||
* @test
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
public function TestLogOkWithASpecificChannel($expectedCallNb, $sExpectedLevel, $ConfigReturnedObject, $bExceptionRaised=false)
|
||||
{
|
||||
|
||||
@@ -10,10 +10,6 @@ use MetaModel;
|
||||
/**
|
||||
* Class MetaModelTest
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @since 2.6.0
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*/
|
||||
@@ -181,6 +177,8 @@ class MetaModelTest extends ItopDataTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @dataProvider enumPluginsProvider
|
||||
*
|
||||
* @param $expectedResults
|
||||
@@ -228,6 +226,8 @@ class MetaModelTest extends ItopDataTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*
|
||||
* @dataProvider getPluginsProvider
|
||||
*
|
||||
* @param $expectedInstanciationCalls
|
||||
|
||||
@@ -16,11 +16,6 @@ use OQLException;
|
||||
use OqlInterpreter;
|
||||
use OQLParserException;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class OQLParserTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
@@ -21,11 +21,6 @@ use QueryBuilderContext;
|
||||
use SQLObjectQueryBuilder;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class OQLTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
@@ -18,10 +18,6 @@ use TagSetFieldData;
|
||||
|
||||
/**
|
||||
* @group itopFaqLight
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class TagSetFieldDataTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -14,10 +14,6 @@ use TriggerOnObjectCreate;
|
||||
* Class TriggerTest
|
||||
*
|
||||
* @package Combodo\iTop\Test\UnitTest\Core
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class TriggerTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -35,9 +31,9 @@ class TriggerTest extends ItopDataTestCase
|
||||
$oTrigger = MetaModel::NewObject('TriggerOnObjectCreate');
|
||||
$oTrigger->Set('context', ContextTag::TAG_PORTAL.', '.ContextTag::TAG_CRON);
|
||||
$this->assertFalse($oTrigger->IsContextValid());
|
||||
ContextTag::AddContext(ContextTag::TAG_SETUP);
|
||||
$oC1 = new ContextTag(ContextTag::TAG_SETUP);
|
||||
$this->assertFalse($oTrigger->IsContextValid());
|
||||
ContextTag::AddContext(ContextTag::TAG_CRON);
|
||||
$oC2 = new ContextTag(ContextTag::TAG_CRON);
|
||||
$this->assertTrue($oTrigger->IsContextValid());
|
||||
}
|
||||
|
||||
@@ -55,7 +51,7 @@ class TriggerTest extends ItopDataTestCase
|
||||
}
|
||||
catch (\CoreException $e1) {
|
||||
$this->assertEquals('CoreException', get_class($e1));
|
||||
$this->assertEquals('Unknown class \'Toto\' (<b title="Trigger">TriggerOnObjectCreate</b>::-1 ()<br/>)', $e1->getMessage());
|
||||
$this->assertStringStartsWith('Unknown class \'Toto\' (<b title="Trigger">TriggerOnObjectCreate</b>::-', $e1->getMessage());
|
||||
|
||||
$fullStackTraceAsString = $e1->getFullStackTraceAsString();
|
||||
$this->assertStringContainsString("MetaModel::NewObject", $fullStackTraceAsString,"new enriched exception should contain root cause method: " . $fullStackTraceAsString);
|
||||
|
||||
@@ -41,10 +41,6 @@ use utils;
|
||||
* @group itopRequestMgmt
|
||||
* @group userRights
|
||||
* @group defaultProfiles
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class UserRightsTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -68,6 +64,25 @@ class UserRightsTest extends ItopDataTestCase
|
||||
'ModuleInstallation' => ['class' => 'ModuleInstallation', 'attcode' => 'name'],
|
||||
];
|
||||
|
||||
/**
|
||||
* @param string $sLoginPrefix
|
||||
* @param int $iProfileId initial profile
|
||||
*
|
||||
* @return \DBObject
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function CreateUniqueUserAndLogin(string $sLoginPrefix, int $iProfileId): DBObject
|
||||
{
|
||||
static $iCount = 0;
|
||||
$sLogin = $sLoginPrefix.$iCount;
|
||||
$iCount++;
|
||||
|
||||
$oUser = self::CreateUser($sLogin, $iProfileId);
|
||||
$_SESSION = array();
|
||||
UserRights::Login($sLogin);
|
||||
return $oUser;
|
||||
}
|
||||
|
||||
public function testIsLoggedIn()
|
||||
{
|
||||
@@ -90,6 +105,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
$_SESSION = [];
|
||||
$this->assertEquals($bResult, UserRights::Login($sLogin));
|
||||
$this->assertEquals($bResult, UserRights::IsLoggedIn());
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function LoginProvider(): array
|
||||
@@ -101,22 +117,6 @@ class UserRightsTest extends ItopDataTestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sLogin
|
||||
* @param int $iProfileId initial profile
|
||||
*
|
||||
* @return \DBObject
|
||||
* @throws \CoreException
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function AddUser(string $sLogin, int $iProfileId): DBObject
|
||||
{
|
||||
$oUser = self::CreateUser($sLogin, $iProfileId);
|
||||
$oUser->DBUpdate();
|
||||
|
||||
return $oUser;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed when not logged => always true
|
||||
*
|
||||
* @dataProvider ActionAllowedNotLoggedProvider
|
||||
@@ -145,8 +145,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
return $aClassActions;
|
||||
}
|
||||
|
||||
/** Test IsActionAllowed
|
||||
*
|
||||
/**
|
||||
* @dataProvider ActionAllowedProvider
|
||||
*
|
||||
* @param int $iProfileId
|
||||
@@ -158,11 +157,10 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testIsActionAllowed(int $iProfileId, array $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = array();
|
||||
UserRights::Login('test1');
|
||||
$this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
$bRes = UserRights::IsActionAllowed($aClassActionResult['class'], $aClassActionResult['action']) == UR_ALLOWED_YES;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -239,12 +237,11 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testIsActionAllowedOnAttribute(int $iProfileId, array $aClassActionResult)
|
||||
{
|
||||
$this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
$sClass = $aClassActionResult['class'];
|
||||
$bRes = UserRights::IsActionAllowedOnAttribute($sClass, self::$aClasses[$sClass]['attcode'], $aClassActionResult['action']) == UR_ALLOWED_YES;
|
||||
$this->assertEquals($aClassActionResult['res'], $bRes);
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -291,9 +288,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testProfileDenyingConsole(int $iProfileId)
|
||||
{
|
||||
$oUser = $this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
|
||||
try {
|
||||
$this->AddProfileToUser($oUser, 2);
|
||||
@@ -303,6 +298,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function ProfileDenyingConsoleProvider(): array
|
||||
@@ -322,9 +318,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testProfileCannotModifySelf(int $iProfileId)
|
||||
{
|
||||
$oUser = $this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
|
||||
try {
|
||||
$this->AddProfileToUser($oUser, 1); // trying to become an admin
|
||||
@@ -334,6 +328,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function ProfileCannotModifySelfProvider(): array
|
||||
@@ -353,9 +348,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testDeletingSelfUser(int $iProfileId)
|
||||
{
|
||||
$oUser = $this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
|
||||
try {
|
||||
$oUser->DBDelete();
|
||||
@@ -365,6 +358,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function DeletingSelfUserProvider(): array
|
||||
@@ -387,9 +381,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testRemovingOwnContact(int $iProfileId)
|
||||
{
|
||||
$oUser = $this->AddUser('test1', $iProfileId);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', $iProfileId);
|
||||
|
||||
$oUser->Set('contactid', 0);
|
||||
|
||||
@@ -398,6 +390,8 @@ class UserRightsTest extends ItopDataTestCase
|
||||
$this->fail('Current User cannot remove his own contact');
|
||||
} catch (CoreCannotSaveObjectException $e) {
|
||||
}
|
||||
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function RemovingOwnContactProvider(): array
|
||||
@@ -417,9 +411,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testUpgradingToAdmin()
|
||||
{
|
||||
$oUser = $this->AddUser('test1', 3);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', 3);
|
||||
|
||||
try {
|
||||
$this->AddProfileToUser($oUser, 1);
|
||||
@@ -430,6 +422,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -441,9 +434,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testDenyingUserModification()
|
||||
{
|
||||
$oUser = $this->AddUser('test1', 1);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', 1);
|
||||
$this->AddProfileToUser($oUser, 3);
|
||||
|
||||
// Keep only the profile 3 (remove profile 1)
|
||||
@@ -461,6 +452,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -468,10 +460,8 @@ class UserRightsTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testNonAdminCanListOwnProfiles($bHideAdministrators)
|
||||
{
|
||||
$oUser = $this->AddUser('test1', 2); // portal user
|
||||
$_SESSION = [];
|
||||
utils::GetConfig()->Set('security.hide_administrators', $bHideAdministrators);
|
||||
UserRights::Login('test1');
|
||||
$oUser = $this->CreateUniqueUserAndLogin('test1', 2); // portal user
|
||||
|
||||
// List the link between the User and the Profiles
|
||||
$oSearch = new DBObjectSearch('URP_UserProfile');
|
||||
@@ -486,6 +476,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function NonAdminCanListOwnProfilesProvider(): array
|
||||
@@ -496,16 +487,15 @@ class UserRightsTest extends ItopDataTestCase
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*@dataProvider NonAdminCannotListAdminProfilesProvider
|
||||
*/
|
||||
public function testNonAdminCannotListAdminProfiles($bHideAdministrators, $iExpectedCount)
|
||||
{
|
||||
utils::GetConfig()->Set('security.hide_administrators', $bHideAdministrators);
|
||||
|
||||
$this->AddUser('test1', 2); // portal user
|
||||
$oUserAdmin = $this->AddUser('admin1', 1);
|
||||
$_SESSION = [];
|
||||
UserRights::Login('test1');
|
||||
$oUserAdmin = $this->CreateUser('admin1', 1);
|
||||
$this->CreateUniqueUserAndLogin('test1', 2); // portal user
|
||||
|
||||
$oSearch = new DBObjectSearch('URP_UserProfile');
|
||||
$oSearch->AddCondition('userid', $oUserAdmin->GetKey());
|
||||
@@ -518,6 +508,7 @@ class UserRightsTest extends ItopDataTestCase
|
||||
|
||||
// logout
|
||||
$_SESSION = [];
|
||||
UserRights::Logoff();
|
||||
}
|
||||
|
||||
public function NonAdminCannotListAdminProfilesProvider(): array
|
||||
|
||||
@@ -11,11 +11,6 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use MetaModel;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ValueSetObjectsTest extends ItopTestCase
|
||||
{
|
||||
|
||||
|
||||
@@ -33,14 +33,10 @@ use MetaModel;
|
||||
|
||||
/**
|
||||
* @group specificOrgInSampleData
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class XMLDataLoaderTest extends ItopDataTestCase
|
||||
{
|
||||
const CREATE_TEST_ORG = true;
|
||||
const CREATE_TEST_ORG = false;
|
||||
|
||||
public function testDataLoader()
|
||||
{
|
||||
|
||||
@@ -33,8 +33,6 @@ define('UNIT_MAX_CACHE_FILES', 10);
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class apcEmulationTest extends ItopTestCase
|
||||
{
|
||||
|
||||
@@ -32,8 +32,6 @@ use Dict;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class dictApcuTest extends ItopTestCase
|
||||
{
|
||||
|
||||
@@ -30,11 +30,8 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Dict;
|
||||
use Exception;
|
||||
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class dictTest extends ItopTestCase
|
||||
{
|
||||
|
||||
@@ -15,10 +15,6 @@ use ormCaseLog;
|
||||
* Tests of the ormCaseLog class
|
||||
*
|
||||
* @covers \ormCaseLog
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormCaseLogTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -37,10 +37,6 @@ use ormLinkSet;
|
||||
* @group itopRequestMgmt
|
||||
* @group itopConfigMgmt
|
||||
* Tests of the ormLinkSet class using N-N links between FunctionalCI and Contact
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormLinkSetTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -12,10 +12,6 @@ use Utils;
|
||||
|
||||
/**
|
||||
* Tests of the ormPassword class
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormPasswordTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -32,9 +28,11 @@ class ormPasswordTest extends ItopDataTestCase
|
||||
*/
|
||||
public function testCheckHash($sToHashValues, $sToHashSalt, $sHashAlgo, $sExpectedHash)
|
||||
{
|
||||
$prevHashAlgo = utils::GetConfig()->GetPasswordHashAlgo($sHashAlgo);
|
||||
utils::GetConfig()->SetPasswordHashAlgo($sHashAlgo);
|
||||
$oPassword1 = new ormPassword($sExpectedHash, $sToHashSalt);
|
||||
static::assertTrue($oPassword1->CheckPassword($sToHashValues));
|
||||
utils::GetConfig()->SetPasswordHashAlgo($prevHashAlgo);
|
||||
}
|
||||
|
||||
public function HashProvider()
|
||||
|
||||
@@ -12,10 +12,6 @@ use utils;
|
||||
|
||||
/**
|
||||
* Tests of the ormStyle class
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormStyleTest extends ItopTestCase
|
||||
{
|
||||
|
||||
@@ -38,10 +38,6 @@ define('MAX_TAGS', 12);
|
||||
/**
|
||||
* @group itopFaqLight
|
||||
* Tests of the ormTagSet class
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ormTagSetTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -24,10 +24,6 @@ use utils;
|
||||
|
||||
/**
|
||||
* test class for UserLocal class
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class UserLocalTest extends ItopDataTestCase
|
||||
{
|
||||
@@ -398,6 +394,9 @@ class UserLocalTest extends ItopDataTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess Otherwise, and only in the CI, test fails asserting $oProfilesSet->Count() == 0
|
||||
*/
|
||||
public function testGetUserProfileList()
|
||||
{
|
||||
utils::GetConfig()->SetModuleSetting('authent-local', 'password_validation.pattern', '');
|
||||
|
||||
@@ -24,11 +24,6 @@ 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
|
||||
|
||||
@@ -24,11 +24,6 @@ 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
|
||||
|
||||
@@ -34,10 +34,6 @@ use Exception;
|
||||
* @group itopVirtualizationMgmt
|
||||
* @group itopConfigMgmt
|
||||
* @group itopTickets
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class ItopTicketTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -7,11 +7,6 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use DBBackup;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DBBackupTest extends ItopTestCase
|
||||
{
|
||||
/**
|
||||
@@ -27,7 +22,7 @@ class DBBackupTest extends ItopTestCase
|
||||
// We need a connection to the DB, so let's open it !
|
||||
// We are using the default config file... as the server might not be configured for all the combination we are testing
|
||||
// For example dev env and ci env won't accept TLS connection
|
||||
$oConfigOnDisk = utils::GetConfig();
|
||||
$oConfigOnDisk = utils::GetConfig(true);
|
||||
CMDBSource::InitFromConfig($oConfigOnDisk);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@ use SubMFCompiler;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @runClassInSeparateProcess
|
||||
* @covers \MFCompiler::UseLatestPrecompiledFile
|
||||
*/
|
||||
class MFCompilerTest extends ItopTestCase {
|
||||
@@ -53,9 +51,9 @@ class MFCompilerTest extends ItopTestCase {
|
||||
$sSourceDir = $sAppRootForProvider . 'datamodels' . DIRECTORY_SEPARATOR . '2.x';
|
||||
$sDatamodel2xTargetDir = $sSourceDir . DIRECTORY_SEPARATOR . '/UseLatestPrecompiledFileProvider';
|
||||
|
||||
mkdir($sTempTargetDir);
|
||||
mkdir($sExtensionTargetDir);
|
||||
mkdir($sDatamodel2xTargetDir);
|
||||
if (!is_dir($sTempTargetDir)) mkdir($sTempTargetDir);
|
||||
if (!is_dir($sExtensionTargetDir)) @mkdir($sExtensionTargetDir);
|
||||
if (!is_dir($sDatamodel2xTargetDir)) @mkdir($sDatamodel2xTargetDir);
|
||||
|
||||
self::$aFoldersToCleanup = [ $sTempTargetDir, $sExtensionTargetDir, $sDatamodel2xTargetDir ];
|
||||
|
||||
|
||||
@@ -10,9 +10,6 @@ use Combodo\iTop\Application\Helper\WebResourcesHelper;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @covers \WebPage
|
||||
*/
|
||||
class WebResourcesHelperTest extends ItopTestCase
|
||||
|
||||
@@ -14,10 +14,6 @@ use SecurityException;
|
||||
/**
|
||||
* We need the metamodel started as this is a dependency of {@link RuntimeDashboard}
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*
|
||||
* @since 2.7.8 3.0.3 3.1.0 N°4449 Test Full Path Disclosure in Dashboard
|
||||
*/
|
||||
class RuntimeDashboardTest extends ItopDataTestCase
|
||||
|
||||
@@ -8,11 +8,6 @@ namespace Combodo\iTop\Test\UnitTest\Application;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class TestAutoload extends ItopDataTestCase
|
||||
{
|
||||
|
||||
|
||||
@@ -2,15 +2,11 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Application\TwigBase;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use Combodo\iTop\Portal\Twig\AppExtension;
|
||||
use Twig_Environment;
|
||||
use Twig_Loader_Array;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class TwigTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
|
||||
@@ -44,14 +44,11 @@ use Dict;
|
||||
/**
|
||||
* @group itopRequestMgmt
|
||||
* @group itopServiceMgmt
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class CriterionConversionTest extends ItopDataTestCase
|
||||
{
|
||||
const CREATE_TEST_ORG = true;
|
||||
const CREATE_TEST_ORG = false;
|
||||
const USE_TRANSACTION = false;
|
||||
|
||||
/**
|
||||
* @dataProvider ToOqlProvider
|
||||
@@ -409,9 +406,7 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
* @dataProvider OqlProvider
|
||||
*
|
||||
* @param $sOQL
|
||||
*
|
||||
* @param $sExpectedOQL
|
||||
*
|
||||
* @param $aExpectedCriterion
|
||||
*
|
||||
* @throws \DictExceptionUnknownLanguage
|
||||
@@ -425,7 +420,7 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'First');
|
||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'Second');
|
||||
|
||||
$this->OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion, "EN US");
|
||||
$this->OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion);
|
||||
}
|
||||
|
||||
function OqlProvider()
|
||||
@@ -589,9 +584,7 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
* @dataProvider OqlProviderDates
|
||||
*
|
||||
* @param $sOQL
|
||||
*
|
||||
* @param $sExpectedOQL
|
||||
*
|
||||
* @param $aExpectedCriterion
|
||||
*
|
||||
* @throws \DictExceptionUnknownLanguage
|
||||
@@ -599,33 +592,11 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
* @throws \OQLException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
function testOqlToForSearchToOqlAltLanguageFR($sOQL, $sExpectedOQL, $aExpectedCriterion)
|
||||
function testOqlToForSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion)
|
||||
{
|
||||
\MetaModel::GetConfig()->Set('date_and_time_format', array('default' => array('date' => 'Y-m-d', 'time' => 'H:i:s', 'date_time' => '$date $time')));
|
||||
$this->OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion, "FR FR");
|
||||
$this->OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider OqlProviderDates
|
||||
*
|
||||
* @param $sOQL
|
||||
*
|
||||
* @param $sExpectedOQL
|
||||
*
|
||||
* @param $aExpectedCriterion
|
||||
*
|
||||
* @throws \DictExceptionUnknownLanguage
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \OQLException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
function testOqlToForSearchToOqlAltLanguageEN($sOQL, $sExpectedOQL, $aExpectedCriterion)
|
||||
{
|
||||
\MetaModel::GetConfig()->Set('date_and_time_format', array('default' => array('date' => 'Y-m-d', 'time' => 'H:i:s', 'date_time' => '$date $time')));
|
||||
$this->OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion, "EN US");
|
||||
}
|
||||
|
||||
function OqlProviderDates()
|
||||
{
|
||||
return array(
|
||||
@@ -706,26 +677,18 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
/**
|
||||
*
|
||||
* @param $sOQL
|
||||
*
|
||||
* @param $sExpectedOQL
|
||||
*
|
||||
* @param $aExpectedCriterion
|
||||
*
|
||||
* @param $sLanguageCode
|
||||
*
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionUnknownLanguage
|
||||
* @throws \MissingQueryArgument
|
||||
* @throws \OQLException
|
||||
*/
|
||||
function OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion, $sLanguageCode )
|
||||
function OqlToSearchToOqlAltLanguage($sOQL, $sExpectedOQL, $aExpectedCriterion)
|
||||
{
|
||||
$this->debug($sOQL);
|
||||
|
||||
|
||||
Dict::SetUserLanguage($sLanguageCode);
|
||||
|
||||
|
||||
$oSearchForm = new SearchForm();
|
||||
$oSearch = DBSearch::FromOQL($sOQL);
|
||||
$aFields = $oSearchForm->GetFields(new DBObjectSet($oSearch));
|
||||
|
||||
@@ -33,9 +33,6 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
/**
|
||||
* @group itopRequestMgmt
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class CriterionParserTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -29,14 +29,10 @@ use Exception;
|
||||
|
||||
/**
|
||||
* @group itopRequestMgmt
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class SearchFormTest extends ItopDataTestCase
|
||||
{
|
||||
const CREATE_TEST_ORG = true;
|
||||
const CREATE_TEST_ORG = false;
|
||||
|
||||
/**
|
||||
* @dataProvider GetFieldsProvider
|
||||
|
||||
@@ -15,11 +15,6 @@ if (!defined('DEBUG_UNIT_TEST')) {
|
||||
define('DEBUG_UNIT_TEST', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class StatusIncTest extends ItopTestCase {
|
||||
|
||||
/**
|
||||
@@ -70,7 +65,10 @@ class StatusIncTest extends ItopTestCase {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testStatusStartupWrongDbPwd()
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testStatusStartupWrongDbPwd()
|
||||
{
|
||||
$this->RequireOnceItopFile('core/cmdbobject.class.inc.php');
|
||||
$this->RequireOnceItopFile('application/utils.inc.php');
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace Combodo\iTop\Test\UnitTest\Status;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use Config;
|
||||
|
||||
class StatusTest extends ItopTestCase
|
||||
{
|
||||
@@ -25,10 +26,18 @@ class StatusTest extends ItopTestCase
|
||||
|
||||
}
|
||||
|
||||
protected function GetPHPCommand()
|
||||
{
|
||||
$this->RequireOnceItopFile('application/utils.inc.php');
|
||||
$oConfig = new Config(ITOP_DEFAULT_CONFIG_FILE);
|
||||
return $oConfig->Get('php_path');
|
||||
}
|
||||
|
||||
public function testStatusGood() {
|
||||
$sPath = APPROOT.'/webservices/status.php';
|
||||
|
||||
exec("php $sPath", $aOutput, $iRet);
|
||||
$sPHP = $this->GetPHPCommand();
|
||||
exec("$sPHP $sPath", $aOutput, $iRet);
|
||||
$this->assertEquals(0, $iRet, "Problem executing status page: $sPath, $iRet, aOutput:\n".var_export($aOutput, true));
|
||||
}
|
||||
|
||||
@@ -39,7 +48,8 @@ class StatusTest extends ItopTestCase
|
||||
{
|
||||
$sPath = APPROOT.'/webservices/status.php';
|
||||
|
||||
exec("php $sPath", $aOutput, $iRet);
|
||||
$sPHP = $this->GetPHPCommand();
|
||||
exec("$sPHP $sPath", $aOutput, $iRet);
|
||||
$sAdditionalInfo = "aOutput:\n".var_export($aOutput, true).'.';
|
||||
|
||||
//Check response
|
||||
|
||||
@@ -31,10 +31,6 @@ use utils;
|
||||
* @package Combodo\iTop\Test\UnitTest\Synchro
|
||||
* @group dataSynchro
|
||||
* @group defaultProfiles
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class DataSynchroTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -10,8 +10,6 @@ use MetaModel;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
*/
|
||||
class CliResetSessionTest extends ItopDataTestCase
|
||||
{
|
||||
|
||||
@@ -13,13 +13,12 @@ use utils;
|
||||
* @group restApi
|
||||
* @group defaultProfiles
|
||||
*
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @backupGlobals disabled
|
||||
* @runClassInSeparateProcess
|
||||
*/
|
||||
class RestTest extends ItopDataTestCase
|
||||
{
|
||||
const USE_TRANSACTION = false;
|
||||
const CREATE_TEST_ORG = false;
|
||||
|
||||
const ENUM_JSONDATA_AS_STRING = 0;
|
||||
const ENUM_JSONDATA_AS_FILE = 1;
|
||||
|
||||
Reference in New Issue
Block a user