Fixed Group class (VisualConsole)

Former-commit-id: 6a241cdc76935f92f99b9cc31b66acd3082571ca
This commit is contained in:
Daniel Maya 2019-03-26 09:48:50 +01:00
parent 205c95bcb8
commit 7d66d0b0fe
3 changed files with 22 additions and 12 deletions

View File

@ -218,7 +218,10 @@ class Item extends Model
*/ */
private function extractLabel(array $data) private function extractLabel(array $data)
{ {
return static::notEmptyStringOr($data['label'], null); return static::notEmptyStringOr(
static::issetInArray($data, ['label']),
null
);
} }

View File

@ -71,9 +71,9 @@ final class Group extends Item
{ {
$groupId = Model::parseIntOr( $groupId = Model::parseIntOr(
Model::issetInArray($data, ['groupId', 'id_group']), Model::issetInArray($data, ['groupId', 'id_group']),
0 -1
); );
if ($groupId === null) { if ($groupId < 0) {
throw new \InvalidArgumentException( throw new \InvalidArgumentException(
'the group Id property is required and should be integer' 'the group Id property is required and should be integer'
); );

View File

@ -62,7 +62,7 @@ class GroupTest extends TestCase
'x' => -666, 'x' => -666,
'y' => 76, 'y' => 76,
'imageSrc' => '', 'imageSrc' => '',
'id_group' => 0, 'groupId' => 0,
] ]
); );
// Missing imageSrc. // Missing imageSrc.
@ -79,7 +79,7 @@ class GroupTest extends TestCase
'height' => '0', 'height' => '0',
'x' => -666, 'x' => -666,
'y' => 76, 'y' => 76,
'id_group' => 0, 'id_group' => 11,
] ]
); );
} }
@ -129,15 +129,22 @@ class GroupTest extends TestCase
public function testContainerIsRepresentedAsJson(): void public function testContainerIsRepresentedAsJson(): void
{ {
$this->assertEquals( $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( Group::fromArray(
[ [
'id' => 1, 'id' => 7,
'type' => GROUP_ITEM, 'type' => GROUP_ITEM,
'width' => '0', 'label' => null,
'height' => '0', 'labelPosition' => 'up',
'imageSrc' => 'image.jpg', 'isLinkEnabled' => true,
'groupId' => 0, 'isOnTop' => false,
'parentId' => null,
'width' => '0',
'height' => '0',
'x' => -666,
'y' => 76,
'imageSrc' => 'image.jpg',
'groupId' => 12,
] ]
) )
); );