-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PluginOutput::render()
: Shorten the output by characterLimit before…
… processing it If the shorten output contained (not properly closed) HTML element, it merged the next list-item into the same html tag, because the closing tag was missing. So we therefor shorten the output by characterLimit before proccessing it
- Loading branch information
1 parent
6029cc1
commit caaa390
Showing
2 changed files
with
132 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
|
||
/* Icinga DB Web | (c) 2024 Icinga GmbH | GPLv2 */ | ||
|
||
namespace Tests\Icinga\Module\Icingadb\Util; | ||
|
||
use Icinga\Module\Icingadb\Util\PluginOutput; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PluginOutputTest extends TestCase | ||
{ | ||
public function testRenderPlainText() | ||
{ | ||
$input = 'This is a plain text'; | ||
$expectedOutput = $input; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
|
||
public function testRenderTextWithStates() | ||
{ | ||
$input = <<<'INPUT' | ||
[OK] Dummy state | ||
\_ [OK] Fake "state" | ||
\_ [WARNING] Fake state again | ||
INPUT; | ||
|
||
$expectedOutput = <<<'EXPECTED_OUTPUT' | ||
<span class="state-ball ball-size-m state-ok"></span> Dummy state | ||
\_ <span class="state-ball ball-size-m state-ok"></span> Fake "state" | ||
\_ <span class="state-ball ball-size-m state-warning"></span> Fake state again | ||
EXPECTED_OUTPUT; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
|
||
public function testRenderTextWithStatesAndCharacterLimit() | ||
{ | ||
$input = <<<'INPUT' | ||
[OK] Dummy state | ||
\_ [OK] Fake "state" | ||
\_ [WARNING] Fake state again | ||
INPUT; | ||
|
||
$expectedOutput = <<<'EXPECTED_OUTPUT' | ||
<span class="state-ball ball-size-m state-ok"></span> Dummy | ||
EXPECTED_OUTPUT; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->setCharacterLimit(10)->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
|
||
public function testRenderTextWithHtml() | ||
{ | ||
$input = <<<'INPUT' | ||
Hello <h3>World</h3>, this "is" 'a <strong>test</strong>. | ||
INPUT; | ||
|
||
$expectedOutput = <<<'EXPECTED_OUTPUT' | ||
Hello <h3>World</h3>, this "is" 'a <strong>test</strong>. | ||
EXPECTED_OUTPUT; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
|
||
public function testRenderTextWithHtmlAndStates() | ||
{ | ||
$input = <<<'INPUT' | ||
Hello <h3>World</h3>, this "is" a <strong>test</strong>. | ||
[OK] Dummy state | ||
\_ [OK] Fake "state" | ||
\_ [WARNING] Fake state again | ||
text <span> ends </span> here | ||
INPUT; | ||
|
||
$expectedOutput = <<<'EXPECTED_OUTPUT' | ||
Hello <h3>World</h3>, this "is" a <strong>test</strong>. | ||
<span class="state-ball ball-size-m state-ok"></span> Dummy state | ||
\_ <span class="state-ball ball-size-m state-ok"></span> Fake "state" | ||
\_ <span class="state-ball ball-size-m state-warning"></span> Fake state again | ||
text <span> ends </span> here | ||
EXPECTED_OUTPUT; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
|
||
public function testRenderTextWithHtmlIncludingStatesAndSpecialChars() | ||
{ | ||
$input = <<<'INPUT' | ||
Hello <h3>World</h3>, this "is" a <strong>test</strong>. | ||
[OK] Dummy state | ||
special chars: !@#$%^&*()_+{}|:"<>?`-=[]\;',./ | ||
text <span> ends </span> here | ||
INPUT; | ||
|
||
$expectedOutput = <<<'EXPECTED_OUTPUT' | ||
Hello <h3>World</h3>, this "is" a <strong>test</strong>. | ||
<span class="state-ball ball-size-m state-ok"></span> Dummy state | ||
special chars: !@#$%^&*()_+{}|:"<>?`-=[]\;',​./ | ||
text <span> ends </span> here | ||
EXPECTED_OUTPUT; | ||
|
||
$this->assertSame( | ||
$expectedOutput, | ||
(new PluginOutput($input))->render(), | ||
'PluginOutput::render does not return expected values' | ||
); | ||
} | ||
} |