diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index fe67e6802a..4ca1718d05 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -218,7 +218,10 @@ class Item extends Model */ private function extractLabel(array $data) { - return static::notEmptyStringOr($data['label'], null); + return static::notEmptyStringOr( + static::issetInArray($data, ['label']), + null + ); } diff --git a/pandora_console/include/rest-api/models/VisualConsole/items/Group.php b/pandora_console/include/rest-api/models/VisualConsole/items/Group.php index ef7817347e..31d2dddd95 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/items/Group.php +++ b/pandora_console/include/rest-api/models/VisualConsole/items/Group.php @@ -70,9 +70,9 @@ final class Group extends Item { $groupId = Model::parseIntOr( Model::issetInArray($data, ['groupId', 'id_group']), - 0 + -1 ); - if ($groupId === null) { + if ($groupId < 0) { throw new \InvalidArgumentException( 'the group Id property is required and should be integer' ); diff --git a/pandora_console/tests/Functional/Models/VisualConsole/items/GroupTest.php b/pandora_console/tests/Functional/Models/VisualConsole/items/GroupTest.php index 19f29a0894..3d6d937beb 100644 --- a/pandora_console/tests/Functional/Models/VisualConsole/items/GroupTest.php +++ b/pandora_console/tests/Functional/Models/VisualConsole/items/GroupTest.php @@ -62,7 +62,7 @@ class GroupTest extends TestCase 'x' => -666, 'y' => 76, 'imageSrc' => '', - 'id_group' => 0, + 'groupId' => 0, ] ); // Missing imageSrc. @@ -79,7 +79,7 @@ class GroupTest extends TestCase 'height' => '0', 'x' => -666, 'y' => 76, - 'id_group' => 0, + 'id_group' => 11, ] ); } @@ -129,15 +129,22 @@ class GroupTest extends TestCase public function testContainerIsRepresentedAsJson(): void { $this->assertEquals( - '{"id":1,"type"11,"label":null,"labelPosition":"down","isLinkEnabled":false,"isOnTop":false,"parentId":null,"aclGroupId":null,"width":0,"height":0,"x":0,"y":0,"imageSrc":"image.jpg","groupId":0}', + '{"id":7,"type":11,"label":null,"labelPosition":"up","isLinkEnabled":true,"isOnTop":false,"parentId":null,"aclGroupId":null,"width":0,"height":0,"x":-666,"y":76,"imageSrc":"image.jpg","groupId":12}', Group::fromArray( [ - 'id' => 1, - 'type' => GROUP_ITEM, - 'width' => '0', - 'height' => '0', - 'imageSrc' => 'image.jpg', - 'groupId' => 0, + 'id' => 7, + 'type' => GROUP_ITEM, + 'label' => null, + 'labelPosition' => 'up', + 'isLinkEnabled' => true, + 'isOnTop' => false, + 'parentId' => null, + 'width' => '0', + 'height' => '0', + 'x' => -666, + 'y' => 76, + 'imageSrc' => 'image.jpg', + 'groupId' => 12, ] ) );