diff --git a/core/DbConnectionWrapper.php b/core/DbConnectionWrapper.php
index 2b25128ab..f432bb262 100644
--- a/core/DbConnectionWrapper.php
+++ b/core/DbConnectionWrapper.php
@@ -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;
+ }
}
}
\ No newline at end of file
diff --git a/core/dict.class.inc.php b/core/dict.class.inc.php
index e96ddfed9..ff9ef890a 100644
--- a/core/dict.class.inc.php
+++ b/core/dict.class.inc.php
@@ -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);
}
diff --git a/core/log.class.inc.php b/core/log.class.inc.php
index 2af8dc5b2..8f59e7e4c 100644
--- a/core/log.class.inc.php
+++ b/core/log.class.inc.php
@@ -1138,7 +1138,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);
diff --git a/core/metamodel.class.php b/core/metamodel.class.php
index c8dd16292..60afe675f 100644
--- a/core/metamodel.class.php
+++ b/core/metamodel.class.php
@@ -6298,6 +6298,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;
try {
@@ -6529,6 +6536,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
*/
diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php
index 699dd597d..317608927 100644
--- a/core/userrights.class.inc.php
+++ b/core/userrights.class.inc.php
@@ -761,14 +761,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
*
@@ -787,8 +798,7 @@ class UserRights
}
self::$m_oAddOn = new $sModuleName;
self::$m_oAddOn->Init();
- self::$m_oUser = null;
- self::$m_oRealUser = null;
+ self::ResetCurrentUserData();
}
/**
@@ -855,6 +865,8 @@ class UserRights
*/
public static function Login($sLogin, $sAuthentication = 'any')
{
+ static::Logoff();
+
$oUser = self::FindUser($sLogin, $sAuthentication);
if (is_null($oUser))
{
@@ -872,6 +884,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
diff --git a/datamodels/2.x/itop-backup/dbrestore.class.inc.php b/datamodels/2.x/itop-backup/dbrestore.class.inc.php
index d285e8cf2..669d04bbc 100644
--- a/datamodels/2.x/itop-backup/dbrestore.class.inc.php
+++ b/datamodels/2.x/itop-backup/dbrestore.class.inc.php
@@ -235,13 +235,16 @@ class DBRestore extends DBBackup
if (in_array($oFileInfo->getFilename(), $aStandardFiles)) {
continue;
}
- if (strncmp($oFileInfo->getPathname(), $sDataDir.'/production-modules', strlen($sDataDir.'/production-modules')) == 0) {
+ // Normalize filenames to cope with Windows backslashes
+ $sPath = str_replace('\\', '/', $oFileInfo->getPathname());
+ $sRefPath = str_replace('\\', '/', $sDataDir.'/production-modules');
+ if (strncmp($sPath, $sRefPath, strlen($sRefPath)) == 0) {
continue;
}
-
+
$aExtraFiles[$oFileInfo->getPathname()] = APPROOT.substr($oFileInfo->getPathname(), strlen($sDataDir));
}
-
+
return $aExtraFiles;
}
}
diff --git a/tests/php-unit-tests/README.md b/tests/php-unit-tests/README.md
index e4058802c..26c32491a 100644
--- a/tests/php-unit-tests/README.md
+++ b/tests/php-unit-tests/README.md
@@ -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".
\ No newline at end of file
+ - 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
+
*
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class DBSearchCommitTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearchIntersectTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearchIntersectTest.php
index b87c44de3..7e4c6c6fc 100644
--- a/tests/php-unit-tests/unitary-tests/core/DBSearchIntersectTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/DBSearchIntersectTest.php
@@ -11,10 +11,6 @@ use DBSearch;
* Class DBSearchIntersectTest
*
* @package Combodo\iTop\Test\UnitTest\Core
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class DBSearchIntersectTest extends ItopTestCase
{
@@ -71,16 +67,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'",
@@ -191,9 +187,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'",
diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearchJoinTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearchJoinTest.php
index 468c9ef92..55077d4d1 100644
--- a/tests/php-unit-tests/unitary-tests/core/DBSearchJoinTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/DBSearchJoinTest.php
@@ -11,10 +11,6 @@ use DBSearch;
* Class DBSearchIntersectTest
*
* @package Combodo\iTop\Test\UnitTest\Core
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class DBSearchJoinTest extends ItopDataTestCase {
diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php
index 2a6de4c6d..09265d8d4 100644
--- a/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/DBSearchTest.php
@@ -43,10 +43,6 @@ use FunctionExpression;
*
*
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class DBSearchTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearchUpdateRealiasingMapTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearchUpdateRealiasingMapTest.php
index 4fd6a3ace..44670c985 100644
--- a/tests/php-unit-tests/unitary-tests/core/DBSearchUpdateRealiasingMapTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/DBSearchUpdateRealiasingMapTest.php
@@ -10,10 +10,6 @@ use DBObjectSearch;
* Class DBSearchUpdateRealiasingMapTest
*
* @package Combodo\iTop\Test\UnitTest\Core
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class DBSearchUpdateRealiasingMapTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/DBUnionSearchTest.php b/tests/php-unit-tests/unitary-tests/core/DBUnionSearchTest.php
index 1b65ce66f..bcf382ac7 100644
--- a/tests/php-unit-tests/unitary-tests/core/DBUnionSearchTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/DBUnionSearchTest.php
@@ -7,11 +7,6 @@
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class DBUnionSearchTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/ExpressionEvaluateTest.php b/tests/php-unit-tests/unitary-tests/core/ExpressionEvaluateTest.php
index b97e4e385..f748d2422 100644
--- a/tests/php-unit-tests/unitary-tests/core/ExpressionEvaluateTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ExpressionEvaluateTest.php
@@ -13,11 +13,6 @@ use FunctionExpression;
use MetaModel;
use ScalarExpression;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class ExpressionEvaluateTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
diff --git a/tests/php-unit-tests/unitary-tests/core/ExpressionTest.php b/tests/php-unit-tests/unitary-tests/core/ExpressionTest.php
index 838143180..56f9869c6 100644
--- a/tests/php-unit-tests/unitary-tests/core/ExpressionTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ExpressionTest.php
@@ -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;
diff --git a/tests/php-unit-tests/unitary-tests/core/GetSelectFilterTest.php b/tests/php-unit-tests/unitary-tests/core/GetSelectFilterTest.php
index e38e78885..f1056e608 100644
--- a/tests/php-unit-tests/unitary-tests/core/GetSelectFilterTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/GetSelectFilterTest.php
@@ -20,10 +20,6 @@ use UserRightsProfile;
* @group specificOrgInSampleData
* Class GetSelectFilterTest
*
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- *
* @package Combodo\iTop\Test\UnitTest\Webservices
*/
class GetSelectFilterTest extends ItopDataTestCase
diff --git a/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php b/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
index f4a6d6a21..d3066ecf0 100644
--- a/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/InlineImageTest.php
@@ -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
{
/**
diff --git a/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php b/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php
index 582711b50..055e67669 100644
--- a/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest.php b/tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest.php
index e2074c84a..d4e84cdb8 100644
--- a/tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/Log/ExceptionLogTest.php
@@ -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)
diff --git a/tests/php-unit-tests/unitary-tests/core/Log/LogAPITest.php b/tests/php-unit-tests/unitary-tests/core/Log/LogAPITest.php
index 8f16aaf0e..910245147 100644
--- a/tests/php-unit-tests/unitary-tests/core/Log/LogAPITest.php
+++ b/tests/php-unit-tests/unitary-tests/core/Log/LogAPITest.php
@@ -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)
{
diff --git a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php
index a65c7008c..c8c9de667 100644
--- a/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/MetaModelTest.php
@@ -10,10 +10,6 @@ use MetaModel;
/**
* Class MetaModelTest
*
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- *
* @since 2.6.0
* @package Combodo\iTop\Test\UnitTest\Core
*/
@@ -220,6 +216,8 @@ class MetaModelTest extends ItopDataTestCase
}
/**
+ * @runInSeparateProcess
+ *
* @dataProvider enumPluginsProvider
*
* @param $expectedResults
@@ -267,6 +265,8 @@ class MetaModelTest extends ItopDataTestCase
}
/**
+ * @runInSeparateProcess
+ *
* @dataProvider getPluginsProvider
*
* @param $expectedInstanciationCalls
diff --git a/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php b/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
index 63cd2c626..d18148abd 100644
--- a/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/OQLParserTest.php
@@ -16,11 +16,6 @@ use OQLException;
use OqlInterpreter;
use OQLParserException;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class OQLParserTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
diff --git a/tests/php-unit-tests/unitary-tests/core/OQLTest.php b/tests/php-unit-tests/unitary-tests/core/OQLTest.php
index 40a2e0845..de81dc512 100644
--- a/tests/php-unit-tests/unitary-tests/core/OQLTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/OQLTest.php
@@ -21,11 +21,6 @@ use QueryBuilderContext;
use SQLObjectQueryBuilder;
use utils;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class OQLTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
diff --git a/tests/php-unit-tests/unitary-tests/core/TagSetFieldDataTest.php b/tests/php-unit-tests/unitary-tests/core/TagSetFieldDataTest.php
index a1ee34772..136ab2900 100644
--- a/tests/php-unit-tests/unitary-tests/core/TagSetFieldDataTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/TagSetFieldDataTest.php
@@ -18,10 +18,6 @@ use TagSetFieldData;
/**
* @group itopFaqLight
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class TagSetFieldDataTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/TriggerTest.php b/tests/php-unit-tests/unitary-tests/core/TriggerTest.php
index 12744e34f..f8abde406 100644
--- a/tests/php-unit-tests/unitary-tests/core/TriggerTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/TriggerTest.php
@@ -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\' (TriggerOnObjectCreate::-1 ()
)', $e1->getMessage());
+ $this->assertStringStartsWith('Unknown class \'Toto\' (TriggerOnObjectCreate::-', $e1->getMessage());
$fullStackTraceAsString = $e1->getFullStackTraceAsString();
$this->assertStringContainsString("MetaModel::NewObject", $fullStackTraceAsString,"new enriched exception should contain root cause method: " . $fullStackTraceAsString);
diff --git a/tests/php-unit-tests/unitary-tests/core/UniquenessMessageTest.php b/tests/php-unit-tests/unitary-tests/core/UniquenessMessageTest.php
index 03495dfb5..9e11e4868 100644
--- a/tests/php-unit-tests/unitary-tests/core/UniquenessMessageTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/UniquenessMessageTest.php
@@ -12,10 +12,6 @@ use Team;
/**
* Class UniquenessMessageTest
*
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- *
* @package Combodo\iTop\Test\UnitTest\Core
*/
class UniquenessMessageTest extends ItopDataTestCase
diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php
index 0b4cc29e4..51734ee4f 100644
--- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/core/ValueSetObjectsTest.php b/tests/php-unit-tests/unitary-tests/core/ValueSetObjectsTest.php
index 9f7089f3f..0483f5e24 100644
--- a/tests/php-unit-tests/unitary-tests/core/ValueSetObjectsTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ValueSetObjectsTest.php
@@ -11,11 +11,6 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
use MetaModel;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class ValueSetObjectsTest extends ItopTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/XMLDataLoaderTest.php b/tests/php-unit-tests/unitary-tests/core/XMLDataLoaderTest.php
index 5ee47bc1b..2615e6bc9 100644
--- a/tests/php-unit-tests/unitary-tests/core/XMLDataLoaderTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/XMLDataLoaderTest.php
@@ -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()
{
diff --git a/tests/php-unit-tests/unitary-tests/core/apcEmulationTest.php b/tests/php-unit-tests/unitary-tests/core/apcEmulationTest.php
index 2d29703fe..ce9d90601 100644
--- a/tests/php-unit-tests/unitary-tests/core/apcEmulationTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/apcEmulationTest.php
@@ -33,8 +33,6 @@ define('UNIT_MAX_CACHE_FILES', 10);
/**
* @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class apcEmulationTest extends ItopTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/dictApcuTest.php b/tests/php-unit-tests/unitary-tests/core/dictApcuTest.php
index 3e2d992c0..4acf314a1 100644
--- a/tests/php-unit-tests/unitary-tests/core/dictApcuTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/dictApcuTest.php
@@ -32,8 +32,6 @@ use Dict;
/**
* @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class dictApcuTest extends ItopTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/dictTest.php b/tests/php-unit-tests/unitary-tests/core/dictTest.php
index a657bf30f..f43ad0c87 100644
--- a/tests/php-unit-tests/unitary-tests/core/dictTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/dictTest.php
@@ -30,11 +30,8 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Dict;
use Exception;
-
/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
+ * @runClassInSeparateProcess
*/
class dictTest extends ItopTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php
index 484be7951..326964dbe 100644
--- a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php
@@ -15,10 +15,6 @@ use ormCaseLog;
* Tests of the ormCaseLog class
*
* @covers \ormCaseLog
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class ormCaseLogTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/ormLinkSetTest.php b/tests/php-unit-tests/unitary-tests/core/ormLinkSetTest.php
index 01db719fa..4889c05a8 100644
--- a/tests/php-unit-tests/unitary-tests/core/ormLinkSetTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ormLinkSetTest.php
@@ -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
{
diff --git a/tests/php-unit-tests/unitary-tests/core/ormPasswordTest.php b/tests/php-unit-tests/unitary-tests/core/ormPasswordTest.php
index d170382ba..6d8c0ca34 100644
--- a/tests/php-unit-tests/unitary-tests/core/ormPasswordTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ormPasswordTest.php
@@ -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()
diff --git a/tests/php-unit-tests/unitary-tests/core/ormStyleTest.php b/tests/php-unit-tests/unitary-tests/core/ormStyleTest.php
index ca74964de..737bc06b2 100644
--- a/tests/php-unit-tests/unitary-tests/core/ormStyleTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ormStyleTest.php
@@ -12,10 +12,6 @@ use utils;
/**
* Tests of the ormStyle class
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class ormStyleTest extends ItopTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/core/ormTagSetTest.php b/tests/php-unit-tests/unitary-tests/core/ormTagSetTest.php
index 890ecf460..e67bfa0dc 100644
--- a/tests/php-unit-tests/unitary-tests/core/ormTagSetTest.php
+++ b/tests/php-unit-tests/unitary-tests/core/ormTagSetTest.php
@@ -38,10 +38,6 @@ define('MAX_TAGS', 12);
/**
* @group itopFaqLight
* Tests of the ormTagSet class
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class ormTagSetTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php
index f558ef125..d8484d182 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php
@@ -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', '');
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php
index 8c8372ae3..0fedb3d5b 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/BulkChangeExtKeyTest.php
@@ -8,15 +8,13 @@ use MetaModel;
/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- *
* created a dedicated test for external keys imports.
*
* Class BulkChangeExtKeyTest
*
* @package Combodo\iTop\Test\UnitTest\Core
+ *
+ * @runTestsInSeparateProcesses
*/
class BulkChangeExtKeyTest extends ItopDataTestCase {
const CREATE_TEST_ORG = true;
@@ -227,13 +225,6 @@ class BulkChangeExtKeyTest extends ItopDataTestCase {
return $this->sUid;
}
- /** *
- * @param $aInitData
- * @param $aCsvData
- * @param $aAttributes
- * @param $aExtKeys
- * @param $aReconcilKeys
- */
public function performBulkChangeTest($sExpectedDisplayableValue, $sExpectedDescription, $oOrg, $bIsRackReconKey,
$aAdditionalCsvData=null, $aExtKeys=null, $sSearchLinkUrl=null, $sError="Object not found") {
if ($sSearchLinkUrl===null){
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php
index c4f5e825b..914110fc7 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php
@@ -10,16 +10,11 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use lnkContactToFunctionalCI;
use MetaModel;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class DBObjectTest extends ItopDataTestCase
{
const USE_TRANSACTION = true;
const CREATE_TEST_ORG = true;
- const DEBUG_UNIT_TEST = true;
+ const DEBUG_UNIT_TEST = false;
public function testReloadNotNecessaryForInsert()
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigPlaceholdersResolverTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigPlaceholdersResolverTest.php
index 8c82371e0..51b31d920 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigPlaceholdersResolverTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigPlaceholdersResolverTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigTest.php
index 178440826..6d963499a 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/ConfigTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-tickets/itopTicketTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-tickets/itopTicketTest.php
index 73e168f88..a53e50a15 100644
--- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-tickets/itopTicketTest.php
+++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-tickets/itopTicketTest.php
@@ -34,10 +34,6 @@ use Exception;
* @group itopVirtualizationMgmt
* @group itopConfigMgmt
* @group itopTickets
- *
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class ItopTicketTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php b/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php
index 02ec0734a..129664c74 100644
--- a/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php
+++ b/tests/php-unit-tests/unitary-tests/setup/DBBackupDataTest.php
@@ -8,11 +8,6 @@ use DBRestore;
use MetaModel;
use SetupUtils;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class DBBackupDataTest extends ItopDataTestCase
{
/**
@@ -32,35 +27,33 @@ class DBBackupDataTest extends ItopDataTestCase
file_put_contents(APPROOT.'/'.$sExtraFile, 'Hello World!');
}
}
-
- if ($bUnsafeFileException)
- {
- $this->expectExceptionMessage("Backup: Aborting, resource '$sExtraFile'. Considered as UNSAFE because not inside the iTop directory.");
- }
- $aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT.'/conf/production/config-itop.php', $sTmpDir, true]);
- SetupUtils::rrmdir($sTmpDir);
- $aExpectedFiles = [
- $sTmpDir.'/config-itop.php',
- ];
- foreach($aExtraFiles as $sRelFile => $bExists)
- {
- if ($bExists)
- {
- $aExpectedFiles[] = $sTmpDir.'/'.$sRelFile;
+
+ try {
+ if ($bUnsafeFileException) {
+ $this->expectExceptionMessage("Backup: Aborting, resource '$sExtraFile'. Considered as UNSAFE because not inside the iTop directory.");
+ }
+ $aFiles = $this->InvokeNonPublicMethod('DBBackup', 'PrepareFilesToBackup', $oBackup, [APPROOT . '/conf/production/config-itop.php', $sTmpDir, true]);
+ SetupUtils::rrmdir($sTmpDir);
+ $aExpectedFiles = [
+ $sTmpDir . '/config-itop.php',
+ ];
+ foreach ($aExtraFiles as $sRelFile => $bExists) {
+ if ($bExists) {
+ $aExpectedFiles[] = $sTmpDir . '/' . $sRelFile;
+ }
+ }
+ } finally {
+ // Cleanup
+ foreach ($aExtraFiles as $sExtraFile => $bExists) {
+ if ($bExists) {
+ unlink(APPROOT . '/' . $sExtraFile);
+ }
}
}
+
sort($aFiles);
sort($aExpectedFiles);
$this->assertEquals($aFiles, $aExpectedFiles);
-
- // Cleanup
- foreach($aExtraFiles as $sExtraFile => $bExists)
- {
- if ($bExists)
- {
- unlink(APPROOT.'/'.$sExtraFile);
- }
- }
}
function prepareFilesToBackupProvider()
@@ -95,9 +88,15 @@ class DBBackupDataTest extends ItopDataTestCase
$aExpectedExtraFiles = [];
foreach($aExpectedRelativeExtraFiles as $sRelativeName)
{
- $aExpectedExtraFiles[$sTmpDir.'/'.$sRelativeName] = APPROOT.'/'.$sRelativeName;
+ if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+ $sRelativeName = str_replace('/', '\\', $sRelativeName);
+ $aExpectedExtraFiles[$sTmpDir.'\\'.$sRelativeName] = APPROOT.'\\'.$sRelativeName;
+ }
+ else {
+ $aExpectedExtraFiles[$sTmpDir.'/'.$sRelativeName] = APPROOT.'/'.$sRelativeName;
+ }
}
-
+
$oRestore = new DBRestore(MetaModel::GetConfig());
$aExtraFiles = $this->InvokeNonPublicMethod('DBRestore', 'ListExtraFiles', $oRestore, [$sTmpDir]);
diff --git a/tests/php-unit-tests/unitary-tests/setup/DBBackupTest.php b/tests/php-unit-tests/unitary-tests/setup/DBBackupTest.php
index 715a6173b..1267921ad 100644
--- a/tests/php-unit-tests/unitary-tests/setup/DBBackupTest.php
+++ b/tests/php-unit-tests/unitary-tests/setup/DBBackupTest.php
@@ -8,11 +8,6 @@ use DateTime;
use DBBackup;
use utils;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class DBBackupTest extends ItopTestCase
{
protected const DUMMY_DB_HOST = 'localhost';
@@ -32,7 +27,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);
}
diff --git a/tests/php-unit-tests/unitary-tests/setup/MFCompilerTest.php b/tests/php-unit-tests/unitary-tests/setup/MFCompilerTest.php
index 0794677ef..e3e0ca40f 100644
--- a/tests/php-unit-tests/unitary-tests/setup/MFCompilerTest.php
+++ b/tests/php-unit-tests/unitary-tests/setup/MFCompilerTest.php
@@ -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 ];
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Helper/WebResourcesHelperTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Helper/WebResourcesHelperTest.php
index 4fc30b2b3..515f4a432 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Helper/WebResourcesHelperTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Helper/WebResourcesHelperTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/RuntimeDashboardTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/RuntimeDashboardTest.php
index 7261f170e..5c18c86b0 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/RuntimeDashboardTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/RuntimeDashboardTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionConversionTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionConversionTest.php
index 644f57395..aa117c78f 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionConversionTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionConversionTest.php
@@ -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));
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionParserTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionParserTest.php
index 06921b627..00b7aa5d1 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionParserTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Search/CriterionParserTest.php
@@ -33,9 +33,6 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
/**
* @group itopRequestMgmt
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class CriterionParserTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Search/SearchFormTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Search/SearchFormTest.php
index 85f9c09ba..133cde21c 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Search/SearchFormTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Search/SearchFormTest.php
@@ -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
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusIncTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusIncTest.php
index bdd8fc9f6..ac936c2a9 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusIncTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusIncTest.php
@@ -16,11 +16,6 @@ if (!defined('DEBUG_UNIT_TEST')) {
define('DEBUG_UNIT_TEST', true);
}
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class StatusIncTest extends ItopTestCase {
/**
@@ -67,7 +62,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');
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusTest.php
index ef5a5eb76..03ef79468 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/Status/StatusTest.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
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/TestAutoload.php b/tests/php-unit-tests/unitary-tests/sources/Application/TestAutoload.php
index 0db76a875..92bf32c16 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/TestAutoload.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/TestAutoload.php
@@ -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
{
diff --git a/tests/php-unit-tests/unitary-tests/sources/Application/TwigBase/Twig/TwigTest.php b/tests/php-unit-tests/unitary-tests/sources/Application/TwigBase/Twig/TwigTest.php
index 0e2178eda..a460a88fa 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Application/TwigBase/Twig/TwigTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Application/TwigBase/Twig/TwigTest.php
@@ -2,16 +2,11 @@
namespace Combodo\iTop\Test\UnitTest\Application\TwigBase;
-use Combodo\iTop\Portal\Twig\AppExtension;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
+use Combodo\iTop\Portal\Twig\AppExtension;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class TwigTest extends ItopDataTestCase
{
protected function setUp(): void
diff --git a/tests/php-unit-tests/unitary-tests/sources/Service/Events/EventTest.php b/tests/php-unit-tests/unitary-tests/sources/Service/Events/EventTest.php
index 969865382..467ca566a 100644
--- a/tests/php-unit-tests/unitary-tests/sources/Service/Events/EventTest.php
+++ b/tests/php-unit-tests/unitary-tests/sources/Service/Events/EventTest.php
@@ -9,6 +9,7 @@ namespace Combodo\iTop\Test\UnitTest\Service\Events;
use Combodo\iTop\Service\Events\Description\EventDescription;
use Combodo\iTop\Service\Events\EventData;
use Combodo\iTop\Service\Events\EventService;
+use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use Combodo\iTop\Test\UnitTest\ItopTestCase;
use ContextTag;
use CoreException;
@@ -20,7 +21,7 @@ use TypeError;
* @package Combodo\iTop\Test\UnitTest\Application\Service
*
*/
-class EventTest extends ItopTestCase
+class EventTest extends ItopDataTestCase
{
const USE_TRANSACTION = false;
const CREATE_TEST_ORG = false;
@@ -45,7 +46,7 @@ class EventTest extends ItopTestCase
public function testRegisterBadCallback($callback)
{
$this->expectException(TypeError::class);
- EventService::RegisterListener('event', $callback);
+ $this->EventService_RegisterListener('event', $callback);
}
public function BadCallbackProvider()
@@ -60,7 +61,7 @@ class EventTest extends ItopTestCase
public function testNoParameterCallbackFunction()
{
- $sId = EventService::RegisterListener('event', function () {
+ $sId = $this->EventService_RegisterListener('event', function () {
$this->debug("Closure: event received !!!");
self::IncrementCallCount();
});
@@ -82,7 +83,7 @@ class EventTest extends ItopTestCase
public function testMethodCallbackFunction(callable $callback)
{
EventService::RegisterEvent(new EventDescription('event', [], 'test', '', [], ''));
- $sId = EventService::RegisterListener('event', $callback);
+ $sId = $this->EventService_RegisterListener('event', $callback);
$this->debug("Registered 'event' with id $sId");
self::$iEventCalls = 0;
@@ -109,7 +110,7 @@ class EventTest extends ItopTestCase
{
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event_a', array($oReceiver, 'BrokenCallback'));
+ $this->EventService_RegisterListener('event_a', array($oReceiver, 'BrokenCallback'));
$this->expectException(TypeError::class);
EventService::FireEvent(new EventData('event_a'));
@@ -119,7 +120,7 @@ class EventTest extends ItopTestCase
{
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
+ $this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event_a'));
@@ -139,15 +140,15 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event_a', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event_b', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
- EventService::RegisterListener('event_a', array($oReceiver, 'OnEvent2'));
- EventService::RegisterListener('event_a', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
- EventService::RegisterListener('event_a', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
+ $this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent1'));
+ $this->EventService_RegisterListener('event_a', array($oReceiver, 'OnEvent2'));
+ $this->EventService_RegisterListener('event_a', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
+ $this->EventService_RegisterListener('event_a', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
- EventService::RegisterListener('event_b', array($oReceiver, 'OnEvent1'));
- EventService::RegisterListener('event_b', array($oReceiver, 'OnEvent2'));
- EventService::RegisterListener('event_b', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
- EventService::RegisterListener('event_b', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
+ $this->EventService_RegisterListener('event_b', array($oReceiver, 'OnEvent1'));
+ $this->EventService_RegisterListener('event_b', array($oReceiver, 'OnEvent2'));
+ $this->EventService_RegisterListener('event_b', array('Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver', 'OnStaticEvent1'));
+ $this->EventService_RegisterListener('event_b', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent2');
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event_a'));
@@ -162,13 +163,13 @@ class EventTest extends ItopTestCase
{
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -180,8 +181,8 @@ class EventTest extends ItopTestCase
{
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event1', [$oReceiver, 'OnEventWithData'], '');
- EventService::RegisterListener('event1', [$oReceiver, 'OnEventWithData'], '');
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEventWithData'], '');
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEventWithData'], '');
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event1', '', ['text' => 'Event Data 1']));
@@ -193,11 +194,11 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent1'], '', [], null, 0);
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent2'], '', [], null, 1);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1'], '', [], null, 0);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent2'], '', [], null, 1);
- EventService::RegisterListener('event2', [$oReceiver, 'OnEvent1'], '', [], null, 1);
- EventService::RegisterListener('event2', [$oReceiver, 'OnEvent2'], '', [], null, 0);
+ $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent1'], '', [], null, 1);
+ $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent2'], '', [], null, 0);
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event1'));
@@ -218,14 +219,14 @@ class EventTest extends ItopTestCase
{
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent1'], '', [], null, 0);
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent2'], '', [], 'test_context', 1);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1'], '', [], null, 0);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent2'], '', [], 'test_context', 1);
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event1'));
$this->assertEquals(1, self::$iEventCalls);
- ContextTag::AddContext('test_context');
+ $oTag = new ContextTag('test_context');
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event1'));
$this->assertEquals(2, self::$iEventCalls);
@@ -236,13 +237,13 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent1'], 'A', [], null, 0);
- EventService::RegisterListener('event1', [$oReceiver, 'OnEvent2'], 'A', [], null, 1);
- EventService::RegisterListener('event1', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1', null, [], null, 2);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent1'], 'A', [], null, 0);
+ $this->EventService_RegisterListener('event1', [$oReceiver, 'OnEvent2'], 'A', [], null, 1);
+ $this->EventService_RegisterListener('event1', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1', null, [], null, 2);
- EventService::RegisterListener('event2', [$oReceiver, 'OnEvent1'], 'A', [], null, 1);
- EventService::RegisterListener('event2', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1', null, [], null, 2);
- EventService::RegisterListener('event2', [$oReceiver, 'OnEvent2'], 'B', [], null, 0);
+ $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent1'], 'A', [], null, 1);
+ $this->EventService_RegisterListener('event2', 'Combodo\iTop\Test\UnitTest\Service\Events\TestEventReceiver::OnStaticEvent1', null, [], null, 2);
+ $this->EventService_RegisterListener('event2', [$oReceiver, 'OnEvent2'], 'B', [], null, 0);
self::$iEventCalls = 0;
EventService::FireEvent(new EventData('event1', 'A'));
@@ -272,13 +273,13 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event2', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -305,13 +306,13 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event2', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
self::$iEventCalls = 0;
@@ -333,13 +334,13 @@ class EventTest extends ItopTestCase
EventService::RegisterEvent(new EventDescription('event1', [], 'test', '', [], ''));
EventService::RegisterEvent(new EventDescription('event2', [], 'test', '', [], ''));
$oReceiver = new TestEventReceiver();
- $sIdToRemove = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sIdToRemove = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sIdToRemove");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event1', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event1', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
- $sId = EventService::RegisterListener('event2', array($oReceiver, 'OnEvent1'));
+ $sId = $this->EventService_RegisterListener('event2', array($oReceiver, 'OnEvent1'));
$this->debug("Registered $sId");
self::$iEventCalls = 0;
diff --git a/tests/php-unit-tests/unitary-tests/synchro/DataSynchroTest.php b/tests/php-unit-tests/unitary-tests/synchro/DataSynchroTest.php
index 613abea3b..d418e23c2 100644
--- a/tests/php-unit-tests/unitary-tests/synchro/DataSynchroTest.php
+++ b/tests/php-unit-tests/unitary-tests/synchro/DataSynchroTest.php
@@ -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
{
diff --git a/tests/php-unit-tests/unitary-tests/webservices/CliResetSessionTest.php b/tests/php-unit-tests/unitary-tests/webservices/CliResetSessionTest.php
index a3b78130f..f5ad5a33e 100644
--- a/tests/php-unit-tests/unitary-tests/webservices/CliResetSessionTest.php
+++ b/tests/php-unit-tests/unitary-tests/webservices/CliResetSessionTest.php
@@ -10,8 +10,6 @@ use MetaModel;
/**
* @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
*/
class CliResetSessionTest extends ItopDataTestCase
{
diff --git a/tests/php-unit-tests/unitary-tests/webservices/ImportTest.php b/tests/php-unit-tests/unitary-tests/webservices/ImportTest.php
index 1a4537f63..08663eed3 100644
--- a/tests/php-unit-tests/unitary-tests/webservices/ImportTest.php
+++ b/tests/php-unit-tests/unitary-tests/webservices/ImportTest.php
@@ -5,11 +5,6 @@ namespace Combodo\iTop\Test\UnitTest\Webservices;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use MetaModel;
-/**
- * @runTestsInSeparateProcesses
- * @preserveGlobalState disabled
- * @backupGlobals disabled
- */
class ImportTest extends ItopDataTestCase {
const USE_TRANSACTION = false;
diff --git a/tests/php-unit-tests/unitary-tests/webservices/RestTest.php b/tests/php-unit-tests/unitary-tests/webservices/RestTest.php
index 5c1fc4676..d23e7cba8 100644
--- a/tests/php-unit-tests/unitary-tests/webservices/RestTest.php
+++ b/tests/php-unit-tests/unitary-tests/webservices/RestTest.php
@@ -13,93 +13,161 @@ 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;
- const ENUM_JSONDATA_NONE = 2;
-
- private $sTmpFile = "";
- private $sUrl;
- private $sLogin;
- private $sPassword = "Iuytrez9876543ç_è-(";
- /** @var int $iJsonDataMode */
- private int $iJsonDataMode = self::ENUM_JSONDATA_AS_STRING;
+ static private $sUrl;
+ static private $sLogin;
+ static private $sPassword = "Iuytrez9876543ç_è-(";
/**
- * @throws Exception
- */
- protected function setUp(): void
- {
- parent::setUp();
-
- $this->sLogin = "rest-user-".date('dmYHis');
- $this->CreateTestOrganization();
-
- if (!empty($this->sTmpFile)) {
- unlink($this->sTmpFile);
- }
-
- $this->sUrl = MetaModel::GetConfig()->Get('app_root_url');
-
- $oRestProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'REST Services User'), true);
- $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => 'Administrator'), true);
-
- if (is_object($oRestProfile) && is_object($oAdminProfile)) {
- $oUser = $this->CreateUser($this->sLogin, $oRestProfile->GetKey(), $this->sPassword);
- $this->AddProfileToUser($oUser, $oAdminProfile->GetKey());
- }
- }
-
- public function testJSONPCallback()
+ * This method is called before the first test of this test class is run (in the current process).
+ */
+ public static function setUpBeforeClass(): void
{
- $sCallbackName = 'fooCallback';
- $sJsonData = <<
$description
", $oObject->Get('description')); - $aCmdbChangeUserInfo = $this->GetCmdbChangeUserInfo($iId); - $this->assertEquals(['CMDBChangeOpCreate' => 'test'], $aCmdbChangeUserInfo); + $this->assertDBChangeOpCount('UserRequest', $iId, 1); // Delete ticket - $this->DeleteTicketFromApi($iId); + $oObject->DBDelete(); } /** @@ -136,135 +202,36 @@ JSON; } } - /** - * @dataProvider BasicProvider - * @param int $iJsonDataMode - */ - public function testUpdateApi($iJsonDataMode) + public function testCoreApiUpdate() { - $this->iJsonDataMode = $iJsonDataMode; - //create ticket $description = date('dmY H:i:s'); - $sOuputJson = $this->CreateTicketViaApi($description); - $aJson = json_decode($sOuputJson, true); - $this->assertNotNull($aJson, 'json_decode() on the REST API response returned null :('); - - if ($this->iJsonDataMode === static::ENUM_JSONDATA_NONE){ - $this->assertStringContainsString("3", "".$aJson['code'], $sOuputJson); - $this->assertStringContainsString("Error: Missing parameter 'json_data'", "".$aJson['message'], $sOuputJson); - return; - } - - $this->assertStringContainsString("0", "".$aJson['code'], $sOuputJson); - $sUserRequestKey = $this->array_key_first($aJson['objects']); - $this->assertStringContainsString('UserRequest::', $sUserRequestKey); - $iId = $aJson['objects'][$sUserRequestKey]['key']; + $oTicket = $this->CreateSampleTicket($description); + $iId = $oTicket->GetKey(); // Update ticket - $description = date('Ymd H:i:s'); + $description = 'Update to '.date('Ymd H:i:s'); + $sJSONOutput = $this->CallCoreRestApi_Internally(<<