mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-04-08 18:55:09 +02:00
Added EventsHistory, SimpleValue and StaticGraph
Former-commit-id: 9e56eb3df9997f0d601db774a7131f783cc3dfe9
This commit is contained in:
parent
8d95afc9ea
commit
f516c6d36a
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
use Models\Model;
|
||||
|
||||
/**
|
||||
* Model of a group item of the Visual Console.
|
||||
*/
|
||||
final class EventsHistory extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = AUTO_SLA_GRAPH;
|
||||
$return['maxTime'] = $this->extractMaxTime($data);
|
||||
$return['data'] = $this->extractData($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of maxTime and
|
||||
* return a integer or null.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private function extractMaxTime(array $data)
|
||||
{
|
||||
$maxTime = Model::parseIntOr(
|
||||
Model::issetInArray($data, ['maxTime', 'period']),
|
||||
null
|
||||
);
|
||||
return $maxTime;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of data and
|
||||
* return an array.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractData(array $data): array
|
||||
{
|
||||
$array = [];
|
||||
if (isset($data['data']) && \is_array($data['data'])) {
|
||||
$array = $data['data'];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
use Models\Model;
|
||||
|
||||
/**
|
||||
* Model of a simple value item of the Visual Console.
|
||||
*/
|
||||
final class SimpleValue extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Validate the received data structure to ensure if we can extract the
|
||||
* values required to build the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \InvalidArgumentException If any input value is considered
|
||||
* invalid.
|
||||
*
|
||||
* @overrides Item::validateData.
|
||||
*/
|
||||
protected function validateData(array $data): void
|
||||
{
|
||||
parent::validateData($data);
|
||||
if (isset($data['valueType']) === false
|
||||
|| \is_string($data['valueType']) === false
|
||||
) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the valueType property is required and should be string'
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($data['value']) === false) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the value property is required'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = SIMPLE_VALUE;
|
||||
$return['processValue'] = $this->extractProcessValue($data);
|
||||
if ($return['processValue'] !== 'none') {
|
||||
$return['period'] = $this->extractPeriod($data);
|
||||
}
|
||||
|
||||
$return['valueType'] = $this->extractValueType($data);
|
||||
$return['value'] = $data['value'];
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of processValue and
|
||||
* return 'avg', 'max', 'min' or 'none'.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function extractProcessValue(array $data): string
|
||||
{
|
||||
$processValue = Model::notEmptyStringOr(
|
||||
Model::issetInArray($data, ['processValue']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($processValue) {
|
||||
case 'avg':
|
||||
return 'avg';
|
||||
|
||||
case 'max':
|
||||
return 'max';
|
||||
|
||||
case 'min':
|
||||
return 'min';
|
||||
|
||||
default:
|
||||
return 'none';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of period and
|
||||
* return a integer.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function extractPeriod(array $data): int
|
||||
{
|
||||
$period = Model::parseIntOr(
|
||||
Model::issetInArray($data, ['period']),
|
||||
0
|
||||
);
|
||||
if ($period >= 0) {
|
||||
return $period;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of valueType and
|
||||
* return 'image' or 'string'.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function extractValueType(array $data): string
|
||||
{
|
||||
$valueType = Model::notEmptyStringOr(
|
||||
Model::issetInArray($data, ['valueType']),
|
||||
null
|
||||
);
|
||||
|
||||
switch ($valueType) {
|
||||
case 'image':
|
||||
return 'image';
|
||||
|
||||
default:
|
||||
return 'string';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Models\VisualConsole\Items;
|
||||
use Models\VisualConsole\Item;
|
||||
use Models\Model;
|
||||
|
||||
/**
|
||||
* Model of a group item of the Visual Console.
|
||||
*/
|
||||
final class StaticGraph extends Item
|
||||
{
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked visual console.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedVisualConsole = true;
|
||||
|
||||
/**
|
||||
* Used to enable the fetching, validation and extraction of information
|
||||
* about the linked module.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected static $useLinkedModule = true;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a valid representation of the model.
|
||||
*
|
||||
* @param array $data Input data.
|
||||
*
|
||||
* @return array Data structure representing the model.
|
||||
*
|
||||
* @overrides Item::decode.
|
||||
*/
|
||||
protected function decode(array $data): array
|
||||
{
|
||||
$return = parent::decode($data);
|
||||
$return['type'] = STATIC_GRAPH;
|
||||
$return['imageSrc'] = $this->extractImageSrc($data);
|
||||
$return['showLastValueTooltip'] = $this->extractShowLastValueTooltip($data);
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract a image src value.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return mixed String representing the image url (not empty) or null.
|
||||
*
|
||||
* @throws \InvalidArgumentException When a valid image src can't be found.
|
||||
*/
|
||||
private function extractImageSrc(array $data): string
|
||||
{
|
||||
$imageSrc = static::notEmptyStringOr(
|
||||
static::issetInArray($data, ['imageSrc', 'image']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($imageSrc === null || \strlen($imageSrc) === 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'the image src property is required and should be a non empty string'
|
||||
);
|
||||
}
|
||||
|
||||
return $imageSrc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the value of showLastValueTooltip and
|
||||
* return 'default', 'enabled' or 'disabled'.
|
||||
*
|
||||
* @param array $data Unknown input data structure.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function extractShowLastValueTooltip(array $data): string
|
||||
{
|
||||
$showLastValueTooltip = Model::notEmptyStringOr(
|
||||
Model::issetInArray($data, ['showLastValueTooltip']),
|
||||
null
|
||||
);
|
||||
|
||||
if ($showLastValueTooltip === null) {
|
||||
$showLastValueTooltip = Model::parseIntOr(
|
||||
Model::issetInArray($data, ['show_last_value']),
|
||||
null
|
||||
);
|
||||
switch ($showLastValueTooltip) {
|
||||
case 1:
|
||||
return 'enabled';
|
||||
|
||||
case 2:
|
||||
return 'disabled';
|
||||
|
||||
default:
|
||||
return 'default';
|
||||
}
|
||||
} else {
|
||||
switch ($showLastValueTooltip) {
|
||||
case 'enabled':
|
||||
return 'enabled';
|
||||
|
||||
case 'disabled':
|
||||
return 'disabled';
|
||||
|
||||
default:
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Models\VisualConsole\Items\EventsHistory;
|
||||
|
||||
/**
|
||||
* Test for the Visual Console events history Item model.
|
||||
*/
|
||||
class EventsHistoryTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Test if the instance is created using a valid data structure.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanBeCreatedFromValidUserStructure(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
EventsHistory::class,
|
||||
EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'maxTime' => null,
|
||||
'data' => [],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
EventsHistory::class,
|
||||
EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 14,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'maxTime' => 12800,
|
||||
'data' => [
|
||||
'data' => '5',
|
||||
'time' => 23456788,
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if the model has a valid JSON representation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testContainerIsRepresentedAsJson(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":[],"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||
(string) EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'maxTime' => null,
|
||||
'data' => [],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","maxTime":12800,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||
(string) EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'maxTime' => 12800,
|
||||
'data' => [
|
||||
'time' => 23456789,
|
||||
'data' => 15,
|
||||
],
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":[],"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","maxTime":null,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||
(string) EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'maxTime' => null,
|
||||
'data' => [],
|
||||
'id_layout_linked' => 1,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":5,"moduleId":null,"moduleName":null,"parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||
(string) EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'maxTime' => 12800,
|
||||
'data' => [
|
||||
'time' => 23456789,
|
||||
'data' => 15,
|
||||
],
|
||||
'id_metaconsole' => 5,
|
||||
'linked_layout_node_id' => 3,
|
||||
'linkedLayoutId' => 2,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":21,"agentName":null,"data":{"time":23456789,"data":15},"height":0,"id":7,"isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":15,"linkedLayoutId":3,"linkedLayoutStatusType":"default","maxTime":12800,"metaconsoleId":2,"moduleId":385,"moduleName":"module_test","parentId":null,"type":14,"width":0,"x":-666,"y":76}',
|
||||
(string) EventsHistory::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => AUTO_SLA_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'maxTime' => 12800,
|
||||
'data' => [
|
||||
'time' => 23456789,
|
||||
'data' => 15,
|
||||
],
|
||||
'id_metaconsole' => 2,
|
||||
'linked_layout_node_id' => 15,
|
||||
'linkedLayoutId' => 3,
|
||||
'agentId' => 21,
|
||||
'moduleId' => 385,
|
||||
'moduleName' => 'module_test',
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Models\VisualConsole\Items\SimpleValue;
|
||||
|
||||
/**
|
||||
* Test for the Visual Console Simple Value Item model.
|
||||
*/
|
||||
class SimpleValueTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Test if the instance is created using a valid data structure.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCanBeCreatedFromValidUserStructure(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
SimpleValue::class,
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
'processValue' => 'avg',
|
||||
'period' => 12800,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
SimpleValue::class,
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 14,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'image',
|
||||
'value' => 3598,
|
||||
'processValue' => 'max',
|
||||
'period' => 9000,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testCannotBeCreatedWithInvalidValueType(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
// Invalid valueType.
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'valueType' => '',
|
||||
'value' => 57,
|
||||
]
|
||||
);
|
||||
// Missing valueType.
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'value' => 57,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testCannotBeCreatedWithInvalidValue(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
// Invalid valueType.
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'valueType' => 'string',
|
||||
'value' => 'foo',
|
||||
]
|
||||
);
|
||||
// Missing valueType.
|
||||
SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'valueType' => 'string',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if the model has a valid JSON representation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testContainerIsRepresentedAsJson(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":500,"id":3,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"period":12800,"processValue":"avg","type":2,"value":57,"valueType":"string","width":600,"x":0,"y":0}',
|
||||
(string) SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
'processValue' => 'avg',
|
||||
'period' => 12800,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":500,"id":3,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"processValue":"none","type":2,"value":57,"valueType":"string","width":600,"x":0,"y":0}',
|
||||
(string) SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":500,"id":3,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"processValue":"none","type":2,"value":57,"valueType":"string","width":600,"x":0,"y":0}',
|
||||
(string) SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
'id_layout_linked' => 1,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":500,"id":3,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","metaconsoleId":5,"moduleId":null,"moduleName":null,"parentId":null,"processValue":"none","type":2,"value":57,"valueType":"string","width":600,"x":0,"y":0}',
|
||||
(string) SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
'id_metaconsole' => 5,
|
||||
'linked_layout_node_id' => 3,
|
||||
'linkedLayoutId' => 2,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":21,"agentName":null,"height":500,"id":3,"isLinkEnabled":false,"isOnTop":false,"label":null,"labelPosition":"down","linkedLayoutAgentId":15,"linkedLayoutId":3,"linkedLayoutStatusType":"default","metaconsoleId":2,"moduleId":385,"moduleName":"module_test","parentId":null,"processValue":"none","type":2,"value":57,"valueType":"string","width":600,"x":0,"y":0}',
|
||||
(string) SimpleValue::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => SIMPLE_VALUE,
|
||||
'width' => '600',
|
||||
'height' => '500',
|
||||
'valueType' => 'string',
|
||||
'value' => 57,
|
||||
'id_metaconsole' => 2,
|
||||
'linked_layout_node_id' => 15,
|
||||
'linkedLayoutId' => 3,
|
||||
'agentId' => 21,
|
||||
'moduleId' => 385,
|
||||
'moduleName' => 'module_test',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Models\VisualConsole\Items\StaticGraph;
|
||||
|
||||
/**
|
||||
* Test class
|
||||
*/
|
||||
class StaticGrahpTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public function testCanBeCreatedFromValidUserStructure(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
StaticGraph::class,
|
||||
StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 345,
|
||||
'type' => 1,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'imageSrc' => 'aaaaa',
|
||||
'showLastValueTooltip' => 'enabled',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
StaticGraph::class,
|
||||
StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 1000,
|
||||
'type' => 0,
|
||||
'width' => 100,
|
||||
'height' => 900,
|
||||
'image' => 'test.jpg',
|
||||
'show_last_value' => 2,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if the model has a valid JSON representation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testContainerIsRepresentedAsJson(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"showLastValueTooltip":"default","type":0,"width":0,"x":-666,"y":76}',
|
||||
(string) StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => STATIC_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'imageSrc' => 'image.jpg',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":null,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"showLastValueTooltip":"disabled","type":0,"width":0,"x":-666,"y":76}',
|
||||
(string) StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => STATIC_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'image' => 'image.jpg',
|
||||
'showLastValueTooltip' => 'disabled',
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":3,"linkedLayoutId":2,"linkedLayoutStatusType":"default","metaconsoleId":5,"moduleId":null,"moduleName":null,"parentId":null,"showLastValueTooltip":"default","type":0,"width":0,"x":-666,"y":76}',
|
||||
(string) StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => STATIC_GRAPH,
|
||||
'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,"agentId":null,"agentName":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":1,"linkedLayoutStatusType":"default","moduleId":null,"moduleName":null,"parentId":null,"showLastValueTooltip":"default","type":0,"width":0,"x":-666,"y":76}',
|
||||
(string) StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => STATIC_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'image' => 'image.jpg',
|
||||
'id_layout_linked' => 1,
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"aclGroupId":null,"agentId":null,"agentName":null,"height":0,"id":7,"imageSrc":"image.jpg","isLinkEnabled":true,"isOnTop":false,"label":null,"labelPosition":"up","linkedLayoutAgentId":null,"linkedLayoutId":2,"linkedLayoutStatusType":"service","linkedLayoutStatusTypeCriticalThreshold":80,"linkedLayoutStatusTypeWarningThreshold":50,"moduleId":null,"moduleName":null,"parentId":null,"showLastValueTooltip":"default","type":0,"width":0,"x":-666,"y":76}',
|
||||
(string) StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 7,
|
||||
'type' => STATIC_GRAPH,
|
||||
'label' => null,
|
||||
'labelPosition' => 'up',
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '0',
|
||||
'height' => '0',
|
||||
'x' => -666,
|
||||
'y' => 76,
|
||||
'image' => 'image.jpg',
|
||||
'linkedLayoutId' => 2,
|
||||
'linked_layout_status_type' => 'service',
|
||||
'linkedLayoutStatusTypeWarningThreshold' => 50,
|
||||
'linked_layout_status_as_service_critical' => 80,
|
||||
]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testCannotBeCreatedWithInvalidImageSrc(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
// Invalid imageSrc.
|
||||
StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => 0,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'imageSrc' => 45,
|
||||
'showLastValueTooltip' => 'disabled',
|
||||
]
|
||||
);
|
||||
// Missing imageSrc.
|
||||
StaticGraph::fromArray(
|
||||
[
|
||||
'id' => 3,
|
||||
'type' => 0,
|
||||
'label' => null,
|
||||
'isLinkEnabled' => true,
|
||||
'isOnTop' => false,
|
||||
'parentId' => null,
|
||||
'width' => '330',
|
||||
'height' => '0',
|
||||
'x' => 511,
|
||||
'y' => 76,
|
||||
'showLastValueTooltip' => 'enabled',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user