2019-03-20 16:31:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
use Models\VisualConsole\Item as ItemConsole;
|
|
|
|
|
|
|
|
/**
|
2019-03-25 16:36:38 +01:00
|
|
|
* Test for the Visual Console Item model.
|
2019-03-20 16:31:29 +01:00
|
|
|
*/
|
|
|
|
class ItemTest extends TestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the instance is created using a valid data structure.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testCanBeCreatedFromValidUserStructure(): void
|
|
|
|
{
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
ItemConsole::class,
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 1,
|
|
|
|
'type' => 5,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(
|
|
|
|
ItemConsole::class,
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 1,
|
|
|
|
'type' => 5,
|
|
|
|
'width' => 0,
|
|
|
|
'height' => 0,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the instance is not created when using a invalid id.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testCannotBeCreatedWithInvalidId(): void
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
// Invalid id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 'foo',
|
|
|
|
'type' => 5,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// Missing id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'type' => 5,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the instance is not created when using a invalid type.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testCannotBeCreatedWithInvalidType(): void
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
// Invalid id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 'clock',
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// Missing id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 6,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the instance is not created when using a invalid width.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testCannotBeCreatedWithInvalidWidth(): void
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
// Invalid id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => -1,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// Missing id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the instance is not created when using a invalid height.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testCannotBeCreatedWithInvalidHeight(): void
|
|
|
|
{
|
|
|
|
$this->expectException(InvalidArgumentException::class);
|
|
|
|
// Invalid id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => -1,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
// Missing id.
|
|
|
|
ItemConsole::fromArray(
|
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-25 16:36:38 +01:00
|
|
|
/**
|
|
|
|
* Test if the model has a valid JSON representation.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-03-20 16:31:29 +01:00
|
|
|
public function testItemIsRepresentedAsJson(): void
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
2019-03-26 11:45:50 +01:00
|
|
|
'{"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(
|
2019-03-20 16:31:29 +01:00
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => 'test',
|
|
|
|
'labelPosition' => 'down',
|
|
|
|
'isLinkEnabled' => false,
|
|
|
|
'isOnTop' => true,
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2019-03-26 11:45:50 +01:00
|
|
|
'{"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(
|
2019-03-20 16:31:29 +01:00
|
|
|
[
|
|
|
|
'id' => 15,
|
|
|
|
'type' => 3,
|
|
|
|
'label' => '',
|
|
|
|
'labelPosition' => 'test',
|
|
|
|
'parentId' => 0,
|
|
|
|
'aclGroupId' => 12,
|
|
|
|
'width' => 800,
|
|
|
|
'height' => 600,
|
|
|
|
'x' => 0,
|
|
|
|
'y' => 0,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEquals(
|
2019-03-26 11:45:50 +01:00
|
|
|
'{"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(
|
2019-03-20 16:31:29 +01:00
|
|
|
[
|
|
|
|
'id' => 69,
|
|
|
|
'type' => 20,
|
|
|
|
'label' => null,
|
|
|
|
'labelPosition' => 'up',
|
|
|
|
'isLinkEnabled' => true,
|
|
|
|
'isOnTop' => false,
|
|
|
|
'parentId' => null,
|
|
|
|
'width' => '0',
|
|
|
|
'height' => '0',
|
|
|
|
'x' => -666,
|
|
|
|
'y' => 76,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|