| 
									
										
										
										
											2012-06-18 20:35:21 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | namespace PhpOffice\PhpSpreadsheetTests\Shared; | 
					
						
							| 
									
										
										
										
											2012-06-18 20:35:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-31 17:18:12 +00:00
										 |  |  | use PhpOffice\PhpSpreadsheet\Shared\StringHelper; | 
					
						
							| 
									
										
										
										
											2017-05-17 22:02:17 +00:00
										 |  |  | use PHPUnit_Framework_TestCase; | 
					
						
							| 
									
										
										
										
											2016-08-14 04:08:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 10:29:08 +00:00
										 |  |  | class StringHelperTest extends PHPUnit_Framework_TestCase | 
					
						
							| 
									
										
										
										
											2012-06-18 20:35:21 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-18 11:37:00 +00:00
										 |  |  |     public function setUp() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         parent::setUp(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Reset Currency Code
 | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         StringHelper::setCurrencyCode(null); | 
					
						
							| 
									
										
										
										
											2016-05-18 11:37:00 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     public function testGetIsIconvEnabled() | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getIsIconvEnabled(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertTrue($result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetDecimalSeparator() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $localeconv = localeconv(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ','; | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getDecimalSeparator(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetDecimalSeparator() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = ','; | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         StringHelper::setDecimalSeparator($expectedResult); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getDecimalSeparator(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetThousandsSeparator() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $localeconv = localeconv(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ','; | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getThousandsSeparator(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetThousandsSeparator() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = ' '; | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         StringHelper::setThousandsSeparator($expectedResult); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getThousandsSeparator(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGetCurrencyCode() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $localeconv = localeconv(); | 
					
						
							| 
									
										
										
										
											2016-12-22 14:43:37 +00:00
										 |  |  |         $expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol'] : '$')); | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getCurrencyCode(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSetCurrencyCode() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = '£'; | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         StringHelper::setCurrencyCode($expectedResult); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-26 06:39:29 +00:00
										 |  |  |         $result = StringHelper::getCurrencyCode(); | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2015-05-17 13:00:02 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-09-09 10:29:08 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testControlCharacterPHP2OOXML() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = 'foo_x000B_bar'; | 
					
						
							|  |  |  |         $result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2017-09-09 10:29:08 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testControlCharacterOOXML2PHP() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = 'foo' . chr(11) . 'bar'; | 
					
						
							|  |  |  |         $result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2017-09-09 10:29:08 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testSYLKtoUTF8() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $expectedResult = 'foo' . chr(11) . 'bar'; | 
					
						
							|  |  |  |         $result = StringHelper::SYLKtoUTF8("foo\x1B ;bar"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-20 05:55:42 +00:00
										 |  |  |         self::assertEquals($expectedResult, $result); | 
					
						
							| 
									
										
										
										
											2017-09-09 10:29:08 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-06-18 20:35:21 +00:00
										 |  |  | } |