diff --git a/modules/monitoring/application/views/helpers/PluginOutput.php b/modules/monitoring/application/views/helpers/PluginOutput.php
index cecf0262b..1c77b578d 100644
--- a/modules/monitoring/application/views/helpers/PluginOutput.php
+++ b/modules/monitoring/application/views/helpers/PluginOutput.php
@@ -143,16 +143,28 @@ class Zend_View_Helper_PluginOutput extends Zend_View_Helper_Abstract
$offsetLeft = $match[0][1];
$matchLength = strlen($match[0][0]);
$leftLength = $offsetLeft - $start;
+ // if there is text before the match
if ($leftLength) {
+ // create node for leading text
$text = new DOMText(substr($node->nodeValue, $start, $leftLength));
$node->parentNode->insertBefore($text, $node);
}
+ // create the new element for the match
$span = $doc->createElement('span', $match[0][0]);
$span->setAttribute('class', 'state-' . strtolower($match[1][0]));
$node->parentNode->insertBefore($span, $node);
+
+ // start for next match
$start = $offsetLeft + $matchLength;
}
if ($start) {
+ // is there text left?
+ if (strlen($node->nodeValue) > $start) {
+ // create node for trailing text
+ $text = new DOMText(substr($node->nodeValue, $start));
+ $node->parentNode->insertBefore($text, $node);
+ }
+ // delete the old node later
$nodesToRemove[] = $node;
}
} elseif ($node->nodeType === XML_ELEMENT_NODE) {
diff --git a/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php b/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php
new file mode 100644
index 000000000..9a3e4a0fa
--- /dev/null
+++ b/modules/monitoring/test/php/application/views/helpers/PluginOutputTest.php
@@ -0,0 +1,141 @@
+';
+ const PREFIX = '
';
+ const SUFFIX = '
';
+
+ protected static $statusTags = array('OK', 'WARNING', 'CRITICAL', 'UNKNOWN', 'UP', 'DOWN');
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->helper = $h = new Zend_View_Helper_PluginOutput;
+ $h->setView(new View());
+ }
+
+ protected function checkOutput($output, $html, $regexp = false, $isHtml = false)
+ {
+ $actual = $this->helper->pluginOutput($output);
+
+ if ($isHtml) {
+ $prefix = self::PREFIX;
+ } else {
+ $prefix = self::PREFIX_PRE;
+ }
+
+ if ($regexp) {
+ $expect = sprintf(
+ '~%s%s%s~',
+ preg_quote($prefix, '~'),
+ $html,
+ preg_quote(self::SUFFIX, '~')
+ );
+ $this->assertRegExp($expect, $actual, 'Output must match example regexp');
+ } else {
+ $expect = $prefix . $html . self::SUFFIX;
+ $this->assertEquals($expect, $actual, 'Output must match example');
+ }
+ }
+
+ protected function checkHtmlOutput($outputHtml, $html, $regexp = false)
+ {
+ return $this->checkOutput($outputHtml, $html, $regexp, true);
+ }
+
+ public function testSimpleOutput()
+ {
+ $this->checkOutput(
+ 'Foobar',
+ 'Foobar'
+ );
+ }
+
+ public function testSimpleHtmlOutput()
+ {
+ /** @noinspection HtmlUnknownAttribute */
+ $this->checkHtmlOutput(
+ 'OK - Teststatus Info',
+ 'OK - Teststatus ]*>Info',
+ true
+ );
+ }
+
+ public function testMultilineHtmlOutput()
+ {
+ $input = array(
+ 'Teststatus',
+ 'Info
',
+ 'Info2'
+ );
+ /** @noinspection HtmlUnknownAttribute */
+ $output = array(
+ 'Teststatus',
+ ']*>Info',
+ '',
+ '',
+ ']*>Info2'
+ );
+ $this->checkHtmlOutput(
+ join("\n", $input),
+ join("\n", $output),
+ true
+ );
+ }
+
+ public function testHtmlTable()
+ {
+ $this->markTestIncomplete();
+ }
+
+ public function testAllowedHtmlTags()
+ {
+ $this->markTestIncomplete();
+ }
+
+ public function testTextStatusTags()
+ {
+ foreach (self::$statusTags as $s) {
+ $l = strtolower($s);
+ $this->checkOutput(
+ sprintf('[%s] Test', $s),
+ sprintf('[%s] Test', $l, $s)
+ );
+ $this->checkOutput(
+ sprintf('(%s) Test', $s),
+ sprintf('(%s) Test', $l, $s)
+ );
+ }
+ }
+
+ public function testHtmlStatusTags()
+ {
+ $dummyHtml = '';
+
+ foreach (self::$statusTags as $s) {
+ $l = strtolower($s);
+ $this->checkHtmlOutput(
+ sprintf('%s [%s] Test', $dummyHtml, $s),
+ sprintf('%s [%s] Test', $dummyHtml, $l, $s)
+ );
+ $this->checkHtmlOutput(
+ sprintf('%s (%s) Test', $dummyHtml, $s),
+ sprintf('%s (%s) Test', $dummyHtml, $l, $s)
+ );
+ }
+ }
+}