N°5341 - fix test

This commit is contained in:
odain
2023-04-07 07:06:32 +02:00
parent 128e7eed42
commit 948bcb032a
2 changed files with 27 additions and 21 deletions

View File

@@ -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',

View File

@@ -221,6 +221,11 @@ class ormCaseLogTest extends ItopDataTestCase
$sSeparator = sprintf(CASELOG_SEPARATOR, $sDate, $sOnBehalfOf, $iUserId);
$sExpectedLog = $sSeparator."<p>$sLog</p>";
$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."<p>$sLog</p>";
$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){