From 4b4197d9104162b0aea74af2fade7af871a1f79d Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 28 Jan 2025 11:08:04 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B08131=20-=20:white=5Fcheck=5Fmark:=20Issu?= =?UTF-8?q?e=20on=20DBlinkchange=20event=20when=20object=20is=20deleted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CRUDEventWithModifiedDataModelTest.php | 17 +++++++++++++---- .../core/DBObject/Delta/dbobjecttest.xml | 14 +++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/DBObject/CRUDEventWithModifiedDataModelTest.php b/tests/php-unit-tests/unitary-tests/core/DBObject/CRUDEventWithModifiedDataModelTest.php index f941be05d..2c0fae0a1 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObject/CRUDEventWithModifiedDataModelTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObject/CRUDEventWithModifiedDataModelTest.php @@ -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; @@ -34,14 +35,14 @@ class CRUDEventWithModifiedDataModelTest extends ItopCustomDatamodelTestCase { static::CleanCallCount(); parent::setUp(); - static::$DEBUG_UNIT_TEST = false; + static::$DEBUG_UNIT_TEST = true; if (static::$DEBUG_UNIT_TEST) { echo '--- logging in '.APPROOT.static::$sLogFile."\n\n"; @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'); } diff --git a/tests/php-unit-tests/unitary-tests/core/DBObject/Delta/dbobjecttest.xml b/tests/php-unit-tests/unitary-tests/core/DBObject/Delta/dbobjecttest.xml index af58c4d92..20c31528e 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObject/Delta/dbobjecttest.xml +++ b/tests/php-unit-tests/unitary-tests/core/DBObject/Delta/dbobjecttest.xml @@ -19,15 +19,23 @@ false - all + none - + parent_id true + TestDBObject DEL_AUTO - all + none + + + + TestDBObject + parent_id + 0 + 0 true