mirror of
https://github.com/Combodo/iTop.git
synced 2026-07-13 18:26:39 +02:00
Move TrimValue() base definition to AttributeDefinition class, assign DBObject::SetTrim old behavior to it
This commit is contained in:
@@ -897,6 +897,26 @@ abstract class AttributeDefinition
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to set a value that fits the attribute max size
|
||||
*
|
||||
* Default behavior is what DBObject::SetTrim used to do, now delegated to AttributeDefinition
|
||||
*
|
||||
* @param string $sValue
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0 N°9643
|
||||
*/
|
||||
public function TrimValue(string $sValue)
|
||||
{
|
||||
$iMaxSize = $this->GetMaxSize();
|
||||
if ($iMaxSize && (strlen($sValue) > $iMaxSize))
|
||||
{
|
||||
$sValue = substr($sValue, 0, $iMaxSize);
|
||||
}
|
||||
return $sValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed|null
|
||||
* @deprecated never used
|
||||
|
||||
@@ -1387,6 +1387,17 @@ class DBObjectTest extends ItopDataTestCase
|
||||
$this->assertEquals($sResult, $oOrganisation->Get('name'), 'SetTrim must limit string to 255 characters');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::SetTrim
|
||||
*/
|
||||
public function testSetTrimOnNonStringAttributeDoesNotTrim()
|
||||
{
|
||||
$oTicket = MetaModel::NewObject(UserRequest::class);
|
||||
$oTicket->SetTrim('caller_id', '15');
|
||||
|
||||
$this->assertEquals(15, $oTicket->Get('caller_id'), 'SetTrim should keep non-string attributes untouched before regular Set conversion');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::SetComputedDate
|
||||
* @return void
|
||||
|
||||
Reference in New Issue
Block a user