diff --git a/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php b/tests/php-unit-tests/unitary-tests/core/AttributeDefinitionTest.php index 4bfbe085a..9897fb99d 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 @@ PHP $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 000000000..4b06ad97c --- /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)); + } +}