mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
✅ Fix DBObject::EvaluateExpression() tests
This commit is contained in:
@@ -5548,30 +5548,31 @@ abstract class DBObject implements iDisplay
|
||||
{
|
||||
$aFields = $oExpression->ListRequiredFields();
|
||||
$aArgs = array();
|
||||
foreach ($aFields as $sFieldDesc)
|
||||
{
|
||||
foreach ($aFields as $sFieldDesc) {
|
||||
$aFieldParts = explode('.', $sFieldDesc);
|
||||
if (count($aFieldParts) == 2)
|
||||
{
|
||||
if (count($aFieldParts) == 2) {
|
||||
$sClass = $aFieldParts[0];
|
||||
$sAttCode = $aFieldParts[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$sClass = get_class($this);
|
||||
$sAttCode = $aFieldParts[0];
|
||||
}
|
||||
if (get_class($this) != $sClass) continue;
|
||||
if (!MetaModel::IsValidAttCode(get_class($this), $sAttCode)) continue;
|
||||
if (get_class($this) != $sClass) {
|
||||
continue;
|
||||
}
|
||||
if (!MetaModel::IsValidAttCode(get_class($this), $sAttCode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
|
||||
$aSQLValues = $oAttDef->GetSQLValues($this->m_aCurrValues[$sAttCode]);
|
||||
$value = reset($aSQLValues);
|
||||
if ($oAttDef->IsNull($value)) {
|
||||
$value = '';
|
||||
return '';
|
||||
}
|
||||
$aArgs[$sFieldDesc] = $value;
|
||||
}
|
||||
|
||||
return $oExpression->Evaluate($aArgs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,28 @@ class DBObjectTest extends ItopDataTestCase
|
||||
static::assertEquals('Romain Duris', $oObject->Get('friendlyname'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::NewObject
|
||||
* @covers DBObject::Get
|
||||
*/
|
||||
public function testPartialAttributeEvaluation()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'org_id' => 3, 'location_id' => 2));
|
||||
|
||||
static::assertEquals('', $oObject->Get('friendlyname'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::NewObject
|
||||
* @covers DBObject::Get
|
||||
*/
|
||||
public function testEmptyAttributeEvaluation()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('org_id' => 3, 'location_id' => 2));
|
||||
|
||||
static::assertEquals('', $oObject->Get('friendlyname'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::Get
|
||||
* @covers DBObject::Set
|
||||
|
||||
@@ -295,10 +295,15 @@ class ExpressionEvaluateTest extends iTopDataTestCase
|
||||
|
||||
public function ExpressionsWithObjectFieldsProvider()
|
||||
{
|
||||
return array(
|
||||
array('Location', array('name' => 'Grenoble', 'org_id' => 2), 'org_id', 2),
|
||||
array('Location', array('name' => 'Grenoble', 'org_id' => 2), 'CONCAT(SUBSTR(name, 4), " cause")', 'noble cause'),
|
||||
);
|
||||
return [
|
||||
['URP_UserProfile', ['profileid' => 2], 'friendlyname', ''],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'name', 'Grenoble'],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'friendlyname', ''],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'org_name', ''],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'org_id_friendlyname', ''],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'org_id', 2],
|
||||
['Location', ['name' => 'Grenoble', 'org_id' => 2], 'CONCAT(SUBSTR(name, 4), " cause")', 'noble cause'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user