mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
test SDK enhancement: be able to compare moduleinstallation
ci: add log and hopefully fix hub test ci: fix all test that rely on CustomDataTC
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Combodo\iTop\DBTools\Service;
|
||||
use CMDBSource;
|
||||
use DBObjectSearch;
|
||||
use DBObjectSet;
|
||||
use IssueLog;
|
||||
|
||||
class DBToolsUtils
|
||||
{
|
||||
@@ -138,6 +139,49 @@ EOF;
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return previous module installation. offset is applied on parent_id.
|
||||
* @param $iOffset
|
||||
* @return array
|
||||
*/
|
||||
public static function GetPreviousModuleInstallationsByOffset(int $iOffset = 0): array
|
||||
{
|
||||
$oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation AS mi WHERE mi.parent_id=0 AND mi.name!="datamodel"');
|
||||
$oSet = new DBObjectSet($oFilter, ['installed' => false]); // Most recent first
|
||||
$oSet->SetLimit($iOffset + 1);
|
||||
|
||||
$iParentId = 0;
|
||||
/** @var \DBObject $oModuleInstallation */
|
||||
while ($oModuleInstallation = $oSet->Fetch()) {
|
||||
if ($iOffset == 0) {
|
||||
$iParentId = $oModuleInstallation->Get('id');
|
||||
break;
|
||||
}
|
||||
$iOffset--;
|
||||
}
|
||||
|
||||
if ($iParentId === 0) {
|
||||
IssueLog::Error("no ITOP_APPLICATION ModuleInstallation found", null, ['offset' => $iOffset]);
|
||||
throw new \Exception("no ITOP_APPLICATION ModuleInstallation found");
|
||||
}
|
||||
|
||||
$oFilter = DBObjectSearch::FromOQL("SELECT ModuleInstallation AS mi WHERE mi.id=$iParentId OR mi.parent_id=$iParentId");
|
||||
$oSet = new DBObjectSet($oFilter); // Most recent first
|
||||
$aRawValues = $oSet->ToArrayOfValues();
|
||||
$aValues = [];
|
||||
foreach ($aRawValues as $aRawValue) {
|
||||
$aValue = [];
|
||||
foreach ($aRawValue as $sAliasAttCode => $sValue) {
|
||||
// remove 'mi.' from AttCode
|
||||
$sAttCode = substr($sAliasAttCode, 3);
|
||||
$aValue[$sAttCode] = $sValue;
|
||||
}
|
||||
|
||||
$aValues[] = $aValue;
|
||||
}
|
||||
return $aValues;
|
||||
}
|
||||
|
||||
public static function GetDBTablesInfo()
|
||||
{
|
||||
self::AnalyzeTables();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\HubConnector;
|
||||
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\HubConnector\Controller\HubController;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use DOMFormatException;
|
||||
@@ -45,6 +46,7 @@ class HubControllerTest extends ItopDataTestCase
|
||||
$this->testLaunchCompile();
|
||||
HubController::GetInstance()->LaunchDeploy();
|
||||
$this->CheckReport('{"code":0,"message":"Compilation successful.","fields":[]}');
|
||||
$this->CompareCurrentAndPreviousModuleInstallations();
|
||||
}
|
||||
|
||||
private function CheckReport($sExpected)
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Combodo\iTop\Test\UnitTest;
|
||||
use ArchivedObjectException;
|
||||
use CMDBObject;
|
||||
use CMDBSource;
|
||||
use Combodo\iTop\DBTools\Service\DBToolsUtils;
|
||||
use Combodo\iTop\Service\Events\EventService;
|
||||
use Config;
|
||||
use Contact;
|
||||
@@ -1556,4 +1557,32 @@ abstract class ItopDataTestCase extends ItopTestCase
|
||||
@chmod($sConfigPath, 0440);
|
||||
@unlink($this->sConfigTmpBackupFile);
|
||||
}
|
||||
|
||||
public function CompareCurrentAndPreviousModuleInstallations()
|
||||
{
|
||||
$this->RequireOnceItopFile('env-production/combodo-db-tools/src/Service/DBToolsUtils.php');
|
||||
$aPreviousInstallations = DBToolsUtils::GetPreviousModuleInstallationsByOffset(1);
|
||||
$aInstallations = DBToolsUtils::GetPreviousModuleInstallationsByOffset();
|
||||
$this->assertEquals($this->KeepModuleInstallationComparableFields($aPreviousInstallations), $this->KeepModuleInstallationComparableFields($aInstallations));
|
||||
}
|
||||
|
||||
public function KeepModuleInstallationComparableFields($aInstallations): array
|
||||
{
|
||||
$aRes = [];
|
||||
$aIgnoredFields = ['id', 'parent_id', 'installed', 'comment'];
|
||||
foreach ($aInstallations as $aData) {
|
||||
$aNewData = [];
|
||||
foreach ($aData as $sKey => $val) {
|
||||
if (in_array($sKey, $aIgnoredFields)) {
|
||||
continue;
|
||||
}
|
||||
$aNewData[$sKey] = $val;
|
||||
}
|
||||
$sName = $aNewData['name'];
|
||||
$aRes[$sName] = $aNewData;
|
||||
}
|
||||
|
||||
asort($aRes);
|
||||
return $aRes;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user