diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 2aef623709..4e6017c210 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -8988,12 +8988,15 @@ public function GetSubItemAsPlainText($sItemCode, $value) switch ($sThresholdCode) { case 'deadline': if ($value) { - if (is_int($value)) { + if (is_numeric($value)) { + if (!is_int($value)) { + $value = intval($value); + } $sDate = date(AttributeDateTime::GetInternalFormat(), $value); $sRet = AttributeDeadline::FormatDeadline($sDate); - } else { - $sRet = $value; - } + } else { + $sRet = $value; + } } else { $sRet = ''; } diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php new file mode 100644 index 0000000000..f34ae26346 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php @@ -0,0 +1,47 @@ + "Test DisplayStopwatch", + ]; + $oUserRequest = $this->CreateUserRequest(456, $aUserRequestCustomParams); + + $iStartDate = time() - 200; + $oStopwatch = $oUserRequest->Get('ttr'); + $oStopwatch->DefineThreshold(100, $iStartDate); + $oUserRequest->Set('ttr', $oStopwatch); + + $sValue = $oUserRequest->Get('ttr_escalation_deadline'); + $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), 'ttr_escalation_deadline'); + + self::assertEquals('Missed by 3 min', $oAttDef->GetForTemplate($sValue, 'html', $oUserRequest)); + $oDateTime = new DateTime(); + $oDateTime->setTimestamp($iStartDate); + $sDate = $oDateTime->format(AttributeDateTime::GetFormat()); + self::assertEquals($sDate, $oAttDef->GetForTemplate($sValue, 'label', $oUserRequest), 'label() should render the date in the format specified in the configuration file, in parameter "date_and_time_format"'); + self::assertEquals('Missed by 3 min', $oAttDef->GetForTemplate($sValue, 'text', $oUserRequest), 'text() should render the deadline as specified in the configuration file, in parameter "deadline_format", and depending on the user language'); + self::assertEquals($iStartDate, $oAttDef->GetForTemplate($sValue, '', $oUserRequest)); + } +}