From 058e0b2b8ab501249237e0193f6ced89ec7b7e0f Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 10 Nov 2025 16:14:43 +0100 Subject: [PATCH 1/7] =?UTF-8?q?N=C2=B08692=20-=20Notification=20-=20placeh?= =?UTF-8?q?older=20attributesubitem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/attributedef.class.inc.php | 11 +++++++---- .../core/AttributeDefinitionTest.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) 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/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 5c4e620a41..48b638facf 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php @@ -340,4 +340,20 @@ public function GivenAttribute(string $sHostClass, string $sAttCode, string $sAt return $oAttribute; } + public function testDisplayStopwatch() + { + $aUserRequestCustomParams = [ + 'title' => "Test DisplayStopwatch", + ]; + $oUserRequest = $this->CreateUserRequest(456, $aUserRequestCustomParams); + $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), 'ttr_escalation_deadline'); + $iStartDate = time() - 200; + + $oStopwatch = $oUserRequest->Get('ttr'); + $oStopwatch->DefineThreshold(100, $iStartDate); + $oUserRequest->Set('ttr', $oStopwatch); + $value = $oUserRequest->Get('ttr_escalation_deadline'); + $sRet = $oAttDef->GetAsPlainText($value, $oUserRequest); + self::assertEquals('Missed by 3 min', $sRet); + } } From 93bdb6b9f7bf42d3f8c854bd54506d440cfabbb8 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Tue, 3 Mar 2026 16:13:13 +0100 Subject: [PATCH 2/7] tests --- .../core/AttributeDefinitionTest.php | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 48b638facf..4bfbe085a2 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php @@ -6,6 +6,7 @@ use AttributeDateTime; use Change; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; +use DateTime; use MetaModel; use UserRequest; @@ -340,20 +341,68 @@ public function GivenAttribute(string $sHostClass, string $sAttCode, string $sAt return $oAttribute; } - public function testDisplayStopwatch() + public function DisplayThresholdInNotificationProvider(): array + { + $iTime = time(); + $oDateTime = new DateTime(); + $oDateTime->setTimestamp($iTime - 200); + $sDate = $oDateTime->format("Y-m-d H:i:s"); + + // Note: This is test is not great as we are datamodel dependent and don't have a class with all the attribute types + return [ + 'GetHtml' => [ + 'ttr_escalation_deadline', + 'html', // no default value on this field + $iTime, + 'Missed by 3 min', + ], + 'GetLabel' => [ + 'ttr_escalation_deadline', + 'label', // no default value on this field + $iTime, + $sDate, + ], + 'GetText' => [ + 'ttr_escalation_deadline', + 'text', // no default value on this field + $iTime, + 'Missed by 3 min', + ], + 'Get' => [ + 'ttr_escalation_deadline', + '', // no default value on this field + $iTime, + $iTime - 200, + ], + + ]; + } + + /** + * @dataProvider DisplayThresholdInNotificationProvider + * + * @param string $sAttCode + * @param string $sVerb + * @param string $sExpectedValue + * + * @return void + */ + public function testDisplayThresholdInNotification($sAttCode, $sVerb, $iTime, $sExpectedValue) { $aUserRequestCustomParams = [ 'title' => "Test DisplayStopwatch", ]; $oUserRequest = $this->CreateUserRequest(456, $aUserRequestCustomParams); - $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), 'ttr_escalation_deadline'); - $iStartDate = time() - 200; + $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), $sAttCode); + $iStartDate = $iTime - 200; + - $oStopwatch = $oUserRequest->Get('ttr'); + $oStopwatch = $oUserRequest->Get('ttr'); $oStopwatch->DefineThreshold(100, $iStartDate); $oUserRequest->Set('ttr', $oStopwatch); $value = $oUserRequest->Get('ttr_escalation_deadline'); - $sRet = $oAttDef->GetAsPlainText($value, $oUserRequest); - self::assertEquals('Missed by 3 min', $sRet); + //$sRet = $oAttDef->GetAsPlainText($value, $oUserRequest); + $sRet = $oAttDef->GetForTemplate($oUserRequest->Get($sAttCode), $sVerb, $oUserRequest); + self::assertEquals($sExpectedValue, $sRet); } } From 872f75721390bd14e94db75ed7a556e0a53c24ac Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Thu, 5 Mar 2026 13:59:38 +0100 Subject: [PATCH 3/7] tests --- .../core/AttributeDefinitionTest.php | 65 ------------------- .../core/AttributeSubItemTest.php | 52 +++++++++++++++ 2 files changed, 52 insertions(+), 65 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 4bfbe085a2..9897fb99db 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php @@ -340,69 +340,4 @@ public function GivenAttribute(string $sHostClass, string $sAttCode, string $sAt $oAttribute->SetHostClass($sHostClass); return $oAttribute; } - - public function DisplayThresholdInNotificationProvider(): array - { - $iTime = time(); - $oDateTime = new DateTime(); - $oDateTime->setTimestamp($iTime - 200); - $sDate = $oDateTime->format("Y-m-d H:i:s"); - - // Note: This is test is not great as we are datamodel dependent and don't have a class with all the attribute types - return [ - 'GetHtml' => [ - 'ttr_escalation_deadline', - 'html', // no default value on this field - $iTime, - 'Missed by 3 min', - ], - 'GetLabel' => [ - 'ttr_escalation_deadline', - 'label', // no default value on this field - $iTime, - $sDate, - ], - 'GetText' => [ - 'ttr_escalation_deadline', - 'text', // no default value on this field - $iTime, - 'Missed by 3 min', - ], - 'Get' => [ - 'ttr_escalation_deadline', - '', // no default value on this field - $iTime, - $iTime - 200, - ], - - ]; - } - - /** - * @dataProvider DisplayThresholdInNotificationProvider - * - * @param string $sAttCode - * @param string $sVerb - * @param string $sExpectedValue - * - * @return void - */ - public function testDisplayThresholdInNotification($sAttCode, $sVerb, $iTime, $sExpectedValue) - { - $aUserRequestCustomParams = [ - 'title' => "Test DisplayStopwatch", - ]; - $oUserRequest = $this->CreateUserRequest(456, $aUserRequestCustomParams); - $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), $sAttCode); - $iStartDate = $iTime - 200; - - - $oStopwatch = $oUserRequest->Get('ttr'); - $oStopwatch->DefineThreshold(100, $iStartDate); - $oUserRequest->Set('ttr', $oStopwatch); - $value = $oUserRequest->Get('ttr_escalation_deadline'); - //$sRet = $oAttDef->GetAsPlainText($value, $oUserRequest); - $sRet = $oAttDef->GetForTemplate($oUserRequest->Get($sAttCode), $sVerb, $oUserRequest); - self::assertEquals($sExpectedValue, $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..4b06ad97c3 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php @@ -0,0 +1,52 @@ + "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', MetaModel::ApplyParams('$this->title$', ['this' => $oUserRequest])); + self::assertEquals('Missed by 3 min', MetaModel::ApplyParams('$this->ttr_escalation_deadline$', ['this' => $oUserRequest])); + self::assertEquals('Missed by 3 min', MetaModel::ApplyParams('$this->html(ttr_escalation_deadline)$', ['this' => $oUserRequest]));*/ + + + 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)); + self::assertEquals('Missed by 3 min', $oAttDef->GetForTemplate($sValue, 'text', $oUserRequest)); + self::assertEquals($iStartDate, $oAttDef->GetForTemplate($sValue, '', $oUserRequest)); + } +} From ca2fbb943833fa09ba9f4dc6ed6df4c3db6440ea Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Fri, 6 Mar 2026 09:21:13 +0100 Subject: [PATCH 4/7] rollback changes --- .../unitary-tests/core/AttributeDefinitionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 9897fb99db..5c4e620a41 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php @@ -6,7 +6,6 @@ use AttributeDateTime; use Change; use Combodo\iTop\Test\UnitTest\ItopDataTestCase; -use DateTime; use MetaModel; use UserRequest; @@ -340,4 +339,5 @@ public function GivenAttribute(string $sHostClass, string $sAttCode, string $sAt $oAttribute->SetHostClass($sHostClass); return $oAttribute; } + } From b4bfa286ea944177667738ab80b652dbf53ce8f5 Mon Sep 17 00:00:00 2001 From: Anne-Catherine <57360138+accognet@users.noreply.github.com> Date: Mon, 9 Mar 2026 12:32:22 +0100 Subject: [PATCH 5/7] Update tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php Co-authored-by: Romain Quetiez --- .../php-unit-tests/unitary-tests/core/AttributeSubItemTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php index 4b06ad97c3..a3333a278d 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php @@ -45,7 +45,7 @@ public function testGetForTemplate() $oDateTime = new DateTime(); $oDateTime->setTimestamp($iStartDate); $sDate = $oDateTime->format(AttributeDateTime::GetFormat()); - self::assertEquals($sDate, $oAttDef->GetForTemplate($sValue, 'label', $oUserRequest)); + 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)); self::assertEquals($iStartDate, $oAttDef->GetForTemplate($sValue, '', $oUserRequest)); } From 6578868b71d34002b685bb889a344d5be5141221 Mon Sep 17 00:00:00 2001 From: Anne-Cath Date: Mon, 9 Mar 2026 13:39:33 +0100 Subject: [PATCH 6/7] remove unused comment --- .../unitary-tests/core/AttributeSubItemTest.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php index a3333a278d..9ff46cba24 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php @@ -35,12 +35,7 @@ public function testGetForTemplate() $sValue = $oUserRequest->Get('ttr_escalation_deadline'); $oAttDef = MetaModel::GetAttributeDef(get_class($oUserRequest), 'ttr_escalation_deadline'); - - /* self::assertEquals('Missed by 3 min', MetaModel::ApplyParams('$this->title$', ['this' => $oUserRequest])); - self::assertEquals('Missed by 3 min', MetaModel::ApplyParams('$this->ttr_escalation_deadline$', ['this' => $oUserRequest])); - self::assertEquals('Missed by 3 min', MetaModel::ApplyParams('$this->html(ttr_escalation_deadline)$', ['this' => $oUserRequest]));*/ - - + self::assertEquals('Missed by 3 min', $oAttDef->GetForTemplate($sValue, 'html', $oUserRequest)); $oDateTime = new DateTime(); $oDateTime->setTimestamp($iStartDate); From 4ef07d41f42b2ae0aa52f86ff51da646b9494b19 Mon Sep 17 00:00:00 2001 From: Anne-Catherine <57360138+accognet@users.noreply.github.com> Date: Mon, 9 Mar 2026 13:41:03 +0100 Subject: [PATCH 7/7] Apply suggestion from @rquetiez Co-authored-by: Romain Quetiez --- .../php-unit-tests/unitary-tests/core/AttributeSubItemTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php index 9ff46cba24..f34ae26346 100644 --- a/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php +++ b/tests/php-unit-tests/unitary-tests/core/AttributeSubItemTest.php @@ -41,7 +41,7 @@ public function testGetForTemplate() $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)); + 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)); } }