mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
deletion plan test coverage
This commit is contained in:
@@ -102,7 +102,7 @@ class DeletionPlanService
|
|||||||
* @throws \CoreUnexpectedValue
|
* @throws \CoreUnexpectedValue
|
||||||
* @throws \MySQLException
|
* @throws \MySQLException
|
||||||
*/
|
*/
|
||||||
public function ExecuteDeletionPlan(array $aClasses, int $iUnixTimeLimit = 0, int $iMaxExecutionCount=0): array
|
public function ExecuteDeletionPlan(array $aClasses, int $iUnixTimeLimit = 0, int $iMaxExecutionCount = -1): array
|
||||||
{
|
{
|
||||||
$oDeletionPlan = $this->GetDeletionPlan($aClasses);
|
$oDeletionPlan = $this->GetDeletionPlan($aClasses);
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ class DeletionPlanService
|
|||||||
throw new DataFeatureRemovalException("Deletion Plan cannot be executed due to issues");
|
throw new DataFeatureRemovalException("Deletion Plan cannot be executed due to issues");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->iExecutionCount=0;
|
$this->iExecutionCount = 0;
|
||||||
|
|
||||||
$aSummary = [];
|
$aSummary = [];
|
||||||
foreach ($oDeletionPlan->ListUpdates() as $sClass => $aToUpdate) {
|
foreach ($oDeletionPlan->ListUpdates() as $sClass => $aToUpdate) {
|
||||||
@@ -199,13 +199,12 @@ class DeletionPlanService
|
|||||||
|
|
||||||
public function IsTimeLimitExceeded(int $iUnixTimeLimit, int $iMaxExecutionCount): bool
|
public function IsTimeLimitExceeded(int $iUnixTimeLimit, int $iMaxExecutionCount): bool
|
||||||
{
|
{
|
||||||
throw new \Exception("");
|
if (($iMaxExecutionCount !== -1) && ($iMaxExecutionCount <= $this->iExecutionCount)) {
|
||||||
$this->iExecutionCount++;
|
return true;
|
||||||
echo json_encode([$this->iExecutionCount, $iMaxExecutionCount]);
|
|
||||||
if ($iMaxExecutionCount === $this->iExecutionCount){
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->iExecutionCount++;
|
||||||
|
|
||||||
if ($iUnixTimeLimit === 0) {
|
if ($iUnixTimeLimit === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -366,12 +366,10 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
|
|||||||
EOF);
|
EOF);
|
||||||
|
|
||||||
$aClasses = [ 'DFRToRemoveLeaf' ];
|
$aClasses = [ 'DFRToRemoveLeaf' ];
|
||||||
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 2);
|
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 3);
|
||||||
$aExpected = [
|
$aExpected = [
|
||||||
['DFRToUpdate', 2, 0 ],
|
['DFRToUpdate', 3, 0 ],
|
||||||
['DFRToRemoveLeaf', 0, 0 ],
|
['DFRToRemoveLeaf', 0, 0 ],
|
||||||
['DFRRemovedCollateral', 0, 0 ],
|
|
||||||
['DFRRemovedCollateralCascade', 0, 0 ],
|
|
||||||
];
|
];
|
||||||
$this->AssertSummaryEquals($aExpected, $aRes);
|
$this->AssertSummaryEquals($aExpected, $aRes);
|
||||||
}
|
}
|
||||||
@@ -393,16 +391,48 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
|
|||||||
EOF);
|
EOF);
|
||||||
|
|
||||||
$aClasses = [ 'DFRToRemoveLeaf' ];
|
$aClasses = [ 'DFRToRemoveLeaf' ];
|
||||||
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 5);
|
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 8);
|
||||||
$aExpected = [
|
$aExpected = [
|
||||||
['DFRToUpdate', 3, 0 ],
|
['DFRToUpdate', 3, 0 ],
|
||||||
['DFRToRemoveLeaf', 2, 0 ],
|
['DFRToRemoveLeaf', 0, 3 ],
|
||||||
['DFRRemovedCollateral', 0, 0 ],
|
['DFRRemovedCollateral', 0, 2 ],
|
||||||
['DFRRemovedCollateralCascade', 0, 0 ],
|
|
||||||
];
|
];
|
||||||
$this->AssertSummaryEquals($aExpected, $aRes);
|
$this->AssertSummaryEquals($aExpected, $aRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testExecuteDeletionPlan_WrongOrderDeletion()
|
||||||
|
{
|
||||||
|
$this->GivenDFRTreeInDB(<<<EOF
|
||||||
|
DFRToRemoveLeaf_1 <- DFRRemovedCollateral_1
|
||||||
|
DFRRemovedCollateral_1 <- DFRRemovedCollateralCascade_1
|
||||||
|
|
||||||
|
DFRToRemoveLeaf_2 <- DFRRemovedCollateral_2
|
||||||
|
DFRRemovedCollateral_2 <- DFRRemovedCollateralCascade_2
|
||||||
|
|
||||||
|
DFRToRemoveLeaf_3 <- DFRRemovedCollateral_3
|
||||||
|
DFRRemovedCollateral_3 <- DFRRemovedCollateralCascade_3
|
||||||
|
EOF);
|
||||||
|
|
||||||
|
$aClasses = [ 'DFRToRemoveLeaf' ];
|
||||||
|
|
||||||
|
$oSet = new \DBObjectSet(\DBObjectSearch::FromOQL("SELECT DFRRemovedCollateral WHERE name='DFRRemovedCollateral_3'"));
|
||||||
|
$oExpectedObj = $oSet->Fetch();
|
||||||
|
self::assertNotNull($oExpectedObj);
|
||||||
|
|
||||||
|
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 5);
|
||||||
|
$aExpected = [
|
||||||
|
['DFRToRemoveLeaf', 0, 3 ],
|
||||||
|
['DFRRemovedCollateral', 0, 2 ],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->AssertSummaryEquals($aExpected, $aRes);
|
||||||
|
|
||||||
|
$oSet = new \DBObjectSet(\DBObjectSearch::FromOQL("SELECT DFRRemovedCollateral WHERE name='DFRRemovedCollateral_3'"));
|
||||||
|
$oActualObj = $oSet->Fetch();
|
||||||
|
self::assertNotNull($oActualObj, "Deletion plan executed in wrong order: DFRRemovedCollateralCascade/DFRRemovedCollateral are not valid anymore");
|
||||||
|
self::assertEquals($oExpectedObj->GetKey(), $oActualObj->GetKey());
|
||||||
|
}
|
||||||
|
|
||||||
public function GetDatamodelDeltaAbsPath(): string
|
public function GetDatamodelDeltaAbsPath(): string
|
||||||
{
|
{
|
||||||
return __DIR__.'/deletionplan_delta.xml';
|
return __DIR__.'/deletionplan_delta.xml';
|
||||||
@@ -412,7 +442,7 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
|
|||||||
{
|
{
|
||||||
$aTree = explode("\n", $sTree);
|
$aTree = explode("\n", $sTree);
|
||||||
foreach ($aTree as $sLine) {
|
foreach ($aTree as $sLine) {
|
||||||
if (trim($sLine) === ""){
|
if (trim($sLine) === "") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->GivenDFRTreeLineInDB($sLine);
|
$this->GivenDFRTreeLineInDB($sLine);
|
||||||
@@ -423,18 +453,18 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
|
|||||||
private function GivenDFRTreeLineInDB(string $sLine)
|
private function GivenDFRTreeLineInDB(string $sLine)
|
||||||
{
|
{
|
||||||
list($sLeft, $sRight) = explode('<-', $sLine);
|
list($sLeft, $sRight) = explode('<-', $sLine);
|
||||||
$sLeft=trim($sLeft);
|
$sLeft = trim($sLeft);
|
||||||
|
|
||||||
$iLeftId = $this->aIdByObjectName[$sLeft] ?? 0;
|
$iLeftId = $this->aIdByObjectName[$sLeft] ?? 0;
|
||||||
if ($iLeftId===0){
|
if ($iLeftId === 0) {
|
||||||
list($sChildClass, ) = explode('_', $sLeft, 2);
|
list($sChildClass, ) = explode('_', $sLeft, 2);
|
||||||
$iLeftId = $this->GivenObjectInDB($sChildClass, ['name' => $sLeft]);
|
$iLeftId = $this->GivenObjectInDB($sChildClass, ['name' => $sLeft]);
|
||||||
$this->aIdByObjectName[$sLeft]=$iLeftId;
|
$this->aIdByObjectName[$sLeft] = $iLeftId;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sRight=trim($sRight);
|
$sRight = trim($sRight);
|
||||||
list($sChildClass, ) = explode('_', $sRight, 2);
|
list($sChildClass, ) = explode('_', $sRight, 2);
|
||||||
$iRightId = $this->GivenObjectInDB($sChildClass, ['name' => $sRight, 'extkey_id' => $iLeftId]);
|
$iRightId = $this->GivenObjectInDB($sChildClass, ['name' => $sRight, 'extkey_id' => $iLeftId]);
|
||||||
$this->aIdByObjectName[$sRight]=$iRightId;
|
$this->aIdByObjectName[$sRight] = $iRightId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user