Visual Console Refactor: the model's JSON representation is now sorted alphabetically

Added the linked visual console capabilities to the Icon item


Former-commit-id: acda22da54a259404f201190af9e481262ddde03
This commit is contained in:
Alejandro Gallardo Escobar 2019-03-26 11:45:50 +01:00
parent 1517ec8d3c
commit ef1a1f1057
8 changed files with 231 additions and 24 deletions

View File

@ -57,6 +57,8 @@ abstract class Model
{
$this->validateData($unknownData);
$this->data = $this->decode($unknownData);
// Sort alphabetically.
ksort($this->data);
}

View File

@ -11,6 +11,14 @@ use Models\VisualConsole\Item;
final class Icon extends Item
{
/**
* Used to enable the fetching, validation and extraction of information
* about the linked visual console.
*
* @var boolean
*/
protected static $useLinkedVisualConsole = true;
/**
* Returns a valid representation of the model.

View File

@ -6,12 +6,17 @@ use PHPUnit\Framework\TestCase;
use Models\VisualConsole\Container as VisualConsole;
/**
* Test class
* Test for the Visual Console Container.
*/
class ContainerTest extends TestCase
{
/**
* Test if the instance is created using a valid data structure.
*
* @return void
*/
public function testCanBeCreatedFromValidUserStructure(): void
{
$this->assertInstanceOf(
@ -60,6 +65,11 @@ class ContainerTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid id.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidId(): void
{
$this->expectException(InvalidArgumentException::class);
@ -86,6 +96,11 @@ class ContainerTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid name.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidName(): void
{
$this->expectException(InvalidArgumentException::class);
@ -111,10 +126,15 @@ class ContainerTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid group id.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidGroupId(): void
{
$this->expectException(InvalidArgumentException::class);
// invalid group id.
// Invalid group id.
VisualConsole::fromArray(
[
'id' => 1,
@ -137,10 +157,15 @@ class ContainerTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid width.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidWidth(): void
{
$this->expectException(InvalidArgumentException::class);
// invalid width.
// Invalid width.
VisualConsole::fromArray(
[
'id' => 1,
@ -163,10 +188,15 @@ class ContainerTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid height.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidHeigth(): void
{
$this->expectException(InvalidArgumentException::class);
// invalid height.
// Invalid height.
VisualConsole::fromArray(
[
'id' => 1,
@ -189,11 +219,16 @@ class ContainerTest extends TestCase
}
/**
* Test if the model has a valid JSON representation.
*
* @return void
*/
public function testContainerIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"id":1,"name":"foo","groupId":0,"backgroundURL":null,"backgroundColor":null,"isFavorite":false,"width":1024,"height":768}',
VisualConsole::fromArray(
'{"backgroundColor":null,"backgroundURL":null,"groupId":0,"height":768,"id":1,"isFavorite":false,"name":"foo","width":1024}',
(string) VisualConsole::fromArray(
[
'id' => 1,
'name' => 'foo',

View File

@ -237,8 +237,8 @@ class ItemTest extends TestCase
public function testItemIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"id":15,"type":3,"label":"test","labelPosition":"down","isLinkEnabled":false,"isOnTop":true,"parentId":0,"aclGroupId":12,"width":800,"height":600,"x":0,"y":0}',
ItemConsole::fromArray(
'{"aclGroupId":12,"height":600,"id":15,"isLinkEnabled":false,"isOnTop":true,"label":"test","labelPosition":"down","parentId":0,"type":3,"width":800,"x":0,"y":0}',
(string) ItemConsole::fromArray(
[
'id' => 15,
'type' => 3,
@ -257,8 +257,8 @@ class ItemTest extends TestCase
);
$this->assertEquals(
'{"id":15,"type":3,"label":null,"labelPosition":"down","isLinkEnabled":false,"isOnTop":false,"parentId":0,"aclGroupId":12,"width":800,"height":600,"x":0,"y":0}',
ItemConsole::fromArray(
'{"aclGroupId":12,"height":600,"id":15,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","parentId":0,"type":3,"width":800,"x":0,"y":0}',
(string) ItemConsole::fromArray(
[
'id' => 15,
'type' => 3,
@ -275,8 +275,8 @@ class ItemTest extends TestCase
);
$this->assertEquals(
'{"id":69,"type":20,"label":null,"labelPosition":"up","isLinkEnabled":true,"isOnTop":false,"parentId":null,"aclGroupId":null,"width":0,"height":0,"x":-666,"y":76}',
ItemConsole::fromArray(
'{"aclGroupId":null,"height":0,"id":69,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","parentId":null,"type":20,"width":0,"x":-666,"y":76}',
(string) ItemConsole::fromArray(
[
'id' => 69,
'type' => 20,

View File

@ -6,12 +6,17 @@ use PHPUnit\Framework\TestCase;
use Models\VisualConsole\Items\Box;
/**
* Test class
* Test for the Visual Console Box Item model.
*/
class BoxTest extends TestCase
{
/**
* Test if the instance is created using a valid data structure.
*
* @return void
*/
public function testCanBeCreatedFromValidUserStructure(): void
{
$this->assertInstanceOf(
@ -48,11 +53,16 @@ class BoxTest extends TestCase
}
/**
* Test if the model has a valid JSON representation.
*
* @return void
*/
public function testContainerIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"id":7,"type":12,"label":null,"labelPosition":"up","isLinkEnabled":true,"isOnTop":false,"parentId":null,"aclGroupId":null,"width":0,"height":0,"x":-666,"y":76,"borderWidth":0,"borderColor":null,"fillColor":null}',
Box::fromArray(
'{"aclGroupId":null,"borderColor":null,"borderWidth":0,"fillColor":null,"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","parentId":null,"type":12,"width":0,"x":-666,"y":76}',
(string) Box::fromArray(
[
'id' => 7,
'type' => 10,

View File

@ -6,12 +6,17 @@ use PHPUnit\Framework\TestCase;
use Models\VisualConsole\Items\Group;
/**
* Test class
* Test for the Visual Console Box Group Item model.
*/
class GroupTest extends TestCase
{
/**
* Test if the instance is created using a valid data structure.
*
* @return void
*/
public function testCanBeCreatedFromValidUserStructure(): void
{
$this->assertInstanceOf(
@ -44,6 +49,11 @@ class GroupTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid image src.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidImageSrc(): void
{
$this->expectException(InvalidArgumentException::class);
@ -85,6 +95,11 @@ class GroupTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid group Id.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidGroupId(): void
{
$this->expectException(InvalidArgumentException::class);
@ -126,11 +141,16 @@ class GroupTest extends TestCase
}
/**
* Test if the model has a valid JSON representation.
*
* @return void
*/
public function testContainerIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"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(
'{"aclGroupId":null,"groupId":12,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","parentId":null,"type":11,"width":0,"x":-666,"y":76}',
(string) Group::fromArray(
[
'id' => 7,
'type' => GROUP_ITEM,

View File

@ -6,12 +6,17 @@ use PHPUnit\Framework\TestCase;
use Models\VisualConsole\Items\Icon;
/**
* Test class
* Test for the Visual Console Box Icon Item model.
*/
class IconTest extends TestCase
{
/**
* Test if the instance is created using a valid data structure.
*
* @return void
*/
public function testCanBeCreatedFromValidUserStructure(): void
{
$this->assertInstanceOf(
@ -29,6 +34,11 @@ class IconTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid image src.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidImageSrc(): void
{
$this->expectException(InvalidArgumentException::class);
@ -68,11 +78,16 @@ class IconTest extends TestCase
}
/**
* Test if the model has a valid JSON representation.
*
* @return void
*/
public function testContainerIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"id":7,"type":5,"label":null,"labelPosition":"up","isLinkEnabled":true,"isOnTop":false,"parentId":null,"aclGroupId":null,"width":0,"height":0,"x":-666,"y":76,"imageSrc":"image.jpg"}',
Icon::fromArray(
'{"aclGroupId":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","parentId":null,"type":5,"width":0,"x":-666,"y":76}',
(string) Icon::fromArray(
[
'id' => 7,
'type' => ICON,
@ -89,6 +104,103 @@ class IconTest extends TestCase
]
)
);
// With a linked layout.
$this->assertEquals(
'{"aclGroupId":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","parentId":null,"type":5,"width":0,"x":-666,"y":76}',
(string) Icon::fromArray(
[
'id' => 7,
'type' => ICON,
'label' => null,
'labelPosition' => 'up',
'isLinkEnabled' => true,
'isOnTop' => false,
'parentId' => null,
'width' => '0',
'height' => '0',
'x' => -666,
'y' => 76,
'imageSrc' => 'image.jpg',
'id_layout_linked' => 1,
]
)
);
$this->assertEquals(
'{"aclGroupId":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","metaconsoleId":5,"parentId":null,"type":5,"width":0,"x":-666,"y":76}',
(string) Icon::fromArray(
[
'id' => 7,
'type' => ICON,
'label' => null,
'labelPosition' => 'up',
'isLinkEnabled' => true,
'isOnTop' => false,
'parentId' => null,
'width' => '0',
'height' => '0',
'x' => -666,
'y' => 76,
'imageSrc' => 'image.jpg',
'id_metaconsole' => 5,
'linked_layout_node_id' => 3,
'linkedLayoutId' => 2,
]
)
);
$this->assertEquals(
'{"aclGroupId":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"weight","linkedLayoutStatusTypeWeight":80,"metaconsoleId":5,"parentId":null,"type":5,"width":0,"x":-666,"y":76}',
(string) Icon::fromArray(
[
'id' => 7,
'type' => ICON,
'label' => null,
'labelPosition' => 'up',
'isLinkEnabled' => true,
'isOnTop' => false,
'parentId' => null,
'width' => '0',
'height' => '0',
'x' => -666,
'y' => 76,
'imageSrc' => 'image.jpg',
'id_metaconsole' => 5,
'linked_layout_node_id' => 3,
'linkedLayoutId' => 2,
'linkedLayoutStatusType' => 'weight',
'linkedLayoutStatusTypeWeight' => 80,
]
)
);
$this->assertEquals(
'{"aclGroupId":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"service","linkedLayoutStatusTypeCriticalThreshold":80,"linkedLayoutStatusTypeWarningThreshold":50,"metaconsoleId":5,"parentId":null,"type":5,"width":0,"x":-666,"y":76}',
(string) Icon::fromArray(
[
'id' => 7,
'type' => ICON,
'label' => null,
'labelPosition' => 'up',
'isLinkEnabled' => true,
'isOnTop' => false,
'parentId' => null,
'width' => '0',
'height' => '0',
'x' => -666,
'y' => 76,
'imageSrc' => 'image.jpg',
'id_metaconsole' => 5,
'linked_layout_node_id' => 3,
'linkedLayoutId' => 2,
'linked_layout_status_type' => 'service',
'linkedLayoutStatusTypeWarningThreshold' => 50,
'linked_layout_status_as_service_critical' => 80,
]
)
);
}

View File

@ -6,12 +6,17 @@ use PHPUnit\Framework\TestCase;
use Models\VisualConsole\Items\Line;
/**
* Test class
* Test for the Visual Console Box Icon Item model.
*/
class LineTest extends TestCase
{
/**
* Test if the instance is created using a valid data structure.
*
* @return void
*/
public function testCanBeCreatedFromValidUserStructure(): void
{
$this->assertInstanceOf(
@ -46,6 +51,11 @@ class LineTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid Id.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidId(): void
{
$this->expectException(InvalidArgumentException::class);
@ -79,6 +89,11 @@ class LineTest extends TestCase
}
/**
* Test if the instance is not created when using a invalid type.
*
* @return void
*/
public function testCannotBeCreatedWithInvalidtype(): void
{
$this->expectException(InvalidArgumentException::class);
@ -112,11 +127,16 @@ class LineTest extends TestCase
}
/**
* Test if the model has a valid JSON representation.
*
* @return void
*/
public function testContainerIsRepresentedAsJson(): void
{
$this->assertEquals(
'{"id":1,"type":13,"startX":50,"startY":100,"endX":0,"endY":10,"isOnTop":false,"borderWidth":0,"borderColor":"white"}',
Line::fromArray(
'{"borderColor":"white","borderWidth":0,"endX":0,"endY":10,"id":1,"isOnTop":false,"startX":50,"startY":100,"type":13}',
(string) Line::fromArray(
[
'id' => 1,
'type' => LINE_ITEM,