mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 14:58:43 +02:00
N°7157 - Fix ValueSetEnum values as array must conserve keys
This commit is contained in:
@@ -527,14 +527,14 @@ class ValueSetEnum extends ValueSetDefinition
|
||||
$aValues = [];
|
||||
if (is_array($this->m_values))
|
||||
{
|
||||
foreach ($this->m_values as $value) {
|
||||
foreach ($this->m_values as $key => $value) {
|
||||
// Handle backed-enum case
|
||||
if (is_object($value) && enum_exists(get_class($value))) {
|
||||
$aValues[] = $value->value;
|
||||
$aValues[$value->value] = $value->value;
|
||||
continue;
|
||||
}
|
||||
|
||||
$aValues[] = $value;
|
||||
$aValues[$key] = $value;
|
||||
}
|
||||
}
|
||||
elseif (is_string($this->m_values) && strlen($this->m_values) > 0)
|
||||
|
||||
@@ -64,7 +64,7 @@ class ValueSetEnumTest extends ItopTestCase
|
||||
"c" => "c",
|
||||
],
|
||||
],
|
||||
"Array, already ordered" => [
|
||||
"Array without keys, already ordered" => [
|
||||
["a", "b", "c"],
|
||||
[
|
||||
0 => "a",
|
||||
@@ -72,12 +72,20 @@ class ValueSetEnumTest extends ItopTestCase
|
||||
2 => "c",
|
||||
],
|
||||
],
|
||||
"Array with keys, already ordered" => [
|
||||
["a" => "a", "b" => "b", "c" => "c"],
|
||||
[
|
||||
"a" => "a",
|
||||
"b" => "b",
|
||||
"c" => "c",
|
||||
],
|
||||
],
|
||||
"Backed-Enum" => [
|
||||
ABCEnum::class,
|
||||
[
|
||||
0 => "a",
|
||||
1 => "b",
|
||||
2 => "c",
|
||||
"a" => "a",
|
||||
"b" => "b",
|
||||
"c" => "c",
|
||||
],
|
||||
true, // Is the input value a backed enum?
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user