Merge remote-tracking branch 'origin/support/3.2' into develop

This commit is contained in:
Eric Espie
2025-01-28 11:13:05 +01:00
2 changed files with 23 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ namespace Combodo\iTop\Test\UnitTest\Core\DBObject;
use Combodo\iTop\Test\UnitTest\ItopCustomDatamodelTestCase;
use DBObject\Utils\ClassesWithDebug;
use DBObject\Utils\CRUDEventReceiver;
use DBObject\Utils\EventTest;
use IssueLog;
use LogChannels;
@@ -41,7 +42,7 @@ class CRUDEventWithModifiedDataModelTest extends ItopCustomDatamodelTestCase
@unlink(APPROOT.static::$sLogFile);
IssueLog::Enable(APPROOT.static::$sLogFile);
$oConfig = utils::GetConfig();
$oConfig->Set('log_level_min', [LogChannels::DM_CRUD => 'Trace', LogChannels::EVENT_SERVICE => 'Trace']);
$oConfig->Set('log_level_min', [LogChannels::DM_CRUD => 'Debug', LogChannels::EVENT_SERVICE => 'Trace']);
}
}
@@ -56,16 +57,24 @@ class CRUDEventWithModifiedDataModelTest extends ItopCustomDatamodelTestCase
parent::tearDown();
}
/*
* Test that when an object is deleted while having a link set with php computation
* linked to a nullable external key, the db_links_changed event is not fired
*/
public function testDBLinksChangedNotCalledOnDeletedObjects()
{
$oEventReceiver = new CRUDEventReceiver($this);
$oEventReceiver->RegisterCRUDEventListeners(EVENT_DB_LINKS_CHANGED, 'TestDBObject');
$sObjectParentKey = $this->GivenObjectInDB('TestDBObject', ['name' => 'parent']);
$sObjectChildKey = $this->GivenObjectInDB('TestDBObject', ['name' => 'child', 'parent_id' => $sObjectParentKey]);
$oChild = $this->createObject('TestDBObject', ['name' => 'child', 'parent_id' => $sObjectParentKey]);
$this->AssertEventCountEquals(1, EVENT_DB_LINKS_CHANGED, 'Event EVENT_DB_LINKS_CHANGED should have been thrown on child creation');
$oParent = MetaModel::GetObject('TestDBObject', $sObjectParentKey);
static::CleanCallCount();
$oParent->DBDelete();
$oChild = MetaModel::GetObject('TestDBObject', $sObjectChildKey);
$oChild->Reload();
$this->assertEquals(0, $oChild->Get('parent_id'));
$this->AssertEventCountEquals(0, EVENT_DB_LINKS_CHANGED, 'Event EVENT_DB_LINKS_CHANGED should not have been thrown on deleted objects');
}

View File

@@ -19,15 +19,23 @@
<default_value/>
<is_null_allowed>false</is_null_allowed>
<validation_pattern/>
<tracking_level>all</tracking_level>
<tracking_level>none</tracking_level>
</field>
<field id="parent_id" xsi:type="AttributeHierarchicalKey">
<field id="parent_id" xsi:type="AttributeExternalKey">
<sql>parent_id</sql>
<filter/>
<dependencies/>
<is_null_allowed>true</is_null_allowed>
<target_class>TestDBObject</target_class>
<on_target_delete>DEL_AUTO</on_target_delete>
<tracking_level>all</tracking_level>
<tracking_level>none</tracking_level>
<label>Test Object</label>
</field>
<field id="children_list" xsi:type="AttributeLinkedSet">
<linked_class>TestDBObject</linked_class>
<ext_key_to_me>parent_id</ext_key_to_me>
<count_min>0</count_min>
<count_max>0</count_max>
<with_php_computation>true</with_php_computation>
</field>
</fields>