mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
✅ Make sure that tests use valid input data
This commit is contained in:
@@ -22,6 +22,12 @@ class QueryBuilderExpressionsTest extends \Combodo\iTop\Test\UnitTest\ItopCustom
|
|||||||
'description' => 'Tag known as "A"'
|
'description' => 'Tag known as "A"'
|
||||||
]);
|
]);
|
||||||
$oTagA->DBInsert();
|
$oTagA->DBInsert();
|
||||||
|
$oTagB = \MetaModel::NewObject(\TagSetFieldData::GetTagDataClassName('TestObject', 'tagset'), [
|
||||||
|
'code' => 'tagB',
|
||||||
|
'label' => 'Tag B',
|
||||||
|
'description' => 'Tag known as "B"'
|
||||||
|
]);
|
||||||
|
$oTagB->DBInsert();
|
||||||
|
|
||||||
$sTargetClass = 'TestObject';
|
$sTargetClass = 'TestObject';
|
||||||
$aValues = [
|
$aValues = [
|
||||||
@@ -82,7 +88,7 @@ class QueryBuilderExpressionsTest extends \Combodo\iTop\Test\UnitTest\ItopCustom
|
|||||||
'type' => 'php:string',
|
'type' => 'php:string',
|
||||||
],
|
],
|
||||||
'enumset' => [
|
'enumset' => [
|
||||||
'value' => 'low|high',
|
'value' => 'low,high',
|
||||||
'type' => 'php:string',
|
'type' => 'php:string',
|
||||||
],
|
],
|
||||||
'file' => [
|
'file' => [
|
||||||
@@ -122,7 +128,7 @@ class QueryBuilderExpressionsTest extends \Combodo\iTop\Test\UnitTest\ItopCustom
|
|||||||
'type' => 'ormStopWatch',
|
'type' => 'ormStopWatch',
|
||||||
],
|
],
|
||||||
'tagset' => [
|
'tagset' => [
|
||||||
'value' => 'tagA',
|
'value' => 'tagA tagB',
|
||||||
'type' => 'php:string',
|
'type' => 'php:string',
|
||||||
],
|
],
|
||||||
'text' => [
|
'text' => [
|
||||||
@@ -149,16 +155,16 @@ class QueryBuilderExpressionsTest extends \Combodo\iTop\Test\UnitTest\ItopCustom
|
|||||||
|
|
||||||
$aValuesToSet = [];
|
$aValuesToSet = [];
|
||||||
foreach ($aValues as $sAttCode => $aValueData) {
|
foreach ($aValues as $sAttCode => $aValueData) {
|
||||||
|
$oAttDef = \MetaModel::GetAttributeDef($sTargetClass, $sAttCode);
|
||||||
if (substr($aValueData['type'], 0, 4) == 'php:') {
|
if (substr($aValueData['type'], 0, 4) == 'php:') {
|
||||||
$aValuesToSet[$sAttCode] = $aValueData['value'];
|
$aValuesToSet[$sAttCode] = $aValueData['value'];
|
||||||
} else {
|
} else {
|
||||||
$oAttDef = \MetaModel::GetAttributeDef($sTargetClass, $sAttCode);
|
|
||||||
$oJSONObject = is_null($aValueData['value']) ? null : json_decode($aValueData['value'], false);
|
$oJSONObject = is_null($aValueData['value']) ? null : json_decode($aValueData['value'], false);
|
||||||
$aValuesToSet[$sAttCode] = $oAttDef->FromJSONToValue($oJSONObject);
|
$aValuesToSet[$sAttCode] = $oAttDef->FromJSONToValue($oJSONObject);
|
||||||
}
|
}
|
||||||
|
static::assertTrue((bool) $oAttDef->CheckFormat($aValuesToSet[$sAttCode]), "Given test value of attribute '$sAttCode' is not valid: {$aValueData['value']}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Test that I can write without any error (such as malformed SQL query, that would throw an exception)
|
// Test that I can write without any error (such as malformed SQL query, that would throw an exception)
|
||||||
$oObject = \MetaModel::NewObject($sTargetClass, $aValuesToSet);
|
$oObject = \MetaModel::NewObject($sTargetClass, $aValuesToSet);
|
||||||
$oObject->DBInsert();
|
$oObject->DBInsert();
|
||||||
|
|||||||
Reference in New Issue
Block a user