1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
|
8
|
|
|
class StringHelperTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
parent::setUp(); |
13
|
|
|
|
14
|
|
|
// Reset Currency Code |
15
|
|
|
StringHelper::setCurrencyCode(null); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testGetIsIconvEnabled() |
19
|
|
|
{ |
20
|
|
|
$result = StringHelper::getIsIconvEnabled(); |
21
|
|
|
$this->assertTrue($result); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
public function testGetDecimalSeparator() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
$localeconv = localeconv(); |
27
|
|
|
|
28
|
|
|
$expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ','; |
29
|
|
|
$result = StringHelper::getDecimalSeparator(); |
30
|
|
|
$this->assertEquals($expectedResult, $result); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testSetDecimalSeparator() |
34
|
|
|
{ |
35
|
|
|
$expectedResult = ','; |
36
|
|
|
StringHelper::setDecimalSeparator($expectedResult); |
37
|
|
|
|
38
|
|
|
$result = StringHelper::getDecimalSeparator(); |
39
|
|
|
$this->assertEquals($expectedResult, $result); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testGetThousandsSeparator() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$localeconv = localeconv(); |
45
|
|
|
|
46
|
|
|
$expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ','; |
47
|
|
|
$result = StringHelper::getThousandsSeparator(); |
48
|
|
|
$this->assertEquals($expectedResult, $result); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testSetThousandsSeparator() |
52
|
|
|
{ |
53
|
|
|
$expectedResult = ' '; |
54
|
|
|
StringHelper::setThousandsSeparator($expectedResult); |
55
|
|
|
|
56
|
|
|
$result = StringHelper::getThousandsSeparator(); |
57
|
|
|
$this->assertEquals($expectedResult, $result); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetCurrencyCode() |
61
|
|
|
{ |
62
|
|
|
$localeconv = localeconv(); |
63
|
|
|
$expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$')); |
64
|
|
|
$result = StringHelper::getCurrencyCode(); |
65
|
|
|
$this->assertEquals($expectedResult, $result); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testSetCurrencyCode() |
69
|
|
|
{ |
70
|
|
|
$expectedResult = '£'; |
71
|
|
|
StringHelper::setCurrencyCode($expectedResult); |
72
|
|
|
|
73
|
|
|
$result = StringHelper::getCurrencyCode(); |
74
|
|
|
$this->assertEquals($expectedResult, $result); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public function testControlCharacterPHP2OOXML() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$expectedResult = 'foo_x000B_bar'; |
80
|
|
|
$result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar'); |
81
|
|
|
|
82
|
|
|
$this->assertEquals($expectedResult, $result); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
View Code Duplication |
public function testControlCharacterOOXML2PHP() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$expectedResult = 'foo' . chr(11) . 'bar'; |
88
|
|
|
$result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar'); |
89
|
|
|
|
90
|
|
|
$this->assertEquals($expectedResult, $result); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testSYLKtoUTF8() |
94
|
|
|
{ |
95
|
|
|
$expectedResult = 'foo' . chr(11) . 'bar'; |
96
|
|
|
$result = StringHelper::SYLKtoUTF8("foo\x1B ;bar"); |
97
|
|
|
|
98
|
|
|
$this->assertEquals($expectedResult, $result); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.