From a033149a2f87338db7b3809ecf444094cf1a8e9e Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 4 Apr 2019 16:08:50 +0200 Subject: [PATCH] fixed problems with test Former-commit-id: 7897203e3ba020fdda8b06fd82a53d18bd91aaa1 --- .../rest-api/models/VisualConsole/Item.php | 4 +- .../models/VisualConsole/Items/ColorCloud.php | 2 +- .../models/VisualConsole/Items/Label.php | 2 +- .../models/VisualConsole/Items/Percentile.php | 6 +-- .../VisualConsole/Items/SimpleValue.php | 37 ++++++++++++++----- .../VisualConsole/Items/StaticGraph.php | 2 +- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Item.php b/pandora_console/include/rest-api/models/VisualConsole/Item.php index ed6e05942d..b27e708998 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Item.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Item.php @@ -158,8 +158,8 @@ class Item extends Model // The item uses HTML output. if (static::$useHtmlOutput === true) { - if (static::notEmptyStringOr($data['encodedHtml'], null) === null - && static::notEmptyStringOr($data['html'], null) === null + if (static::notEmptyStringOr(static::issetInArray($data, ['encodedHtml']), null) === null + && static::notEmptyStringOr(static::issetInArray($data, ['html']), null) === null ) { throw new \InvalidArgumentException( 'the html property is required and should be a not empty string' diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php b/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php index ca3bc71297..8724178b0c 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/ColorCloud.php @@ -44,7 +44,7 @@ final class ColorCloud extends Item $decodedData['label'] = null; $decodedData['defaultColor'] = static::extractDefaultColor($data); $decodedData['colorRanges'] = static::extractColorRanges($data); - $decodedData['color'] = static::notEmptyStringOr($data['color'], null); + $decodedData['color'] = static::notEmptyStringOr(static::issetInArray($data, ['color']), null); return $decodedData; } diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php index 04a124e36c..41c9c6c6d1 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Label.php @@ -36,7 +36,7 @@ final class Label extends Item protected function validateData(array $data): void { parent::validateData($data); - if (static::notEmptyStringOr($data['label'], null) === null) { + if (static::notEmptyStringOr(static::issetInArray($data, ['label']), null) === null) { throw new \InvalidArgumentException( 'the label property is required and should be a not empty string' ); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/Percentile.php b/pandora_console/include/rest-api/models/VisualConsole/Items/Percentile.php index bf1d8e6757..06465b2654 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/Percentile.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/Percentile.php @@ -52,8 +52,8 @@ final class Percentile extends Item { parent::validateData($data); - if (static::notEmptyStringOr($data['encodedHtml'], null) === null - && static::notEmptyStringOr($data['html'], null) === null + if (static::notEmptyStringOr(static::issetInArray($data, ['encodedHtml']), null) === null + && static::notEmptyStringOr(static::issetInArray($data, ['html']), null) === null ) { throw new \InvalidArgumentException( 'the html property is required and should be string' @@ -77,7 +77,7 @@ final class Percentile extends Item $return['type'] = PERCENTILE_BAR; $return['percentileType'] = static::extractPercentileType($data); $return['valueType'] = static::extractValueType($data); - $return['value'] = static::notEmptyStringOr($data['value'], null); + $return['value'] = static::notEmptyStringOr(static::issetInArray($data, ['value']), null); $return['color'] = static::extractColor($data); $return['labelColor'] = static::extractLabelColor($data); return $return; diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/SimpleValue.php b/pandora_console/include/rest-api/models/VisualConsole/Items/SimpleValue.php index 4d4a8bd312..04522caf89 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/SimpleValue.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/SimpleValue.php @@ -86,15 +86,31 @@ final class SimpleValue extends Item */ private static function extractProcessValue(array $data): string { - switch ($data['processValue']) { - case 'none': - case 'avg': - case 'max': - case 'min': - return $data['processValue']; + if (isset($data['processValue'])) { + switch ($data['processValue']) { + case 'none': + case 'avg': + case 'max': + case 'min': + return $data['processValue']; - default: - return 'none'; + default: + return 'none'; + } + } else { + switch ($data['type']) { + case SIMPLE_VALUE_MAX: + return 'max'; + + case SIMPLE_VALUE_MIN: + return 'min'; + + case SIMPLE_VALUE_AVG: + return 'avg'; + + default: + return 'none'; + } } } @@ -108,7 +124,10 @@ final class SimpleValue extends Item */ private static function extractPeriod(array $data): int { - $period = static::parseIntOr($data['period'], 0); + $period = static::parseIntOr( + static::issetInArray($data, ['period']), + 0 + ); return ($period >= 0) ? $period : 0; } diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php index 01aa4a5c52..d91c5b2cf3 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php @@ -44,7 +44,7 @@ final class StaticGraph extends Item $return['imageSrc'] = $this->extractImageSrc($data); $return['showLastValueTooltip'] = $this->extractShowLastValueTooltip($data); $return['statusImageSrc'] = static::notEmptyStringOr( - $data['statusImageSrc'], + static::issetInArray($data, ['statusImageSrc']), null );