mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°931: TagSet search (manage undefined values) unit tests
This commit is contained in:
@@ -578,6 +578,7 @@ class BinaryExpression extends Expression
|
||||
* @param null $oAttDef
|
||||
*
|
||||
* @return array
|
||||
* @throws \MissingQueryArgument
|
||||
*/
|
||||
public function GetCriterion($oSearch, &$aArgs = null, $bRetrofitParams = false, $oAttDef = null)
|
||||
{
|
||||
@@ -676,6 +677,10 @@ class BinaryExpression extends Expression
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($aCriteriaLeft['widget']) && isset($aCriteriaRight['widget']) && ($aCriteriaLeft['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET) && ($aCriteriaRight['widget'] == AttributeDefinition::SEARCH_WIDGET_TYPE_TAG_SET))
|
||||
{
|
||||
$aCriteriaOverride['operator'] = 'MATCHES';
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($aCriteriaLeft, $aCriteriaRight, $aCriteriaOverride);
|
||||
@@ -886,20 +891,20 @@ class ScalarExpression extends UnaryExpression
|
||||
|
||||
public function GetCriterion($oSearch, &$aArgs = null, $bRetrofitParams = false, $oAttDef = null)
|
||||
{
|
||||
$aCriteria = array();
|
||||
$aCriterion = array();
|
||||
switch ((string)($this->m_value))
|
||||
{
|
||||
case '%Y-%m-%d':
|
||||
$aCriteria['unit'] = 'DAY';
|
||||
$aCriterion['unit'] = 'DAY';
|
||||
break;
|
||||
case '%Y-%m':
|
||||
$aCriteria['unit'] = 'MONTH';
|
||||
$aCriterion['unit'] = 'MONTH';
|
||||
break;
|
||||
case '%w':
|
||||
$aCriteria['unit'] = 'WEEKDAY';
|
||||
$aCriterion['unit'] = 'WEEKDAY';
|
||||
break;
|
||||
case '%H':
|
||||
$aCriteria['unit'] = 'HOUR';
|
||||
$aCriterion['unit'] = 'HOUR';
|
||||
break;
|
||||
default:
|
||||
$aValue = array();
|
||||
@@ -938,7 +943,7 @@ class ScalarExpression extends UnaryExpression
|
||||
}
|
||||
else
|
||||
{
|
||||
$aValue['label'] = Dict::S('Enum:Undefined');
|
||||
$aCriterion['has_undefined'] = true;
|
||||
}
|
||||
}
|
||||
catch (Exception $e)
|
||||
@@ -981,12 +986,12 @@ class ScalarExpression extends UnaryExpression
|
||||
{
|
||||
// only if a label is found
|
||||
$aValue['value'] = $this->GetValue();
|
||||
$aCriteria['values'] = array($aValue);
|
||||
$aCriterion['values'] = array($aValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
$aCriteria['oql'] = $this->RenderExpression(false, $aArgs, $bRetrofitParams);
|
||||
return $aCriteria;
|
||||
$aCriterion['oql'] = $this->RenderExpression(false, $aArgs, $bRetrofitParams);
|
||||
return $aCriterion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ $(function()
|
||||
'empty': null, // Remove as it will be handle by the "null" value in the "MATCHES" operator
|
||||
'not_empty': null, // Remove as it will be handle by the "null" value in the "MATCHES" operator
|
||||
},
|
||||
// Null value
|
||||
'null_value': {
|
||||
'code': '',
|
||||
'label': Dict.S('Enum:Undefined'),
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
|
||||
@@ -157,8 +157,7 @@ class CriterionToOQL extends CriterionConversionAbstract
|
||||
{
|
||||
$aValues = self::GetValues($aCriteria);
|
||||
$sValue = self::GetValue($aValues, 0);
|
||||
|
||||
if (empty($sValue))
|
||||
if (empty($sValue) && (!(isset($aCriteria['has_undefined'])) || !($aCriteria['has_undefined'])))
|
||||
{
|
||||
return "1";
|
||||
}
|
||||
@@ -183,17 +182,34 @@ class CriterionToOQL extends CriterionConversionAbstract
|
||||
{
|
||||
$aValues = self::GetValues($aCriteria);
|
||||
$aRawValues = array();
|
||||
$bHasUnDefined = isset($aCriteria['has_undefined']) ? $aCriteria['has_undefined'] : false;
|
||||
for($i = 0; $i < count($aValues); $i++)
|
||||
{
|
||||
$aRawValues[] = self::GetValue($aValues, $i);
|
||||
$sRawValue = self::GetValue($aValues, $i);
|
||||
if (strlen($sRawValue) == 0)
|
||||
{
|
||||
$bHasUnDefined = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aRawValues[] = $sRawValue;
|
||||
}
|
||||
}
|
||||
$sValue = implode(' ', $aRawValues);
|
||||
|
||||
if (empty($sValue))
|
||||
{
|
||||
if ($bHasUnDefined)
|
||||
{
|
||||
return "({$sRef} = '')";
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
|
||||
if ($bHasUnDefined)
|
||||
{
|
||||
return "((({$sRef} MATCHES '{$sValue}') OR ({$sRef} = '')) AND 1)";
|
||||
}
|
||||
return "({$sRef} MATCHES '{$sValue}')";
|
||||
}
|
||||
|
||||
|
||||
@@ -674,8 +674,18 @@ class CriterionToSearchForm extends CriterionConversionAbstract
|
||||
{
|
||||
case 'MATCHES':
|
||||
// Nothing special to do
|
||||
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
|
||||
{
|
||||
if (!isset($aCriteria['values']))
|
||||
{
|
||||
$aCriteria['values'] = array();
|
||||
}
|
||||
// Convention for 'undefined' tag set
|
||||
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'OR':
|
||||
case 'ISNULL':
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS;
|
||||
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
|
||||
@@ -684,8 +694,21 @@ class CriterionToSearchForm extends CriterionConversionAbstract
|
||||
{
|
||||
$aCriteria['values'] = array();
|
||||
}
|
||||
// Convention for 'undefined' enums
|
||||
$aCriteria['values'][] = array('value' => 'null', 'label' => Dict::S('Enum:Undefined'));
|
||||
// Convention for 'undefined' tag set
|
||||
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
|
||||
}
|
||||
break;
|
||||
|
||||
case '=':
|
||||
$aCriteria['operator'] = CriterionConversionAbstract::OP_EQUALS;
|
||||
if (isset($aCriteria['has_undefined']) && $aCriteria['has_undefined'])
|
||||
{
|
||||
if (!isset($aCriteria['values']))
|
||||
{
|
||||
$aCriteria['values'] = array();
|
||||
}
|
||||
// Convention for 'undefined' tag set
|
||||
$aCriteria['values'][] = array('value' => '', 'label' => Dict::S('Enum:Undefined'));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -468,7 +468,16 @@ class CriterionConversionTest extends ItopDataTestCase
|
||||
'ExpectedOQL' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE `UserRequest`.`tagfield` MATCHES 'tag1 tag2'",
|
||||
'ExpectedCriterion' => array(array('widget' => 'tag_set')),
|
||||
),
|
||||
|
||||
'TagSet Undefined' => array(
|
||||
'OQL' => "SELECT UserRequest WHERE tagfield = ''",
|
||||
'ExpectedOQL' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE (`UserRequest`.`tagfield` = '')",
|
||||
'ExpectedCriterion' => array(array('widget' => 'tag_set')),
|
||||
),
|
||||
'TagSet Undefined and tag' => array(
|
||||
'OQL' => "SELECT UserRequest WHERE (((tagfield MATCHES 'tag1 tag2') OR (tagfield = '')) AND 1)",
|
||||
'ExpectedOQL' => "SELECT `UserRequest` FROM UserRequest AS `UserRequest` WHERE ((`UserRequest`.`tagfield` MATCHES 'tag1 tag2' OR (`UserRequest`.`tagfield` = '')) AND 1)",
|
||||
'ExpectedCriterion' => array(array('widget' => 'tag_set')),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user