From 73bb80ebeacbbb131860548aa29ef9132c03f80b Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Mon, 6 Jan 2025 11:31:22 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B07206=20-=20Force=20DBUpdate()=20when=20a?= =?UTF-8?q?=20transition=20is=20asked,=20and=20it=20leads=20to=20the=20sam?= =?UTF-8?q?e=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobject.class.php | 8 ++++++++ tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php | 4 ++-- .../unitary-tests/core/TriggerOnStateEnterTest.php | 6 ++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index bf51353eb..48b3364ed 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -2867,6 +2867,14 @@ abstract class DBObject implements iDisplay protected function ListChangedValues(array $aProposal) { $aDelta = array(); + $sClass = get_class($this); + if (MetaModel::HasLifecycle($sClass) && utils::IsNotNullOrEmptyString($this->sStimulusBeingApplied)) { + $sStateAttCode = MetaModel::GetStateAttributeCode($sClass); + if (!in_array($sStateAttCode, $aProposal)) { + // Same state but the transition was asked, act as if the state was changed + $aDelta[$sStateAttCode] = $this->m_aCurrValues[$sStateAttCode]; + } + } foreach ($aProposal as $sAtt => $proposedValue) { if (!array_key_exists($sAtt, $this->m_aOrigValues)) diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php index 463d1c44b..52cbe3436 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopTestCase.php @@ -9,9 +9,9 @@ namespace Combodo\iTop\Test\UnitTest; use CMDBSource; use DeprecatedCallsLog; use MySQLTransactionNotClosedException; +use PHPUnit\Framework\TestCase; use ReflectionMethod; use SetupUtils; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; use const DEBUG_BACKTRACE_IGNORE_ARGS; @@ -23,7 +23,7 @@ use const DEBUG_BACKTRACE_IGNORE_ARGS; * * @since 3.0.4 3.1.1 3.2.0 N°6658 move some setUp/tearDown code to the corresponding methods *BeforeClass to speed up tests process time. */ -abstract class ItopTestCase extends KernelTestCase +abstract class ItopTestCase extends TestCase { public const TEST_LOG_DIR = 'test'; diff --git a/tests/php-unit-tests/unitary-tests/core/TriggerOnStateEnterTest.php b/tests/php-unit-tests/unitary-tests/core/TriggerOnStateEnterTest.php index 32134c1e2..f7e878354 100644 --- a/tests/php-unit-tests/unitary-tests/core/TriggerOnStateEnterTest.php +++ b/tests/php-unit-tests/unitary-tests/core/TriggerOnStateEnterTest.php @@ -35,11 +35,9 @@ class TriggerOnStateEnterTest extends ItopDataTestCase $oUserRequest = $this->GivenUserRequest('new'); $oUserRequest->ApplyStimulus('ev_assign'); - $bTransitionned = $oUserRequest->ApplyStimulus('ev_reassign'); - $this->assertTrue($bTransitionned, 'The stimulus should have been accepted'); - return; + $bTransitioned = $oUserRequest->ApplyStimulus('ev_reassign'); + $this->assertTrue($bTransitioned, 'The stimulus should have been accepted'); - $this->MarkTestSkipped('This test fails because the trigger is not executed'); $this->AssertTriggerExecuted($iTrigger, 2, 'The trigger should have been executed twice'); } public function testIsTriggeredOnNewObject()