1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; |
6
|
|
|
|
7
|
|
|
class StringTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function setUp() |
10
|
|
|
{ |
11
|
|
|
parent::setUp(); |
12
|
|
|
|
13
|
|
|
// Reset Currency Code |
14
|
|
|
StringHelper::setCurrencyCode(null); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function testGetIsIconvEnabled() |
18
|
|
|
{ |
19
|
|
|
$result = StringHelper::getIsIconvEnabled(); |
20
|
|
|
$this->assertTrue($result); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function testGetDecimalSeparator() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$localeconv = localeconv(); |
26
|
|
|
|
27
|
|
|
$expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ','; |
28
|
|
|
$result = StringHelper::getDecimalSeparator(); |
29
|
|
|
$this->assertEquals($expectedResult, $result); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSetDecimalSeparator() |
33
|
|
|
{ |
34
|
|
|
$expectedResult = ','; |
35
|
|
|
StringHelper::setDecimalSeparator($expectedResult); |
36
|
|
|
|
37
|
|
|
$result = StringHelper::getDecimalSeparator(); |
38
|
|
|
$this->assertEquals($expectedResult, $result); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testGetThousandsSeparator() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$localeconv = localeconv(); |
44
|
|
|
|
45
|
|
|
$expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ','; |
46
|
|
|
$result = StringHelper::getThousandsSeparator(); |
47
|
|
|
$this->assertEquals($expectedResult, $result); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testSetThousandsSeparator() |
51
|
|
|
{ |
52
|
|
|
$expectedResult = ' '; |
53
|
|
|
StringHelper::setThousandsSeparator($expectedResult); |
54
|
|
|
|
55
|
|
|
$result = StringHelper::getThousandsSeparator(); |
56
|
|
|
$this->assertEquals($expectedResult, $result); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetCurrencyCode() |
60
|
|
|
{ |
61
|
|
|
$localeconv = localeconv(); |
62
|
|
|
$expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$')); |
63
|
|
|
$result = StringHelper::getCurrencyCode(); |
64
|
|
|
$this->assertEquals($expectedResult, $result); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testSetCurrencyCode() |
68
|
|
|
{ |
69
|
|
|
$expectedResult = '£'; |
70
|
|
|
StringHelper::setCurrencyCode($expectedResult); |
71
|
|
|
|
72
|
|
|
$result = StringHelper::getCurrencyCode(); |
73
|
|
|
$this->assertEquals($expectedResult, $result); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
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.