From 948bcb032a026f20f7cc6ba1baa6fb34907ec37e Mon Sep 17 00:00:00 2001 From: odain Date: Fri, 7 Apr 2023 07:06:32 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B05341=20-=20fix=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/ormcaselog.class.inc.php | 14 +++++--- .../unitary-tests/core/ormCaseLogTest.php | 34 +++++++++---------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/core/ormcaselog.class.inc.php b/core/ormcaselog.class.inc.php index 5bf2ab7ca..56839570e 100644 --- a/core/ormcaselog.class.inc.php +++ b/core/ormcaselog.class.inc.php @@ -516,8 +516,11 @@ class ormCaseLog { */ public function AddLogEntry($sText, $sOnBehalfOf = '') { - $sText = HTMLSanitizer::Sanitize($sText); + //date/time ops moved here for test stability + $iNow = time(); $sDate = date(AttributeDateTime::GetInternalFormat()); + + $sText = HTMLSanitizer::Sanitize($sText); if ($sOnBehalfOf == '') { $sOnBehalfOf = UserRights::GetUserFriendlyName(); @@ -550,7 +553,7 @@ class ormCaseLog { $this->m_aIndex[] = array( 'user_name' => $sOnBehalfOf, 'user_id' => $iUserId, - 'date' => time(), + 'date' => $iNow, 'text_length' => $iTextLength, 'separator_length' => $iSepLength, 'format' => 'html', @@ -562,6 +565,9 @@ class ormCaseLog { public function AddLogEntryFromJSON($oJson, $bCheckUserId = true) { + //date/time ops moved here for test stability + $iNow = time(); + if (isset($oJson->user_id)) { if (!UserRights::IsAdministrator()) @@ -600,7 +606,7 @@ class ormCaseLog { } else { - $iDate = time(); + $iDate = $iNow; } if (isset($oJson->format)) { @@ -628,7 +634,7 @@ class ormCaseLog { $this->m_aIndex[] = array( 'user_name' => $sOnBehalfOf, 'user_id' => $iUserId, - 'date' => time(), + 'date' => $iNow, 'text_length' => $iTextLength, 'separator_length' => $iSepLength, 'format' => 'html', diff --git a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php index 139ed0fac..9c081c6a1 100644 --- a/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php +++ b/tests/php-unit-tests/unitary-tests/core/ormCaseLogTest.php @@ -221,6 +221,11 @@ class ormCaseLogTest extends ItopDataTestCase $sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId); $sExpectedLog = $sSeparator."

$sLog

"; + $aRebuiltIndex = ['c' => 'd']; + $aReturnedIndex= $bRebuild ? $aRebuiltIndex : []; + + $oOrmCaseLogService = $this->createMock(\ormCaseLogService::class); + $aExpectedIndex = [ [ 'user_name' => $sOnBehalfOf, @@ -231,11 +236,6 @@ class ormCaseLogTest extends ItopDataTestCase 'format' => 'html', ] ]; - - $aRebuiltIndex = ['c' => 'd']; - $aReturnedIndex= $bRebuild ? $aRebuiltIndex : []; - - $oOrmCaseLogService = $this->createMock(\ormCaseLogService::class); $oOrmCaseLogService->expects($this->exactly(2)) ->method('RebuildIndex') ->withConsecutive(['', []], [$sExpectedLog, $aExpectedIndex]) @@ -266,6 +266,18 @@ class ormCaseLogTest extends ItopDataTestCase $sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId); $sExpectedLog = $sSeparator."

$sLog

"; + $aRebuiltIndex = ['c' => 'd']; + $aReturnedIndex= $bRebuild ? $aRebuiltIndex : []; + + $sJson = json_encode( + [ + 'user_login' => 'gabuzmeu', + 'message' => $sLog, + ] + ); + $oJson = json_decode($sJson); + + $oOrmCaseLogService = $this->createMock(\ormCaseLogService::class); $aExpectedIndex = [ [ 'user_name' => $sOnBehalfOf, @@ -276,24 +288,12 @@ class ormCaseLogTest extends ItopDataTestCase 'format' => 'html', ] ]; - - $aRebuiltIndex = ['c' => 'd']; - $aReturnedIndex= $bRebuild ? $aRebuiltIndex : []; - - $oOrmCaseLogService = $this->createMock(\ormCaseLogService::class); $oOrmCaseLogService->expects($this->exactly(2)) ->method('RebuildIndex') ->withConsecutive(['', []], [$sExpectedLog, $aExpectedIndex]) ->willReturnOnConsecutiveCalls([], $aReturnedIndex); $oLog = new ormCaseLog('', [], $oOrmCaseLogService); - $sJson = json_encode( - [ - 'user_login' => 'gabuzmeu', - 'message' => $sLog, - ] - ); - $oJson = json_decode($sJson); $oLog->AddLogEntryFromJSON($oJson, false); $this->assertEquals($sExpectedLog, $oLog->GetText()); if ($bRebuild){