mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 09:08:42 +02:00
N°3171 - Friendly name and obsolescence flag not refreshed (#151)
- Compute any type of expression on server side - Recompute friendly name and obsolescence flag on server side (DBOBject) - Bonus : compute dependency for external keys
This commit is contained in:
@@ -48,6 +48,7 @@ class DBObjectTest extends ItopDataTestCase
|
||||
|
||||
/**
|
||||
* Test default page name
|
||||
* @covers DBObject::GetUIPage
|
||||
*/
|
||||
public function testGetUIPage()
|
||||
{
|
||||
@@ -81,6 +82,9 @@ class DBObjectTest extends ItopDataTestCase
|
||||
array('PHP_INT_MIN', false));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::GetOriginal
|
||||
*/
|
||||
public function testGetOriginal()
|
||||
{
|
||||
$oObject = $this->CreateUserRequest(190664);
|
||||
@@ -88,4 +92,114 @@ class DBObjectTest extends ItopDataTestCase
|
||||
static::assertNull($oObject->GetOriginal('sla_tto_passed'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::NewObject
|
||||
* @covers DBObject::Get
|
||||
* @covers DBObject::Set
|
||||
*/
|
||||
public function testAttributeRefresh_FriendlyName()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
||||
|
||||
static::assertEquals('John Foo', $oObject->Get('friendlyname'));
|
||||
$oObject->Set('name', 'Who');
|
||||
static::assertEquals('John Who', $oObject->Get('friendlyname'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers MetaModel::GetObject
|
||||
* @covers DBObject::Get
|
||||
* @covers DBObject::Set
|
||||
*/
|
||||
public function testAttributeRefresh_FriendlyNameFromDB()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Gary', 'first_name' => 'Romain', 'org_id' => 3, 'location_id' => 2));
|
||||
$oObject->DBInsert();
|
||||
$iObjKey = $oObject->GetKey();
|
||||
|
||||
$oObject = \MetaModel::GetObject('Person', $iObjKey);
|
||||
|
||||
static::assertEquals('Romain Gary', $oObject->Get('friendlyname'));
|
||||
$oObject->Set('name', 'Duris');
|
||||
static::assertEquals('Romain Duris', $oObject->Get('friendlyname'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::NewObject
|
||||
* @covers DBObject::Get
|
||||
* @covers DBObject::Set
|
||||
*/
|
||||
public function testAttributeRefresh_ObsolescenceFlag()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
||||
|
||||
static::assertEquals(false, (bool)$oObject->Get('obsolescence_flag'));
|
||||
$oObject->Set('status', 'inactive');
|
||||
static::assertEquals(true, (bool)$oObject->Get('obsolescence_flag'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers DBObject::NewObject
|
||||
* @covers DBObject::Get
|
||||
* @covers DBObject::Set
|
||||
*/
|
||||
public function testAttributeRefresh_ExternalKeysAndFields()
|
||||
{
|
||||
static::assertDBQueryCount(0, function() use (&$oObject){
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
||||
});
|
||||
static::assertDBQueryCount(2, function() use (&$oObject){
|
||||
static::assertEquals('Demo', $oObject->Get('org_id_friendlyname'));
|
||||
static::assertEquals('Grenoble', $oObject->Get('location_id_friendlyname'));
|
||||
});
|
||||
|
||||
// External key given as an id
|
||||
static::assertDBQueryCount(1, function() use (&$oObject){
|
||||
$oObject->Set('org_id', 2);
|
||||
static::assertEquals('IT Department', $oObject->Get('org_id_friendlyname'));
|
||||
});
|
||||
|
||||
// External key given as an object
|
||||
static::assertDBQueryCount(1, function() use (&$oBordeaux){
|
||||
$oBordeaux = \MetaModel::GetObject('Location', 1);
|
||||
});
|
||||
|
||||
static::assertDBQueryCount(0, function() use (&$oBordeaux, &$oObject){
|
||||
$oObject->Set('location_id', $oBordeaux);
|
||||
static::assertEquals('IT Department', $oObject->Get('org_id_friendlyname'));
|
||||
static::assertEquals('IT Department', $oObject->Get('org_name'));
|
||||
static::assertEquals('Bordeaux', $oObject->Get('location_id_friendlyname'));
|
||||
});
|
||||
}
|
||||
|
||||
public function testSetExtKeyUnsetDependentAttribute()
|
||||
{
|
||||
$oObject = \MetaModel::NewObject('Person', array('name' => 'Foo', 'first_name' => 'John', 'org_id' => 3, 'location_id' => 2));
|
||||
$oOrg = \MetaModel::GetObject('Organization', 2);
|
||||
$oObject->Set('org_id', $oOrg);
|
||||
static::assertEquals(0, $oObject->Get('location_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Integration
|
||||
*/
|
||||
public function testModelExpressions()
|
||||
{
|
||||
foreach (\MetaModel::GetClasses() as $sClass)
|
||||
{
|
||||
if (\MetaModel::IsAbstract($sClass)) continue;
|
||||
|
||||
$oObject = \MetaModel::NewObject($sClass);
|
||||
foreach (\MetaModel::ListAttributeDefs($sClass) as $sAttCode => $oAttDef)
|
||||
{
|
||||
if ($oAttDef->IsBasedOnOQLExpression())
|
||||
{
|
||||
$this->debug("$sClass::$sAttCode");
|
||||
static::assertDBQueryCount(0, function() use (&$oObject, &$oAttDef){
|
||||
$oObject->EvaluateExpression($oAttDef->GetOQLExpression());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user