Debian Codegraph @

test/php/library/Toplevelview/Util/StrTest.php

raw
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 }