| 1 |
<?php |
| 2 |
|
| 3 |
namespace Tests\Icinga\Module\Toplevelview; |
| 4 |
|
| 5 |
use Icinga\Module\Toplevelview\Util\Str; |
| 6 |
use PHPUnit\Framework\TestCase; |
| 7 |
|
| 8 |
final class StrTest extends TestCase |
| 9 |
{ |
| 10 |
public function testLimitWithSmallerString() |
| 11 |
{ |
| 12 |
$this->assertSame('', Str::limit(null)); |
| 13 |
$this->assertSame('', Str::limit('')); |
| 14 |
$this->assertSame('noop', Str::limit('noop')); |
| 15 |
} |
| 16 |
|
| 17 |
public function testLimitWithLongerStringAndSpecificLimit() |
| 18 |
{ |
| 19 |
$this->assertSame( |
| 20 |
'Lorem ipsu...', |
| 21 |
Str::limit('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 10) |
| 22 |
); |
| 23 |
$this->assertSame( |
| 24 |
'πππππ...', |
| 25 |
Str::limit('ππππππππ', 10) |
| 26 |
); |
| 27 |
} |
| 28 |
|
| 29 |
public function testLimitWithLongerStringAndSpecificEnd() |
| 30 |
{ |
| 31 |
$this->assertSame( |
| 32 |
'L (...)', |
| 33 |
Str::limit('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 1, ' (...)') |
| 34 |
); |
| 35 |
$this->assertSame( |
| 36 |
'Π (...)', |
| 37 |
Str::limit('ΠΡΠΎ ΡΡΠΎ ΡΠΈΡΠ°Π΅Ρ, ΡΠΎΡ Π΄ΡΡΠ°ΠΊ', 1, ' (...)') |
| 38 |
); |
| 39 |
$this->assertSame( |
| 40 |
'Π (π¦π¦π¦)', |
| 41 |
Str::limit('ΠΡΠΎ ΡΡΠΎ ΡΠΈΡΠ°Π΅Ρ, ΡΠΎΡ Π΄ΡΡΠ°ΠΊ', 1, ' (π¦π¦π¦)') |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
public function testPrettyPrint() |
| 46 |
{ |
| 47 |
$this->assertSame('Critical Unhandled', Str::prettyTitle('critical_unhandled')); |
| 48 |
$this->assertSame('Warning Handled', Str::prettyTitle('warning_handled')); |
| 49 |
$this->assertSame('Foo Bar', Str::prettyTitle('foo_bar')); |
| 50 |
$this->assertSame('XXX YYY', Str::prettyTitle('XXX_YYY')); |
| 51 |
$this->assertSame('', Str::prettyTitle('')); |
| 52 |
$this->assertSame('Ok', Str::prettyTitle('ok')); |
| 53 |
} |
| 54 |
} |