From e184eb6aaef7264610b87f6cde7c33b1ed480cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eric=20Espi=C3=A9?= Date: Tue, 17 Jul 2018 12:19:26 +0000 Subject: [PATCH] Retrofit from trunk DBObject->GetOriginal() hardening (now support attributes not set: for example sla_tto_passed for UserRequest until it is closed) [from revision 5932] SVN:2.5[5942] --- core/dbobject.class.php | 3 ++- test/ItopDataTestCase.php | 20 ++++++++++++++++++++ test/core/DBObjectTest.php | 16 +++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index cc55628e8..79bce7ff8 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -568,7 +568,8 @@ abstract class DBObject implements iDisplay { throw new CoreException("Unknown attribute code '$sAttCode' for the class ".get_class($this)); } - return $this->m_aOrigValues[$sAttCode]; + $aOrigValues = $this->m_aOrigValues; + return isset($aOrigValues[$sAttCode]) ? $aOrigValues[$sAttCode] : null; } /** diff --git a/test/ItopDataTestCase.php b/test/ItopDataTestCase.php index 9a7ec5d35..0123f3bae 100644 --- a/test/ItopDataTestCase.php +++ b/test/ItopDataTestCase.php @@ -112,6 +112,26 @@ class ItopDataTestCase extends ItopTestCase return $oMyObj; } + /** + * @param string $sClass + * @param $iKey + * @param array $aParams + * + * @return DBObject + * @throws \ArchivedObjectException + * @throws \CoreException + * @throws \CoreUnexpectedValue + */ + protected static function updateObject($sClass, $iKey, $aParams) + { + $oMyObj = MetaModel::GetObject($sClass, $iKey); + foreach($aParams as $sAttCode => $oValue) + { + $oMyObj->Set($sAttCode, $oValue); + } + $oMyObj->DBUpdate(); + return $oMyObj; + } /** * Create an Organization in database diff --git a/test/core/DBObjectTest.php b/test/core/DBObjectTest.php index 24afa0904..a6e2ea25c 100644 --- a/test/core/DBObjectTest.php +++ b/test/core/DBObjectTest.php @@ -26,9 +26,8 @@ namespace Combodo\iTop\Test\UnitTest\Core; -use Combodo\iTop\Test\UnitTest\ItopTestCase; +use Combodo\iTop\Test\UnitTest\ItopDataTestCase; use DBObject; -use PHPUnit\Framework\TestCase; /** @@ -36,7 +35,7 @@ use PHPUnit\Framework\TestCase; * @preserveGlobalState disabled * @backupGlobals disabled */ -class DBObjectTest extends ItopTestCase +class DBObjectTest extends ItopDataTestCase { protected function setUp() { @@ -50,7 +49,7 @@ class DBObjectTest extends ItopTestCase */ public function testGetUIPage() { - $this->assertEquals('UI.php', DBObject::GetUIPage()); + static::assertEquals('UI.php', DBObject::GetUIPage()); } /** @@ -61,7 +60,7 @@ class DBObjectTest extends ItopTestCase */ public function testIsValidPKeyOK($key, $res) { - $this->assertEquals(DBObject::IsValidPKey($key), $res); + static::assertEquals(DBObject::IsValidPKey($key), $res); } public function keyProviderOK() @@ -80,4 +79,11 @@ class DBObjectTest extends ItopTestCase array('PHP_INT_MIN', false)); } + public function testGetOriginal() + { + $oObject = $this->CreateUserRequest(190664); + + static::assertNull($oObject->GetOriginal('sla_tto_passed')); + } + }