Completed
Pull Request — master (#144)
by Markus
01:01
created

TextValueTest::testStringValueEscaping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) 2019 Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Test\Unit\Presentation\Component\Property\Value;
13
14
use Eluceo\iCal\Presentation\Component\Property\Value\TextValue;
15
use PHPUnit\Framework\TestCase;
16
17
class TextValueTest extends TestCase
18
{
19
    /**
20
     * @dataProvider provideTestData
21
     */
22
    public function testStringValueEscaping(string $inputValue, string $expected)
23
    {
24
        self::assertSame($expected, (string) TextValue::fromString($inputValue));
25
    }
26
27
    public function provideTestData()
28
    {
29
        yield 'no escaping needed' => [
30
            'LOREM',
31
            'LOREM',
32
        ];
33
        yield 'backslashes are escaped' => [
34
            'text contains backslash: \\',
35
            'text contains backslash: \\\\',
36
        ];
37
        yield 'double quotes are escaped' => [
38
            'text with "doublequotes" will be escaped',
39
            'text with \\"doublequotes\\" will be escaped',
40
        ];
41
        yield 'semicolon and comma are escaped' => [
42
            'text with , and ; will also be escaped',
43
            'text with \\, and \\; will also be escaped',
44
        ];
45
        yield 'new lines are escaped' => [
46
            "Text with new\n line",
47
            'Text with new\\n line',
48
        ];
49
        yield 'do not escape colon' => [
50
            'Text containing: colon are not escaped',
51
            'Text containing: colon are not escaped',
52
        ];
53
        yield 'test control characters are removed' => [
54
            "All the controls \x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f are escaped",
55
            'All the controls \\n are escaped',
56
        ];
57
        yield 'escape double quotes' => [
58
            'Double "quotes are escaped',
59
            'Double \\"quotes are escaped',
60
        ];
61
    }
62
}
63