mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
💚 Fix unit tests
This commit is contained in:
@@ -1556,7 +1556,19 @@ class DBObjectSearch extends DBSearch
|
|||||||
return $sRet;
|
return $sRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ENTRY POINT API à conserver
|
|
||||||
|
/**
|
||||||
|
* Get an SQLObjectQuery from the search. This SQLObjectQuery can be rendered as a select, select group by, update or delete
|
||||||
|
*
|
||||||
|
* @param array $aAttToLoad array of 'attCode' => AttributeDefinition
|
||||||
|
* @param bool $bGetCount true for count requests
|
||||||
|
* @param null array $aGroupByExpr array of 'field name' => FieldOQLExpression
|
||||||
|
* @param null array $aSelectedClasses
|
||||||
|
* @param null array $aSelectExpr array of 'attCode' => Expression
|
||||||
|
*
|
||||||
|
* @return array|mixed|\SQLObjectQuery|null
|
||||||
|
* @throws \CoreException
|
||||||
|
*/
|
||||||
public function GetSQLQueryStructure($aAttToLoad, $bGetCount, $aGroupByExpr = null, $aSelectedClasses = null, $aSelectExpr = null)
|
public function GetSQLQueryStructure($aAttToLoad, $bGetCount, $aGroupByExpr = null, $aSelectedClasses = null, $aSelectExpr = null)
|
||||||
{
|
{
|
||||||
// Hide objects that are not visible to the current user
|
// Hide objects that are not visible to the current user
|
||||||
|
|||||||
@@ -1240,77 +1240,70 @@ abstract class DBSearch
|
|||||||
self::$m_bOptimizeQueries = $bEnabled;
|
self::$m_bOptimizeQueries = $bEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @param $sOql
|
||||||
*
|
* @param $aOrderBy
|
||||||
* @param $aOrderBy
|
* @param $aArgs
|
||||||
* @param $aArgs
|
* @param $aAttToLoad
|
||||||
* @param $aAttToLoad
|
* @param $aExtendedDataSpec
|
||||||
* @param $aExtendedDataSpec
|
* @param $iLimitCount
|
||||||
* @param $iLimitCount
|
* @param $iLimitStart
|
||||||
* @param $iLimitStart
|
* @param $bGetCount
|
||||||
* @param $bGetCount
|
* @param $sSql
|
||||||
* @param $sSql
|
*
|
||||||
*
|
* @throws \ConfigException
|
||||||
* @throws MySQLException
|
* @throws \CoreException
|
||||||
*/
|
* @internal
|
||||||
|
*
|
||||||
|
*/
|
||||||
protected function AddQueryTraceSelect($sOql, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount, $sSql)
|
protected function AddQueryTraceSelect($sOql, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart, $bGetCount, $sSql)
|
||||||
{
|
{
|
||||||
if (self::$m_bTraceQueries || (utils::GetConfig()->Get('log_kpi_record_oql') == 1))
|
if (self::$m_bTraceQueries)
|
||||||
{
|
{
|
||||||
$aQueryData = array(
|
$aQueryData = array(
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'filter' => $this,
|
|
||||||
'order_by' => $aOrderBy,
|
'order_by' => $aOrderBy,
|
||||||
'args' => $aArgs,
|
|
||||||
'att_to_load' => $aAttToLoad,
|
'att_to_load' => $aAttToLoad,
|
||||||
'extended_data_spec' => $aExtendedDataSpec,
|
|
||||||
'limit_count' => $iLimitCount,
|
'limit_count' => $iLimitCount,
|
||||||
'limit_start' => $iLimitStart,
|
'limit_start' => $iLimitStart,
|
||||||
'is_count' => $bGetCount
|
'is_count' => $bGetCount
|
||||||
);
|
);
|
||||||
if (self::$m_bTraceQueries)
|
|
||||||
|
DBSearch::EnableQueryTrace(false);
|
||||||
|
$aQueryData['oql'] = $this->ToOQL(true, $aArgs);
|
||||||
|
DBSearch::EnableQueryTrace(true);
|
||||||
|
|
||||||
|
if (!empty($aAttToLoad))
|
||||||
{
|
{
|
||||||
self::AddQueryTrace($aQueryData, $sOql, $sSql);
|
$aAttToLoadNames = array();
|
||||||
}
|
foreach ($aAttToLoad as $sClass => $aAttributes)
|
||||||
if (utils::GetConfig()->Get('log_kpi_record_oql') == 1)
|
|
||||||
{
|
|
||||||
$aQueryData['oql'] = $sOql;
|
|
||||||
unset($aQueryData['filter']);
|
|
||||||
if (!empty($aAttToLoad))
|
|
||||||
{
|
{
|
||||||
$aAttToLoadNames = array();
|
$aAttToLoadNames[$sClass] = array();
|
||||||
foreach ($aAttToLoad as $sClass => $aAttributes)
|
foreach ($aAttributes as $sAttCode => $oAttDef)
|
||||||
{
|
{
|
||||||
$aAttToLoadNames[$sClass] = array();
|
$aAttToLoadNames[$sClass][] = $sAttCode;
|
||||||
foreach ($aAttributes as $sAttCode => $oAttDef)
|
|
||||||
{
|
|
||||||
$aAttToLoadNames[$sClass][] = $sAttCode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
$aAttToLoadNames = null;
|
{
|
||||||
}
|
$aAttToLoadNames = null;
|
||||||
$aQueryData['att_to_load'] = $aAttToLoadNames;
|
}
|
||||||
|
$aQueryData['att_to_load'] = $aAttToLoadNames;
|
||||||
|
|
||||||
$hLogFile = @fopen(APPROOT.'log/oql_records.txt', 'a');
|
$hLogFile = @fopen(APPROOT.'log/oql_records.txt', 'a');
|
||||||
if ($hLogFile !== false)
|
if ($hLogFile !== false)
|
||||||
{
|
{
|
||||||
flock($hLogFile, LOCK_EX);
|
flock($hLogFile,LOCK_EX);
|
||||||
fwrite($hLogFile, base64_encode(serialize($aQueryData))."\n");
|
fwrite($hLogFile,serialize($aQueryData)."\n");
|
||||||
fflush($hLogFile);
|
fflush($hLogFile);
|
||||||
flock($hLogFile, LOCK_UN);
|
flock($hLogFile,LOCK_UN);
|
||||||
fclose($hLogFile);
|
fclose($hLogFile);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
|
||||||
*
|
|
||||||
* @param $aArgs
|
* @param $aArgs
|
||||||
* @param $aGroupByExpr
|
* @param $aGroupByExpr
|
||||||
* @param $bExcludeNullValues
|
* @param $bExcludeNullValues
|
||||||
@@ -1320,41 +1313,39 @@ abstract class DBSearch
|
|||||||
* @param $iLimitStart
|
* @param $iLimitStart
|
||||||
* @param $sSql
|
* @param $sSql
|
||||||
*
|
*
|
||||||
|
* @throws \ConfigException
|
||||||
|
* @throws \CoreException
|
||||||
* @throws \MySQLException
|
* @throws \MySQLException
|
||||||
|
* @internal
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
protected function AddQueryTraceGroupBy($aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart, $sSql)
|
protected function AddQueryTraceGroupBy($aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart, $sSql)
|
||||||
{
|
{
|
||||||
if (self::$m_bTraceQueries || (utils::GetConfig()->Get('log_kpi_record_oql') == 1))
|
if (self::$m_bTraceQueries)
|
||||||
{
|
{
|
||||||
$aQueryData = array(
|
$aQueryData = array(
|
||||||
'type' => 'group_by',
|
'type' => 'group_by',
|
||||||
'filter' => $this,
|
|
||||||
'order_by' => $aOrderBy,
|
'order_by' => $aOrderBy,
|
||||||
'args' => $aArgs,
|
|
||||||
'group_by_expr' => $aGroupByExpr,
|
'group_by_expr' => $aGroupByExpr,
|
||||||
'exclude_null_values' => $bExcludeNullValues,
|
'exclude_null_values' => $bExcludeNullValues,
|
||||||
'select_expr' => $aSelectExpr,
|
'select_expr' => $aSelectExpr,
|
||||||
'limit_count' => $iLimitCount,
|
'limit_count' => $iLimitCount,
|
||||||
'limit_start' => $iLimitStart,
|
'limit_start' => $iLimitStart,
|
||||||
);
|
);
|
||||||
$sOql = $this->ToOQL(true, $aArgs);
|
|
||||||
self::AddQueryTrace($aQueryData, $sOql, $sSql);
|
$aQueryData['oql'] = $this->ToOQL(true, $aArgs);
|
||||||
if (utils::GetConfig()->Get('log_kpi_record_oql') == 1)
|
$aQueryData['group_by_expr'] = Expression::ConvertArrayToOQL($aQueryData['group_by_expr'], $aArgs);
|
||||||
|
$aQueryData['select_expr'] = Expression::ConvertArrayToOQL($aQueryData['select_expr'], $aArgs);
|
||||||
|
|
||||||
|
$hLogFile = @fopen(APPROOT.'log/oql_group_by_records.txt', 'a');
|
||||||
|
if ($hLogFile !== false)
|
||||||
{
|
{
|
||||||
$aQueryData['oql'] = $sOql;
|
flock($hLogFile,LOCK_EX);
|
||||||
unset($aQueryData['filter']);
|
fwrite($hLogFile,serialize($aQueryData)."\n");
|
||||||
|
fflush($hLogFile);
|
||||||
$hLogFile = @fopen(APPROOT.'log/oql_group_by_records.txt', 'a');
|
flock($hLogFile,LOCK_UN);
|
||||||
if ($hLogFile !== false)
|
fclose($hLogFile);
|
||||||
{
|
|
||||||
flock($hLogFile, LOCK_EX);
|
|
||||||
fwrite($hLogFile, base64_encode(serialize($aQueryData))."\n");
|
|
||||||
fflush($hLogFile);
|
|
||||||
flock($hLogFile, LOCK_UN);
|
|
||||||
fclose($hLogFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6291,7 +6291,7 @@ abstract class MetaModel
|
|||||||
&& function_exists('apc_store');
|
&& function_exists('apc_store');
|
||||||
|
|
||||||
DBSearch::EnableQueryCache(self::$m_oConfig->GetQueryCacheEnabled(), self::$m_bUseAPCCache, self::$m_oConfig->Get('apc_cache.query_ttl'));
|
DBSearch::EnableQueryCache(self::$m_oConfig->GetQueryCacheEnabled(), self::$m_bUseAPCCache, self::$m_oConfig->Get('apc_cache.query_ttl'));
|
||||||
DBSearch::EnableQueryTrace(self::$m_oConfig->GetLogQueries());
|
DBSearch::EnableQueryTrace(self::$m_oConfig->GetLogQueries() || self::$m_oConfig->Get('log_kpi_record_oql'));
|
||||||
DBSearch::EnableQueryIndentation(self::$m_oConfig->Get('query_indentation_enabled'));
|
DBSearch::EnableQueryIndentation(self::$m_oConfig->Get('query_indentation_enabled'));
|
||||||
DBSearch::EnableOptimizeQuery(self::$m_oConfig->Get('query_optimization_enabled'));
|
DBSearch::EnableOptimizeQuery(self::$m_oConfig->Get('query_optimization_enabled'));
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,29 @@ abstract class Expression
|
|||||||
*/
|
*/
|
||||||
abstract public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true);
|
abstract public function Translate($aTranslationData, $bMatchAll = true, $bMarkFieldsAsResolved = true);
|
||||||
|
|
||||||
|
public final static function ConvertArrayToOQL($aExpressions, $aArgs)
|
||||||
|
{
|
||||||
|
$aRet = array();
|
||||||
|
foreach ($aExpressions as $sName => $oExpression)
|
||||||
|
{
|
||||||
|
/** @var Expression $oExpression */
|
||||||
|
$aRet[$sName] = $oExpression->RenderExpression(false, $aArgs);
|
||||||
|
}
|
||||||
|
return $aRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static function ConvertArrayFromOQL($aExpressions)
|
||||||
|
{
|
||||||
|
$aRet = array();
|
||||||
|
foreach ($aExpressions as $sName => $sConditionExpr)
|
||||||
|
{
|
||||||
|
/** @var Expression $oExpression */
|
||||||
|
$aRet[$sName] = Expression::FromOQL($sConditionExpr);
|
||||||
|
}
|
||||||
|
return $aRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* recursive rendering
|
* recursive rendering
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
namespace Combodo\iTop\Application\Status;
|
namespace Combodo\iTop\Application\Status;
|
||||||
|
|
||||||
|
use Config;
|
||||||
|
use Exception;
|
||||||
|
use MetaModel;
|
||||||
|
|
||||||
define('STATUS_ERROR', 'ERROR');
|
define('STATUS_ERROR', 'ERROR');
|
||||||
define('STATUS_RUNNING', 'RUNNING');
|
define('STATUS_RUNNING', 'RUNNING');
|
||||||
|
|
||||||
@@ -22,9 +26,10 @@ function StatusGetAppRoot($sAppRootFilename = 'approot.inc.php')
|
|||||||
*/
|
*/
|
||||||
if (!file_exists($sAppRootFile) || !is_readable($sAppRootFile))
|
if (!file_exists($sAppRootFile) || !is_readable($sAppRootFile))
|
||||||
{
|
{
|
||||||
throw new \Exception($sAppRootFilename . ' is not readable');
|
throw new Exception($sAppRootFilename . ' is not readable');
|
||||||
}
|
}
|
||||||
require_once($sAppRootFile);
|
@require_once($sAppRootFile);
|
||||||
|
@require_once(APPROOT.'bootstrap.inc.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +51,7 @@ function StatusCheckConfigFile($sConfigFilename = 'config-itop.php')
|
|||||||
*/
|
*/
|
||||||
if (!file_exists($sConfigFile) || !is_readable($sConfigFile))
|
if (!file_exists($sConfigFile) || !is_readable($sConfigFile))
|
||||||
{
|
{
|
||||||
throw new \Exception($sConfigFilename . ' is not readable');
|
throw new Exception($sConfigFilename . ' is not readable');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +65,7 @@ function StatusCheckConfigFile($sConfigFilename = 'config-itop.php')
|
|||||||
* @throws \DictExceptionUnknownLanguage
|
* @throws \DictExceptionUnknownLanguage
|
||||||
* @throws \MySQLException
|
* @throws \MySQLException
|
||||||
*/
|
*/
|
||||||
function StatusStartup(\Config $oConfig = null)
|
function StatusStartup(Config $oConfig = null)
|
||||||
{
|
{
|
||||||
StatusCheckConfigFile();
|
StatusCheckConfigFile();
|
||||||
|
|
||||||
@@ -71,5 +76,5 @@ function StatusStartup(\Config $oConfig = null)
|
|||||||
$soConfigFile = (null === $oConfig) ? ITOP_DEFAULT_CONFIG_FILE : $oConfig;
|
$soConfigFile = (null === $oConfig) ? ITOP_DEFAULT_CONFIG_FILE : $oConfig;
|
||||||
|
|
||||||
//Check if application could be started
|
//Check if application could be started
|
||||||
\MetaModel::Startup($soConfigFile, true /* $bModelOnly */);
|
MetaModel::Startup($soConfigFile, true /* $bModelOnly */);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,14 @@ use CMDBSource;
|
|||||||
use Contact;
|
use Contact;
|
||||||
use DBObject;
|
use DBObject;
|
||||||
use DBObjectSet;
|
use DBObjectSet;
|
||||||
|
use DBSearch;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Farm;
|
use Farm;
|
||||||
use FunctionalCI;
|
use FunctionalCI;
|
||||||
use Hypervisor;
|
use Hypervisor;
|
||||||
use lnkContactToFunctionalCI;
|
use lnkContactToFunctionalCI;
|
||||||
|
use lnkContactToTicket;
|
||||||
|
use lnkFunctionalCIToTicket;
|
||||||
use MetaModel;
|
use MetaModel;
|
||||||
use Person;
|
use Person;
|
||||||
use Server;
|
use Server;
|
||||||
@@ -72,9 +75,8 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
//require_once(APPROOT.'/application/startup.inc.php');
|
//require_once(APPROOT.'/application/startup.inc.php');
|
||||||
|
|
||||||
require_once(APPROOT.'/core/cmdbobject.class.inc.php');
|
require_once(APPROOT.'application/utils.inc.php');
|
||||||
require_once(APPROOT.'/application/utils.inc.php');
|
|
||||||
require_once(APPROOT.'/core/contexttag.class.inc.php');
|
|
||||||
$sEnv = 'production';
|
$sEnv = 'production';
|
||||||
$sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE;
|
$sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE;
|
||||||
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, true /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
|
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, true /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
|
||||||
@@ -269,7 +271,7 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
|
|
||||||
private function RemoveObjects($sClass, $sOQL)
|
private function RemoveObjects($sClass, $sOQL)
|
||||||
{
|
{
|
||||||
$oFilter = \DBSearch::FromOQL($sOQL);
|
$oFilter = DBSearch::FromOQL($sOQL);
|
||||||
$aRes = $oFilter->ToDataArray(array('id'));
|
$aRes = $oFilter->ToDataArray(array('id'));
|
||||||
foreach ($aRes as $aRow)
|
foreach ($aRes as $aRow)
|
||||||
{
|
{
|
||||||
@@ -510,7 +512,7 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var FAQ $oFaq */
|
/** @var \FAQ $oFaq */
|
||||||
$oFaq = $this->createObject('FAQ', array(
|
$oFaq = $this->createObject('FAQ', array(
|
||||||
'category_id' => $oFaqCategory->GetKey(),
|
'category_id' => $oFaqCategory->GetKey(),
|
||||||
'title' => 'FAQ_phpunit',
|
'title' => 'FAQ_phpunit',
|
||||||
@@ -577,11 +579,12 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
* @param Ticket $oTicket
|
* @param Ticket $oTicket
|
||||||
* @param string $sImpactCode
|
* @param string $sImpactCode
|
||||||
*
|
*
|
||||||
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function AddCIToTicket($oCI, $oTicket, $sImpactCode)
|
protected function AddCIToTicket($oCI, $oTicket, $sImpactCode)
|
||||||
{
|
{
|
||||||
$oNewLink = new \lnkFunctionalCIToTicket();
|
$oNewLink = new lnkFunctionalCIToTicket();
|
||||||
$oNewLink->Set('functionalci_id', $oCI->GetKey());
|
$oNewLink->Set('functionalci_id', $oCI->GetKey());
|
||||||
$oNewLink->Set('impact_code', $sImpactCode);
|
$oNewLink->Set('impact_code', $sImpactCode);
|
||||||
$oCIs = $oTicket->Get('functionalcis_list');
|
$oCIs = $oTicket->Get('functionalcis_list');
|
||||||
@@ -630,11 +633,12 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
* @param string $sRoleCode
|
* @param string $sRoleCode
|
||||||
* @param array $aParams
|
* @param array $aParams
|
||||||
*
|
*
|
||||||
|
* @return array
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function AddContactToTicket($oContact, $oTicket, $sRoleCode, $aParams = array())
|
protected function AddContactToTicket($oContact, $oTicket, $sRoleCode, $aParams = array())
|
||||||
{
|
{
|
||||||
$oNewLink = new \lnkContactToTicket();
|
$oNewLink = new lnkContactToTicket();
|
||||||
$oNewLink->Set('contact_id', $oContact->GetKey());
|
$oNewLink->Set('contact_id', $oContact->GetKey());
|
||||||
$oNewLink->Set('role_code', $sRoleCode);
|
$oNewLink->Set('role_code', $sRoleCode);
|
||||||
foreach ($aParams as $sAttCode => $oValue)
|
foreach ($aParams as $sAttCode => $oValue)
|
||||||
@@ -753,4 +757,4 @@ class ItopDataTestCase extends ItopTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
|
class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
@@ -90,4 +95,4 @@ class UtilsTest extends \Combodo\iTop\Test\UnitTest\ItopTestCase
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
|||||||
use DBObjectSearch;
|
use DBObjectSearch;
|
||||||
use DBSearch;
|
use DBSearch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class CriterionConversionTest extends ItopDataTestCase
|
class CriterionConversionTest extends ItopDataTestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,12 +31,13 @@ namespace Combodo\iTop\Test\UnitTest\Application\Search;
|
|||||||
use Combodo\iTop\Application\Search\CriterionParser;
|
use Combodo\iTop\Application\Search\CriterionParser;
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class CriterionParserTest extends ItopDataTestCase
|
class CriterionParserTest extends ItopDataTestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
|||||||
use DBObjectSearch;
|
use DBObjectSearch;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class SearchFormTest extends ItopDataTestCase
|
class SearchFormTest extends ItopDataTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -43,25 +43,23 @@ $oOQLHandle = @fopen($sOQLFile, "r");
|
|||||||
if ($oOQLHandle) {
|
if ($oOQLHandle) {
|
||||||
while (($sBuffer = fgets($oOQLHandle)) !== false) {
|
while (($sBuffer = fgets($oOQLHandle)) !== false) {
|
||||||
$iRead++;
|
$iRead++;
|
||||||
$aRecord = unserialize(base64_decode($sBuffer));
|
$aRecord = unserialize($sBuffer);
|
||||||
|
|
||||||
$sOQL = $aRecord['oql'];
|
$sOQL = $aRecord['oql'];
|
||||||
|
|
||||||
$sChecksum = md5($sOQL.serialize($aRecord['att_to_load']));
|
$sChecksum = md5($sBuffer);
|
||||||
if (isset($aFoundOQLs[$sChecksum])) { continue; }
|
if (isset($aFoundOQLs[$sChecksum])) { continue; }
|
||||||
$aFoundOQLs[$sChecksum] = true;
|
$aFoundOQLs[$sChecksum] = true;
|
||||||
|
|
||||||
$iCount++;
|
$iCount++;
|
||||||
$sOrderBy = ConvertArray($aRecord['order_by']);
|
$sOrderBy = ConvertArray($aRecord['order_by']);
|
||||||
$sArgs = ConvertArray($aRecord['args']);
|
|
||||||
$sAttToLoad = ConvertArray($aRecord['att_to_load']);
|
$sAttToLoad = ConvertArray($aRecord['att_to_load']);
|
||||||
$sExtendedDataSpec = ConvertArray($aRecord['extended_data_spec']);
|
|
||||||
$iLimitCount = $aRecord['limit_count'];
|
$iLimitCount = $aRecord['limit_count'];
|
||||||
$iLimitStart = $aRecord['limit_start'];
|
$iLimitStart = $aRecord['limit_start'];
|
||||||
|
|
||||||
// $sOQL, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart
|
// $sOQL, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart
|
||||||
|
|
||||||
$sLine = "\$aData[\"SELECT $iCount\"] = array(\"$sOQL\", $sOrderBy, $sArgs, $sAttToLoad, $sExtendedDataSpec, $iLimitCount, $iLimitStart);\n";
|
$sLine = "\$aData[\"SELECT $iCount\"] = array(\"$sOQL\", $sOrderBy, array(), $sAttToLoad, array(), $iLimitCount, $iLimitStart);\n";
|
||||||
@fwrite($oTestHandle, $sLine);
|
@fwrite($oTestHandle, $sLine);
|
||||||
}
|
}
|
||||||
if (!feof($oOQLHandle)) {
|
if (!feof($oOQLHandle)) {
|
||||||
@@ -94,19 +92,18 @@ $oOQLHandle = @fopen($sOQLFile, "r");
|
|||||||
if ($oOQLHandle) {
|
if ($oOQLHandle) {
|
||||||
while (($sBuffer = fgets($oOQLHandle)) !== false) {
|
while (($sBuffer = fgets($oOQLHandle)) !== false) {
|
||||||
$iRead++;
|
$iRead++;
|
||||||
$aRecord = unserialize(base64_decode($sBuffer));
|
$aRecord = unserialize($sBuffer);
|
||||||
|
|
||||||
$sOQL = $aRecord['oql'];
|
$sOQL = $aRecord['oql'];
|
||||||
|
|
||||||
$sChecksum = md5($sOQL.serialize($aRecord['group_by_expr']));
|
$sChecksum = md5($sBuffer);
|
||||||
if (isset($aFoundOQLs[$sChecksum])) { continue; }
|
if (isset($aFoundOQLs[$sChecksum])) { continue; }
|
||||||
$aFoundOQLs[$sChecksum] = true;
|
$aFoundOQLs[$sChecksum] = true;
|
||||||
|
|
||||||
$iCount++;
|
$iCount++;
|
||||||
$sOrderBy = ConvertArray($aRecord['order_by']);
|
$sOrderBy = ConvertArray($aRecord['order_by']);
|
||||||
$sArgs = ConvertArray($aRecord['args']);
|
$sGroupByExpr = ConvertArray($aRecord['group_by_expr']);
|
||||||
$sGroupByExpr = ConvertArray($aRecord['group_by_expr'], true);
|
$sSelectExpr = ConvertArray($aRecord['select_expr']);
|
||||||
$sSelectExpr = ConvertArray($aRecord['select_expr'], true);
|
|
||||||
if ($aRecord['exclude_null_values'])
|
if ($aRecord['exclude_null_values'])
|
||||||
{
|
{
|
||||||
$bExcludeNullValues = 'true';
|
$bExcludeNullValues = 'true';
|
||||||
@@ -120,7 +117,7 @@ if ($oOQLHandle) {
|
|||||||
|
|
||||||
// $sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart
|
// $sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart
|
||||||
|
|
||||||
$sLine = "\$aData[\"SELECT $iCount\"] = array(\"$sOQL\", $sArgs, $sGroupByExpr, $bExcludeNullValues, $sSelectExpr, $sOrderBy, $iLimitCount, $iLimitStart);\n";
|
$sLine = "\$aData[\"SELECT $iCount\"] = array(\"$sOQL\", array(), $sGroupByExpr, $bExcludeNullValues, $sSelectExpr, $sOrderBy, $iLimitCount, $iLimitStart);\n";
|
||||||
@fwrite($oTestHandle, $sLine);
|
@fwrite($oTestHandle, $sLine);
|
||||||
}
|
}
|
||||||
if (!feof($oOQLHandle)) {
|
if (!feof($oOQLHandle)) {
|
||||||
@@ -134,7 +131,7 @@ if ($oOQLHandle) {
|
|||||||
|
|
||||||
echo "<br>File '$sTestFile' generated with ".($iCount-1000)." entries (from $iRead captured OQL).\n";
|
echo "<br>File '$sTestFile' generated with ".($iCount-1000)." entries (from $iRead captured OQL).\n";
|
||||||
|
|
||||||
function ConvertArray($aArray, $bB64Encode = false)
|
function ConvertArray($aArray)
|
||||||
{
|
{
|
||||||
if (is_null($aArray))
|
if (is_null($aArray))
|
||||||
{
|
{
|
||||||
@@ -146,9 +143,5 @@ function ConvertArray($aArray, $bB64Encode = false)
|
|||||||
return 'array()';
|
return 'array()';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($bB64Encode)
|
return 'unserialize(\''.str_replace("'", "\\'",serialize($aArray)).'\')';
|
||||||
{
|
}
|
||||||
return 'unserialize(base64_decode(\''.base64_encode(serialize($aArray)).'\'))';
|
|
||||||
}
|
|
||||||
return 'unserialize(\''.serialize($aArray).'\')';
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
use DBObjectSet;
|
||||||
use DBSearch;
|
use DBSearch;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +29,6 @@ class DBSearchCommitTest extends ItopDataTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws \CoreException
|
* @throws \CoreException
|
||||||
* @throws \CoreUnexpectedValue
|
|
||||||
* @throws \MissingQueryArgument
|
* @throws \MissingQueryArgument
|
||||||
* @throws \MySQLException
|
* @throws \MySQLException
|
||||||
* @throws \MySQLHasGoneAwayException
|
* @throws \MySQLHasGoneAwayException
|
||||||
@@ -47,14 +47,14 @@ class DBSearchCommitTest extends ItopDataTestCase
|
|||||||
|
|
||||||
$oSearch = DBSearch::FromOQL("SELECT ".TAG_CLASS);
|
$oSearch = DBSearch::FromOQL("SELECT ".TAG_CLASS);
|
||||||
$oSearch->AddCondition(TAG_ATTCODE, 'tag1', 'MATCHES');
|
$oSearch->AddCondition(TAG_ATTCODE, 'tag1', 'MATCHES');
|
||||||
$oSet = new \DBObjectSet($oSearch);
|
$oSet = new DBObjectSet($oSearch);
|
||||||
static::assertEquals(1, $oSet->Count());
|
static::assertEquals(1, $oSet->Count());
|
||||||
|
|
||||||
|
|
||||||
$oObjWithTagSet->Set(TAG_ATTCODE, 'tag1 tag2');
|
$oObjWithTagSet->Set(TAG_ATTCODE, 'tag1 tag2');
|
||||||
$oObjWithTagSet->DBWrite();
|
$oObjWithTagSet->DBWrite();
|
||||||
|
|
||||||
$oSet = new \DBObjectSet($oSearch);
|
$oSet = new DBObjectSet($oSearch);
|
||||||
static::assertEquals(1, $oSet->Count());
|
static::assertEquals(1, $oSet->Count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
|||||||
|
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
use DBObjectSearch;
|
||||||
|
use Exception;
|
||||||
|
use OqlInterpreter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @runTestsInSeparateProcesses
|
* @runTestsInSeparateProcesses
|
||||||
@@ -29,7 +32,7 @@ class OQLTest extends ItopDataTestCase
|
|||||||
public function testGoodQueryParser($sQuery)
|
public function testGoodQueryParser($sQuery)
|
||||||
{
|
{
|
||||||
$this->debug($sQuery);
|
$this->debug($sQuery);
|
||||||
$oOql = new \OqlInterpreter($sQuery);
|
$oOql = new OqlInterpreter($sQuery);
|
||||||
$oQuery = $oOql->ParseQuery();
|
$oQuery = $oOql->ParseQuery();
|
||||||
static::assertInstanceOf('OqlQuery', $oQuery);
|
static::assertInstanceOf('OqlQuery', $oQuery);
|
||||||
}
|
}
|
||||||
@@ -126,13 +129,13 @@ class OQLTest extends ItopDataTestCase
|
|||||||
public function testBadQueryParser($sQuery, $sExpectedExceptionClass)
|
public function testBadQueryParser($sQuery, $sExpectedExceptionClass)
|
||||||
{
|
{
|
||||||
$this->debug($sQuery);
|
$this->debug($sQuery);
|
||||||
$oOql = new \OqlInterpreter($sQuery);
|
$oOql = new OqlInterpreter($sQuery);
|
||||||
$sExceptionClass = '';
|
$sExceptionClass = '';
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oOql->ParseQuery();
|
$oOql->ParseQuery();
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
$sExceptionClass = get_class($e);
|
$sExceptionClass = get_class($e);
|
||||||
}
|
}
|
||||||
@@ -168,7 +171,7 @@ class OQLTest extends ItopDataTestCase
|
|||||||
public function testTypeErrorQueryParser($sQuery)
|
public function testTypeErrorQueryParser($sQuery)
|
||||||
{
|
{
|
||||||
$this->debug($sQuery);
|
$this->debug($sQuery);
|
||||||
$oOql = new \OqlInterpreter($sQuery);
|
$oOql = new OqlInterpreter($sQuery);
|
||||||
$oOql->ParseQuery();
|
$oOql->ParseQuery();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,10 +198,10 @@ class OQLTest extends ItopDataTestCase
|
|||||||
$sExceptionClass = '';
|
$sExceptionClass = '';
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oSearch = \DBObjectSearch::FromOQL($sQuery);
|
$oSearch = DBObjectSearch::FromOQL($sQuery);
|
||||||
static::assertInstanceOf('DBObjectSearch', $oSearch);
|
static::assertInstanceOf('DBObjectSearch', $oSearch);
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
$sExceptionClass = get_class($e);
|
$sExceptionClass = get_class($e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
@include_once '../approot.inc.php';
|
|
||||||
@include_once '../../approot.inc.php';
|
|
||||||
@include_once '../../../approot.inc.php';
|
|
||||||
@include_once '../../../../approot.inc.php';
|
|
||||||
require_once(APPROOT.'bootstrap.inc.php');
|
|
||||||
require_once(APPROOT.'application/startup.inc.php');
|
|
||||||
|
|
||||||
define('PRECISION', 2);
|
define('PRECISION', 2);
|
||||||
|
|
||||||
@@ -32,6 +26,7 @@ class OQLToSQLAllCLassesTest extends ItopDataTestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
require_once(APPROOT.'application/startup.inc.php');
|
||||||
|
|
||||||
SetupUtils::builddir(APPROOT.'log/test/OQLToSQL');
|
SetupUtils::builddir(APPROOT.'log/test/OQLToSQL');
|
||||||
}
|
}
|
||||||
@@ -114,7 +109,7 @@ class OQLToSQLAllCLassesTest extends ItopDataTestCase
|
|||||||
$aPrevious = $this->GetPreviousTestResult($this->GetId());
|
$aPrevious = $this->GetPreviousTestResult($this->GetId());
|
||||||
if (is_null($aPrevious))
|
if (is_null($aPrevious))
|
||||||
{
|
{
|
||||||
$aResult = $this->OQLSelectRunner($sOQL, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart);
|
$aResult = $this->OQLSelectRunner($sOQL, $aOrderBy, $aArgs, $aAttToLoad, $aExtendedDataSpec, $iLimitCount, $iLimitStart);
|
||||||
// no test yet, just save
|
// no test yet, just save
|
||||||
$this->SaveTestResult($this->GetId(), $aResult);
|
$this->SaveTestResult($this->GetId(), $aResult);
|
||||||
$this->debug("Test result saved");
|
$this->debug("Test result saved");
|
||||||
@@ -284,8 +279,13 @@ class OQLToSQLAllCLassesTest extends ItopDataTestCase
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static $aPureAbstractClasses = ['AbstractResource', 'ResourceAdminMenu', 'ResourceRunQueriesMenu', 'ResourceItopIntegrityMenu'];
|
||||||
|
|
||||||
public function OQLSelectProvider()
|
public function OQLSelectProvider()
|
||||||
{
|
{
|
||||||
|
parent::setUp();
|
||||||
|
require_once(APPROOT.'application/startup.inc.php');
|
||||||
|
|
||||||
$aData = array();
|
$aData = array();
|
||||||
|
|
||||||
// $sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0
|
// $sOQL, $aOrderBy = array(), $aArgs = array(), $aAttToLoad = null, $aExtendedDataSpec = null, $iLimitCount = 20, $iLimitStart = 0
|
||||||
@@ -295,7 +295,7 @@ class OQLToSQLAllCLassesTest extends ItopDataTestCase
|
|||||||
|
|
||||||
foreach ($aClasses as $sClass)
|
foreach ($aClasses as $sClass)
|
||||||
{
|
{
|
||||||
if ($sClass == 'AbstractResource' || $sClass == 'ResourceAdminMenu' || $sClass == 'ResourceRunQueriesMenu')
|
if (in_array($sClass, self::$aPureAbstractClasses))
|
||||||
{
|
{
|
||||||
// These classes are pure abstract (no table in database)
|
// These classes are pure abstract (no table in database)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
313
test/core/OQLToSQLGroupByTest.php
Normal file
313
test/core/OQLToSQLGroupByTest.php
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
//namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
|
|
||||||
|
define('NUM_PRECISION', 2);
|
||||||
|
|
||||||
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
|
class OQLToSQLTest extends ItopDataTestCase
|
||||||
|
{
|
||||||
|
const USE_TRANSACTION = false;
|
||||||
|
const CREATE_TEST_ORG = false;
|
||||||
|
const TEST_CSV_RESULT = 'OQLToSQLTest.csv';
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
require_once(APPROOT.'application/startup.inc.php');
|
||||||
|
|
||||||
|
SetupUtils::builddir(APPROOT.'log/test/OQLToSQL');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetPreviousTestResult($sTestId)
|
||||||
|
{
|
||||||
|
$sResultFile = APPROOT.'log/test/OQLToSQL/'.$sTestId.'.txt';
|
||||||
|
if (!is_file($sResultFile))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$aResult = unserialize(file_get_contents($sResultFile));
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function SaveTestResult($sTestId, $aResult)
|
||||||
|
{
|
||||||
|
$sResultFile = APPROOT.'log/test/OQLToSQL/'.$sTestId.'.txt';
|
||||||
|
if (is_file($sResultFile))
|
||||||
|
{
|
||||||
|
@unlink($sResultFile);
|
||||||
|
}
|
||||||
|
file_put_contents($sResultFile, serialize($aResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @doesNotPerformAssertions
|
||||||
|
*
|
||||||
|
* @throws \ConfigException
|
||||||
|
* @throws \CoreException
|
||||||
|
*/
|
||||||
|
public function testOQLLegacySetup()
|
||||||
|
{
|
||||||
|
utils::GetConfig()->Set('use_legacy_dbsearch', true, 'Test');
|
||||||
|
utils::GetConfig()->Set('apc_cache.enabled', false, 'Test');
|
||||||
|
utils::GetConfig()->Set('expression_cache_enabled', false, 'Test');
|
||||||
|
utils::GetConfig()->Set('query_cache_enabled', false, 'Test');
|
||||||
|
$sConfigFile = utils::GetConfig()->GetLoadedFile();
|
||||||
|
@chmod($sConfigFile, 0770);
|
||||||
|
utils::GetConfig()->WriteToFile();
|
||||||
|
@chmod($sConfigFile, 0444); // Read-only
|
||||||
|
|
||||||
|
SetupUtils::rrmdir($sResultFile = APPROOT.'log/test');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider OQLGroupByProvider
|
||||||
|
* @depends testOQLLegacySetup
|
||||||
|
*
|
||||||
|
* @param $sOQL
|
||||||
|
* @param $aArgs
|
||||||
|
* @param $aGroupByExpr
|
||||||
|
* @param bool $bExcludeNullValues
|
||||||
|
* @param array $aSelectExpr
|
||||||
|
* @param array $aOrderBy
|
||||||
|
* @param int $iLimitCount
|
||||||
|
* @param int $iLimitStart
|
||||||
|
*
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \MySQLException
|
||||||
|
* @throws \MySQLHasGoneAwayException
|
||||||
|
* @throws \OQLException
|
||||||
|
*/
|
||||||
|
public function testOQLGroupByLegacy($sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues = false, $aSelectExpr = array(), $aOrderBy = array(), $iLimitCount = 0, $iLimitStart = 0)
|
||||||
|
{
|
||||||
|
$this->assertTrue(utils::GetConfig()->Get('use_legacy_dbsearch'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('apc_cache.enabled'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('query_cache_enabled'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('expression_cache_enabled'));
|
||||||
|
|
||||||
|
$aPrevious = $this->GetPreviousTestResult($this->GetId());
|
||||||
|
if (is_null($aPrevious))
|
||||||
|
{
|
||||||
|
$aResult = $this->OQLGroupByRunner($sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart);
|
||||||
|
// no test yet, just save
|
||||||
|
$this->SaveTestResult($this->GetId(), $aResult);
|
||||||
|
$this->debug("Test result saved");
|
||||||
|
}
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @doesNotPerformAssertions
|
||||||
|
*
|
||||||
|
* @throws \ConfigException
|
||||||
|
* @throws \CoreException
|
||||||
|
*/
|
||||||
|
public function testOQLSetup()
|
||||||
|
{
|
||||||
|
utils::GetConfig()->Set('use_legacy_dbsearch', false, 'test');
|
||||||
|
utils::GetConfig()->Set('apc_cache.enabled', false, 'test');
|
||||||
|
utils::GetConfig()->Set('query_cache_enabled', false, 'test');
|
||||||
|
utils::GetConfig()->Set('expression_cache_enabled', false, 'test');
|
||||||
|
$sConfigFile = utils::GetConfig()->GetLoadedFile();
|
||||||
|
@chmod($sConfigFile, 0770);
|
||||||
|
utils::GetConfig()->WriteToFile();
|
||||||
|
@chmod($sConfigFile, 0444); // Read-only
|
||||||
|
|
||||||
|
$aCSVHeader = array(
|
||||||
|
'test', 'OQL','count',
|
||||||
|
'Legacy Count Joins', 'Count Joins',
|
||||||
|
'Legacy Count Duration', 'Count Duration',
|
||||||
|
'Legacy Data Joins', 'Data Joins',
|
||||||
|
'Legacy Data Duration', 'Data Duration',
|
||||||
|
'Count Joins Diff', 'Data Joins Diff',
|
||||||
|
);
|
||||||
|
$this->WriteToCsvHeader(self::TEST_CSV_RESULT, $aCSVHeader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider OQLGroupByProvider
|
||||||
|
* @depends testOQLSetup
|
||||||
|
*
|
||||||
|
* @param $sOQL
|
||||||
|
* @param $aArgs
|
||||||
|
* @param $aGroupByExpr
|
||||||
|
* @param bool $bExcludeNullValues
|
||||||
|
* @param array $aSelectExpr
|
||||||
|
* @param array $aOrderBy
|
||||||
|
* @param int $iLimitCount
|
||||||
|
* @param int $iLimitStart
|
||||||
|
*
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \MySQLException
|
||||||
|
* @throws \MySQLHasGoneAwayException
|
||||||
|
* @throws \OQLException
|
||||||
|
*/
|
||||||
|
public function testOQLGroupBy($sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues = false, $aSelectExpr = array(), $aOrderBy = array(), $iLimitCount = 0, $iLimitStart = 0)
|
||||||
|
{
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('use_legacy_dbsearch'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('apc_cache.enabled'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('query_cache_enabled'));
|
||||||
|
$this->assertFalse(utils::GetConfig()->Get('expression_cache_enabled'));
|
||||||
|
|
||||||
|
$aResult = $this->OQLGroupByRunner($sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart);
|
||||||
|
$this->assertNull($aResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $sOQL
|
||||||
|
* @param $aArgs
|
||||||
|
* @param $aGroupByExpr
|
||||||
|
* @param bool $bExcludeNullValues
|
||||||
|
* @param array $aSelectExpr
|
||||||
|
* @param array $aOrderBy
|
||||||
|
* @param int $iLimitCount
|
||||||
|
* @param int $iLimitStart
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \MySQLException
|
||||||
|
* @throws \MySQLHasGoneAwayException
|
||||||
|
* @throws \OQLException
|
||||||
|
*/
|
||||||
|
private function OQLGroupByRunner($sOQL, $aArgs, $aGroupByExpr, $bExcludeNullValues = false, $aSelectExpr = array(), $aOrderBy = array(), $iLimitCount = 0, $iLimitStart = 0)
|
||||||
|
{
|
||||||
|
$oSearch = DBSearch::FromOQL($sOQL);
|
||||||
|
|
||||||
|
$aGroupByExpr = Expression::ConvertArrayFromOQL($aGroupByExpr);
|
||||||
|
$aSelectExpr = Expression::ConvertArrayFromOQL($aSelectExpr);
|
||||||
|
|
||||||
|
$sSQL = $oSearch->MakeGroupByQuery($aArgs, $aGroupByExpr, $bExcludeNullValues, $aSelectExpr, $aOrderBy, $iLimitCount, $iLimitStart);
|
||||||
|
$fStart = $this->GetMicroTime();
|
||||||
|
$aRow = $this->GetArrayResult($sSQL);
|
||||||
|
$fDataDuration = $this->GetMicroTime() - $fStart;
|
||||||
|
if (is_null($aRow))
|
||||||
|
{
|
||||||
|
$aRow = array();
|
||||||
|
}
|
||||||
|
// Store only to the 10 first entries
|
||||||
|
$aRow = array_slice($aRow, 0, 10);
|
||||||
|
|
||||||
|
$iJoinData = count(explode(' JOIN ', $sSQL)) - 1;
|
||||||
|
|
||||||
|
$aResult = array(
|
||||||
|
'oql' => $sOQL,
|
||||||
|
'data_sql' => $sSQL,
|
||||||
|
'data_join_count' => $iJoinData,
|
||||||
|
'data_duration' => $fDataDuration,
|
||||||
|
);
|
||||||
|
|
||||||
|
$aResult['data'] = $aRow;
|
||||||
|
|
||||||
|
$aPrevious = $this->GetPreviousTestResult($this->GetId());
|
||||||
|
if (is_null($aPrevious))
|
||||||
|
{
|
||||||
|
return $aResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->debug("data_join_count : ".$aPrevious['data_join_count']." -> ".$aResult['data_join_count']);
|
||||||
|
$this->debug("data_duration : ".round($aPrevious['data_duration'], NUM_PRECISION)." -> ".round($aResult['data_duration'], NUM_PRECISION));
|
||||||
|
|
||||||
|
// Compare result
|
||||||
|
$aFields = array('oql', 'data');
|
||||||
|
foreach ($aFields as $sField)
|
||||||
|
{
|
||||||
|
$this->assertEquals($aPrevious[$sField], $aResult[$sField], "$sField differ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($aPrevious['data_join_count'] != $aResult['data_join_count'])
|
||||||
|
{
|
||||||
|
unset($aPrevious['data']);
|
||||||
|
unset($aResult['data']);
|
||||||
|
$this->debug("Previous");
|
||||||
|
$this->debug($aPrevious);
|
||||||
|
$this->debug("Current");
|
||||||
|
$this->debug($aResult);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function OQLGroupByProviderStatic()
|
||||||
|
{
|
||||||
|
$aData = array();
|
||||||
|
|
||||||
|
$aData["SELECT 1"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`status` != 'closed')", array(), unserialize('a:1:{s:6:"group1";s:22:"`UserRequest`.`status`";}'), false, array(), array(), 0, 0);
|
||||||
|
$aData["SELECT 2"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE 1", array(), unserialize('a:1:{s:12:"grouped_by_1";s:22:"`UserRequest`.`status`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:1;}'), 0, 0);
|
||||||
|
$aData["SELECT 4"] = array("SELECT `Contact` FROM Contact AS `Contact` WHERE 1", array(), unserialize('a:1:{s:12:"grouped_by_1";s:18:"`Contact`.`status`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 5"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`status` NOT IN ('closed', 'rejected'))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:22:"`UserRequest`.`status`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 6"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`status` NOT IN ('closed', 'rejected'))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:24:"`UserRequest`.`agent_id`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 7"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`status` NOT IN ('closed', 'rejected'))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:26:"`UserRequest`.`finalclass`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 8"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`status` NOT IN ('closed', 'rejected'))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:22:"`UserRequest`.`org_id`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 9"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (DATE_SUB(NOW(), INTERVAL 14 DAY) < `UserRequest`.`start_date`)", array(), unserialize('a:1:{s:12:"grouped_by_1";s:28:"`UserRequest`.`request_type`";}'), true, array(), unserialize('a:1:{s:12:"_itop_count_";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 10"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (DATE_SUB(NOW(), INTERVAL 14 DAY) < `UserRequest`.`start_date`)", array(), unserialize('a:1:{s:12:"grouped_by_1";s:51:"DATE_FORMAT(`UserRequest`.`start_date`, \'%Y-%m-%d\')";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:1;}'), 0, 0);
|
||||||
|
$aData["SELECT 11"] = array("SELECT `Change` FROM Change AS `Change` WHERE (`Change`.`creation_date` > DATE_SUB(NOW(), INTERVAL 7 DAY))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:19:"`Change`.`category`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 12"] = array("SELECT `Change` FROM Change AS `Change` WHERE (`Change`.`creation_date` > DATE_SUB(NOW(), INTERVAL 7 DAY))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:21:"`Change`.`finalclass`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 13"] = array("SELECT `Change` FROM Change AS `Change` WHERE (`Change`.`creation_date` > DATE_SUB(NOW(), INTERVAL 7 DAY))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:17:"`Change`.`status`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
$aData["SELECT 14"] = array("SELECT `Change` FROM Change AS `Change` WHERE (`Change`.`creation_date` > DATE_SUB(NOW(), INTERVAL 7 DAY))", array(), unserialize('a:1:{s:12:"grouped_by_1";s:46:"DATE_FORMAT(`Change`.`start_date`, \'%Y-%m-%d\')";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:1;}'), 0, 0);
|
||||||
|
$aData["SELECT 15"] = array("SELECT `FunctionalCI` FROM FunctionalCI AS `FunctionalCI` WHERE (`FunctionalCI`.`org_id` = '3')", array(), unserialize('a:1:{s:6:"group1";s:27:"`FunctionalCI`.`finalclass`";}'), false, array(), array(), 0, 0);
|
||||||
|
$aData["SELECT 16"] = array("SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE ((`UserRequest`.`status` != 'closed') AND (`UserRequest`.`org_id` = '3'))", array(), unserialize('a:1:{s:6:"group1";s:22:"`UserRequest`.`status`";}'), false, array(), array(), 0, 0);
|
||||||
|
$aData["SELECT 17"] = array("SELECT `Ticket` FROM Ticket AS `Ticket` WHERE (`Ticket`.`org_id` = '3')", array(), unserialize('a:1:{s:12:"grouped_by_1";s:21:"`Ticket`.`finalclass`";}'), true, array(), unserialize('a:1:{s:12:"grouped_by_1";b:0;}'), 0, 0);
|
||||||
|
|
||||||
|
return $aData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function OQLGroupByProvider()
|
||||||
|
{
|
||||||
|
$aData = $this->OQLGroupByProviderStatic();
|
||||||
|
|
||||||
|
// Dynamic entries
|
||||||
|
@include ('oql_group_by_records.php');
|
||||||
|
|
||||||
|
return $aData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetId()
|
||||||
|
{
|
||||||
|
$sId = str_replace('"', '', $this->getName());
|
||||||
|
$sId = str_replace('Legacy', '', $sId);
|
||||||
|
$sId = str_replace(' ', '_', $sId);
|
||||||
|
return $sId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $sSQL
|
||||||
|
*
|
||||||
|
* @param int $iLimit
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
* @throws \CoreException
|
||||||
|
* @throws \MySQLException
|
||||||
|
* @throws \MySQLHasGoneAwayException
|
||||||
|
*/
|
||||||
|
private function GetArrayResult($sSQL, $iLimit = 10)
|
||||||
|
{
|
||||||
|
$resQuery = CMDBSource::Query($sSQL);
|
||||||
|
if (!$resQuery)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aRow = array();
|
||||||
|
$iCount = 0;
|
||||||
|
while ($aRes = CMDBSource::FetchArray($resQuery))
|
||||||
|
{
|
||||||
|
if ($iCount < $iLimit)
|
||||||
|
{
|
||||||
|
$aRow[] = $aRes;
|
||||||
|
}
|
||||||
|
$iCount++;
|
||||||
|
unset($aRes);
|
||||||
|
}
|
||||||
|
CMDBSource::FreeResult($resQuery);
|
||||||
|
return $aRow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
@@ -10,8 +10,17 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
|||||||
|
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
use CoreException;
|
||||||
|
use DeleteException;
|
||||||
|
use Exception;
|
||||||
|
use MetaModel;
|
||||||
use TagSetFieldData;
|
use TagSetFieldData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class TagSetFieldDataTest extends ItopDataTestCase
|
class TagSetFieldDataTest extends ItopDataTestCase
|
||||||
{
|
{
|
||||||
// Need database COMMIT in order to create the FULLTEXT INDEX of MySQL
|
// Need database COMMIT in order to create the FULLTEXT INDEX of MySQL
|
||||||
@@ -61,7 +70,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'Fourth');
|
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'Fourth');
|
||||||
} catch (\CoreException $e)
|
} catch (CoreException $e)
|
||||||
{
|
{
|
||||||
$this->debug($e->getMessage());
|
$this->debug($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -72,7 +81,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'zembrek');
|
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag4', 'zembrek');
|
||||||
} catch (\CoreException $e)
|
} catch (CoreException $e)
|
||||||
{
|
{
|
||||||
$this->debug($e->getMessage());
|
$this->debug($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -83,7 +92,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'zembrek', 'Fourth');
|
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'zembrek', 'Fourth');
|
||||||
} catch (\CoreException $e)
|
} catch (CoreException $e)
|
||||||
{
|
{
|
||||||
$this->debug($e->getMessage());
|
$this->debug($e->getMessage());
|
||||||
}
|
}
|
||||||
@@ -113,7 +122,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$oTagData->DBDelete();
|
$oTagData->DBDelete();
|
||||||
} catch (\DeleteException $e)
|
} catch (DeleteException $e)
|
||||||
{
|
{
|
||||||
static::assertTrue(true);
|
static::assertTrue(true);
|
||||||
|
|
||||||
@@ -213,7 +222,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
$oTagData->Set('code', 'tag1');
|
$oTagData->Set('code', 'tag1');
|
||||||
$oTagData->DBWrite();
|
$oTagData->DBWrite();
|
||||||
|
|
||||||
} catch (\CoreException $e)
|
} catch (CoreException $e)
|
||||||
{
|
{
|
||||||
static::assertTrue(true);
|
static::assertTrue(true);
|
||||||
|
|
||||||
@@ -231,7 +240,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
public function testMaxTagCodeLength()
|
public function testMaxTagCodeLength()
|
||||||
{
|
{
|
||||||
/** @var \AttributeTagSet $oAttdef */
|
/** @var \AttributeTagSet $oAttdef */
|
||||||
$oAttdef = \MetaModel::GetAttributeDef(TAG_CLASS, TAG_ATTCODE);
|
$oAttdef = MetaModel::GetAttributeDef(TAG_CLASS, TAG_ATTCODE);
|
||||||
|
|
||||||
$iMaxLength = $oAttdef->GetTagCodeMaxLength();
|
$iMaxLength = $oAttdef->GetTagCodeMaxLength();
|
||||||
$sTagCode = str_repeat('a', $iMaxLength);
|
$sTagCode = str_repeat('a', $iMaxLength);
|
||||||
@@ -244,7 +253,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, $sTagCode, $sTagCode);
|
$this->CreateTagData(TAG_CLASS, TAG_ATTCODE, $sTagCode, $sTagCode);
|
||||||
} catch (\CoreException $e)
|
} catch (CoreException $e)
|
||||||
{
|
{
|
||||||
$this->debug('Awaited: '.$e->getMessage());
|
$this->debug('Awaited: '.$e->getMessage());
|
||||||
static::assertTrue(true);
|
static::assertTrue(true);
|
||||||
@@ -257,7 +266,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
public function testMaxTagsAllowed()
|
public function testMaxTagsAllowed()
|
||||||
{
|
{
|
||||||
/** @var \AttributeTagSet $oAttDef */
|
/** @var \AttributeTagSet $oAttDef */
|
||||||
$oAttDef = \MetaModel::GetAttributeDef(TAG_CLASS, TAG_ATTCODE);
|
$oAttDef = MetaModel::GetAttributeDef(TAG_CLASS, TAG_ATTCODE);
|
||||||
$iMaxTags = $oAttDef->GetMaxItems();
|
$iMaxTags = $oAttDef->GetMaxItems();
|
||||||
for ($i = 0; $i < $iMaxTags; $i++)
|
for ($i = 0; $i < $iMaxTags; $i++)
|
||||||
{
|
{
|
||||||
@@ -275,7 +284,7 @@ class TagSetFieldDataTest extends ItopDataTestCase
|
|||||||
$sValue .= "$sTagCode ";
|
$sValue .= "$sTagCode ";
|
||||||
$oObjWithTagSet->Set(TAG_ATTCODE, $sValue);
|
$oObjWithTagSet->Set(TAG_ATTCODE, $sValue);
|
||||||
$oObjWithTagSet->DBWrite();
|
$oObjWithTagSet->DBWrite();
|
||||||
} catch (\Exception $e)
|
} catch (Exception $e)
|
||||||
{
|
{
|
||||||
// Should fail on the last iteration
|
// Should fail on the last iteration
|
||||||
static::assertEquals($iMaxTags, $i);
|
static::assertEquals($iMaxTags, $i);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||||
|
use CoreUnexpectedValue;
|
||||||
|
use MetaModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class UniquenessConstraintTest
|
* Class UniquenessConstraintTest
|
||||||
@@ -12,7 +14,11 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
|||||||
*
|
*
|
||||||
* @package Combodo\iTop\Test\UnitTest\Core
|
* @package Combodo\iTop\Test\UnitTest\Core
|
||||||
*/
|
*/
|
||||||
class UniquenessConstraintTest extends ItopTestCase
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/class UniquenessConstraintTest extends ItopTestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
@@ -34,9 +40,9 @@ class UniquenessConstraintTest extends ItopTestCase
|
|||||||
$bRuleValidResult = true;
|
$bRuleValidResult = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
\MetaModel::CheckUniquenessRuleValidity($aRuleProperties, $bIsRuleOverride);
|
MetaModel::CheckUniquenessRuleValidity($aRuleProperties, $bIsRuleOverride);
|
||||||
}
|
}
|
||||||
catch (\CoreUnexpectedValue $e)
|
catch (CoreUnexpectedValue $e)
|
||||||
{
|
{
|
||||||
$bRuleValidResult = false;
|
$bRuleValidResult = false;
|
||||||
}
|
}
|
||||||
@@ -74,4 +80,4 @@ class UniquenessConstraintTest extends ItopTestCase
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,13 @@
|
|||||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use UserRights;
|
use UserRights;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class UserRightsTest extends ItopDataTestCase
|
class UserRightsTest extends ItopDataTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
|||||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||||
use Dict;
|
use Dict;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,4 +54,4 @@ class dictTest extends ItopTestCase
|
|||||||
$this->assertInternalType('string', Dict::S('Core:AttributeURL'));
|
$this->assertInternalType('string', Dict::S('Core:AttributeURL'));
|
||||||
$this->assertInternalType('string', Dict::Format('Change:AttName_SetTo', '1', '2'));
|
$this->assertInternalType('string', Dict::Format('Change:AttName_SetTo', '1', '2'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
namespace Combodo\iTop\Test\UnitTest\Core;
|
namespace Combodo\iTop\Test\UnitTest\Core;
|
||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||||
|
use CoreException;
|
||||||
use Exception;
|
use Exception;
|
||||||
use ormTagSet;
|
use ormTagSet;
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ class ormTagSetTest extends ItopDataTestCase
|
|||||||
{
|
{
|
||||||
$oTagSet->SetValues(array('tag1', 'tag2', 'tag3', 'tag4'));
|
$oTagSet->SetValues(array('tag1', 'tag2', 'tag3', 'tag4'));
|
||||||
}
|
}
|
||||||
catch (\CoreException $e)
|
catch (CoreException $e)
|
||||||
{
|
{
|
||||||
$this->debug('Awaited: '.$e->getMessage());
|
$this->debug('Awaited: '.$e->getMessage());
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|||||||
@@ -745,7 +745,7 @@ class ItopTicketTest extends ItopDataTestCase
|
|||||||
* +====>Person2
|
* +====>Person2
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @throws ArchivedObjectException
|
* @throws \ArchivedObjectException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testUpdateImpactedItems_Redundancy_two_tickets()
|
public function testUpdateImpactedItems_Redundancy_two_tickets()
|
||||||
@@ -849,7 +849,7 @@ class ItopTicketTest extends ItopDataTestCase
|
|||||||
* +====>Person2
|
* +====>Person2
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @throws ArchivedObjectException
|
* @throws \ArchivedObjectException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function testUpdateImpactedItems_Redundancy_two_tickets2()
|
public function testUpdateImpactedItems_Redundancy_two_tickets2()
|
||||||
|
|||||||
@@ -261,7 +261,7 @@ case 'zoom':
|
|||||||
{
|
{
|
||||||
$aExplain = CMDBSource::ExplainQuery($oQuery->sSql);
|
$aExplain = CMDBSource::ExplainQuery($oQuery->sSql);
|
||||||
$oP->add("<h4>Explain</h4>\n");
|
$oP->add("<h4>Explain</h4>\n");
|
||||||
$oP->add("<table border=\"1\">\n");
|
$oP->add("<table style=\"border=1px;\">\n");
|
||||||
foreach ($aExplain as $aRow)
|
foreach ($aExplain as $aRow)
|
||||||
{
|
{
|
||||||
$oP->add(" <tr>\n");
|
$oP->add(" <tr>\n");
|
||||||
@@ -274,7 +274,7 @@ case 'zoom':
|
|||||||
if (count($oQuery->aRows))
|
if (count($oQuery->aRows))
|
||||||
{
|
{
|
||||||
$oP->add("<h4>Values</h4>\n");
|
$oP->add("<h4>Values</h4>\n");
|
||||||
$oP->add("<table border=\"1\">\n");
|
$oP->add("<table style=\"border=1px;\">\n");
|
||||||
foreach ($oQuery->aRows as $iRow => $aRow)
|
foreach ($oQuery->aRows as $iRow => $aRow)
|
||||||
{
|
{
|
||||||
$oP->add(" <tr>\n");
|
$oP->add(" <tr>\n");
|
||||||
@@ -352,4 +352,4 @@ case 'benchmark':
|
|||||||
}
|
}
|
||||||
|
|
||||||
$oP->output();
|
$oP->output();
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -4,7 +4,13 @@ namespace Combodo\iTop\Test\UnitTest\Core;
|
|||||||
|
|
||||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||||
use Config;
|
use Config;
|
||||||
|
use DBBackup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
|
*/
|
||||||
class DBBackupTest extends ItopTestCase
|
class DBBackupTest extends ItopTestCase
|
||||||
{
|
{
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
@@ -20,16 +26,16 @@ class DBBackupTest extends ItopTestCase
|
|||||||
$oConfig = new Config();
|
$oConfig = new Config();
|
||||||
$oConfig->Set('db_tls.enabled', false);
|
$oConfig->Set('db_tls.enabled', false);
|
||||||
|
|
||||||
$sCliArgsNoTls = \DBBackup::GetMysqlCliTlsOptions($oConfig);
|
$sCliArgsNoTls = DBBackup::GetMysqlCliTlsOptions($oConfig);
|
||||||
$this->assertEmpty($sCliArgsNoTls);
|
$this->assertEmpty($sCliArgsNoTls);
|
||||||
|
|
||||||
$oConfig->Set('db_tls.enabled', true);
|
$oConfig->Set('db_tls.enabled', true);
|
||||||
$sCliArgsMinCfg = \DBBackup::GetMysqlCliTlsOptions($oConfig);
|
$sCliArgsMinCfg = DBBackup::GetMysqlCliTlsOptions($oConfig);
|
||||||
$this->assertEquals(' --ssl', $sCliArgsMinCfg);
|
$this->assertEquals(' --ssl', $sCliArgsMinCfg);
|
||||||
|
|
||||||
$sTestCa = 'my_test_ca';
|
$sTestCa = 'my_test_ca';
|
||||||
$oConfig->Set('db_tls.ca', $sTestCa);
|
$oConfig->Set('db_tls.ca', $sTestCa);
|
||||||
$sCliArgsCapathCfg = \DBBackup::GetMysqlCliTlsOptions($oConfig);
|
$sCliArgsCapathCfg = DBBackup::GetMysqlCliTlsOptions($oConfig);
|
||||||
$this->assertEquals(' --ssl --ssl-ca="'.$sTestCa.'"', $sCliArgsCapathCfg);
|
$this->assertEquals(' --ssl --ssl-ca="'.$sTestCa.'"', $sCliArgsCapathCfg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,10 +12,11 @@ namespace Combodo\iTop\Test\UnitTest\Status;
|
|||||||
* Date: 25/01/2019
|
* Date: 25/01/2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Config;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
use function Combodo\iTop\Application\Status\StatusCheckConfigFile;
|
use function Combodo\iTop\Application\Status\StatusCheckConfigFile;
|
||||||
use function Combodo\iTop\Application\Status\StatusGetAppRoot;
|
use function Combodo\iTop\Application\Status\StatusGetAppRoot;
|
||||||
use function Combodo\iTop\Application\Status\StatusStartup;
|
use function Combodo\iTop\Application\Status\StatusStartup;
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
if (!defined('DEBUG_UNIT_TEST')) {
|
if (!defined('DEBUG_UNIT_TEST')) {
|
||||||
define('DEBUG_UNIT_TEST', true);
|
define('DEBUG_UNIT_TEST', true);
|
||||||
@@ -98,7 +99,7 @@ class StatusIncTest extends TestCase {
|
|||||||
require_once(APPROOT . '/application/utils.inc.php');
|
require_once(APPROOT . '/application/utils.inc.php');
|
||||||
require_once(APPROOT . '/core/contexttag.class.inc.php');
|
require_once(APPROOT . '/core/contexttag.class.inc.php');
|
||||||
|
|
||||||
$oConfigWrong = new \Config(ITOP_DEFAULT_CONFIG_FILE);
|
$oConfigWrong = new Config(ITOP_DEFAULT_CONFIG_FILE);
|
||||||
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd') . '_unittest');
|
$oConfigWrong->Set('db_pwd', $oConfigWrong->Get('db_pwd') . '_unittest');
|
||||||
|
|
||||||
StatusStartup($oConfigWrong);
|
StatusStartup($oConfigWrong);
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ namespace Combodo\iTop\Test\UnitTest\Status;
|
|||||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @runTestsInSeparateProcesses
|
||||||
|
* @preserveGlobalState disabled
|
||||||
|
* @backupGlobals disabled
|
||||||
*/
|
*/
|
||||||
class StatusTest extends ItopTestCase {
|
class StatusTest extends ItopTestCase {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user