Failed Conditions
Push — master ( 27554e...857869 )
by Luca
09:08
created

UtilityTest::testRichTextToPlainText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest;
6
7
use Application\Utility;
8
use PHPUnit\Framework\TestCase;
9
10
class UtilityTest extends TestCase
11
{
12
    /**
13
     * @dataProvider providerSanitizeRichText
14
     */
15
    public function testSanitizeRichText(string $input, string $expected): void
16
    {
17
        self::assertSame($expected, Utility::sanitizeRichText($input));
18
    }
19
20
    public function providerSanitizeRichText(): iterable
21
    {
22
        yield ['', ''];
23
        yield [' foo ', ' foo '];
24
        yield ['foo<div>bar', 'foobar'];
25
        yield ['<script>script</script><div>div</div><span>span</span><p>p</p><strong>strong</strong><br><em>em</em><u>u</u>', 'scriptdivspan<p>p</p><strong>strong</strong><br><em>em</em><u>u</u>'];
26
        yield ['&nbsp;' . html_entity_decode('&nbsp;'), chr(32) . chr(32)];
27
    }
28
29
    /**
30
     * @dataProvider providerSanitizeSingleLineRichText
31
     */
32
    public function testSanitizeSingleLineRichText(string $input, string $expected): void
33
    {
34
        self::assertSame($expected, Utility::sanitizeSingleLineRichText($input));
35
    }
36
37
    public function providerSanitizeSingleLineRichText(): iterable
38
    {
39
        yield ['', ''];
40
        yield [' foo ', ' foo '];
41
        yield ['foo<div>bar', 'foobar'];
42
        yield ['<script>script</script><div>div</div><span>span</span><p>p</p><strong>strong</strong><br><em>em</em><u>u</u>', 'scriptdivspanp<strong>strong</strong><em>em</em><u>u</u>'];
43
        yield ['&nbsp;' . html_entity_decode('&nbsp;'), chr(32) . chr(32)];
44
    }
45
46
    /**
47
     * @dataProvider providerRichTextToPlainText
48
     */
49
    public function testRichTextToPlainText(string $input, string $expected): void
50
    {
51
        self::assertSame($expected, Utility::richTextToPlainText($input));
52
    }
53
54
    public function providerRichTextToPlainText(): iterable
55
    {
56
        yield ['', ''];
57
        yield [' foo ', 'foo'];
58
        yield ['foo<div>bar', 'foobar'];
59
        yield ['<p>p</p>scriptdivspan<p>p</p><strong>strong</strong><br>1<br >2<br/>3<br />4<em>em</em><u>u</u><p>p</p>', <<<STRING
60
            p
61
62
            scriptdivspan
63
64
            p
65
66
            strong
67
            1
68
            2
69
            3
70
            4emu
71
72
            p
73
            STRING
74
            ,
75
        ];
76
        yield ['&amp;&gt;&lt;&quot;&nbsp;' . html_entity_decode('&nbsp;') . '&#8364;&#x20AC;', '&><"  €€'];
77
    }
78
}
79