setCharacterLimit($characterLimit);
}
$this->assertSame($expected, $p->render(), 'PluginOutput::render does not return expected values');
}
public function testRenderPlainText(): void
{
$input = 'This is a plain text';
$this->checkOutput($input, $input);
}
public function testRenderTextWithStates(): void
{
$input = <<<'INPUT'
[OK] Dummy state
\_ [OK] Fake "state"
\_ [WARNING] Fake state again
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
Dummy state
\_ Fake "state"
\_ Fake state again
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
public function testRenderTextWithStatesAndCharacterLimit(): void
{
$input = <<<'INPUT'
[OK] Dummy state
\_ [OK] Fake "state"
\_ [WARNING] Fake state again
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
Dummy
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input, 10);
}
public function testRenderTextWithHtml(): void
{
$input = <<<'INPUT'
Hello
World
, this "is" 'a test.
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
Hello World
, this "is" 'a test.
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
public function testRenderTextWithHtmlAndStates(): void
{
$input = <<<'INPUT'
Hello World
, this "is" a test.
[OK] Dummy state
\_ [OK] Fake "state"
\_ [WARNING] Fake state again
text ends here
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
Hello World
, this "is" a test.
Dummy state
\_ Fake "state"
\_ Fake state again
text ends here
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
public function testRenderTextWithHtmlIncludingStatesAndSpecialChars(): void
{
$input = <<<'INPUT'
Hello World
, this "is" a test.
[OK] Dummy state
special chars: !@#$%^&*()_+{}|:"<>?`-=[]\;',./
text ends here
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
Hello World
, this "is" a test.
Dummy state
special chars: !@#$%^&*()_+{}|:"<>?`-=[]\;',./
text ends here
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
public function testOutputWithNewlines(): void
{
$input = 'foo\nbar\n\nraboof';
$expectedOutput = "foo\nbar\n\nraboof";
$this->checkOutput($expectedOutput, $input);
}
public function testOutputWithHtmlEntities(): void
{
$input = 'foo & bar';
$expectedOutput = $input;
$this->checkOutput($expectedOutput, $input);
}
public function testSimpleHtmlOutput(): void
{
$input = <<<'INPUT'
OK - Teststatus Info
INPUT;
$expectedOutput = <<<'EXPECTED_OUTPUT'
OK - Teststatus Info
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
public function testTextStatusTags(): void
{
foreach (['OK', 'WARNING', 'CRITICAL', 'UNKNOWN', 'UP', 'DOWN'] as $s) {
$l = strtolower($s);
$input = sprintf('[%s] Test', $s);
$expectedOutput = sprintf(' Test', $l);
$this->checkOutput($expectedOutput, $input);
$input = sprintf('(%s) Test', $s);
$this->checkOutput($expectedOutput, $input);
}
}
public function testHtmlStatusTags(): void
{
$dummyHtml = '';
foreach (['OK', 'WARNING', 'CRITICAL', 'UNKNOWN', 'UP', 'DOWN'] as $s) {
$l = strtolower($s);
$input = sprintf('%s [%s] Test', $dummyHtml, $s);
$expectedOutput = sprintf('%s Test', $dummyHtml, $l);
$this->checkOutput($expectedOutput, $input);
$input = sprintf('%s (%s) Test', $dummyHtml, $s);
$this->checkOutput($expectedOutput, $input);
}
}
public function testNewlineProcessingInHtmlOutput(): void
{
$input = 'This is plugin output\n\n\n\n'
. 'and more text that\nis split onto multiple\n\nlines';
$expectedOutput = <<<'EXPECTED_OUTPUT'
This is plugin output
and more text that
is split onto multiple
lines
EXPECTED_OUTPUT;
$this->checkOutput($expectedOutput, $input);
}
}