PhpSpreadsheet/tests/PhpSpreadsheetTests/Shared/StringHelperTest.php

101 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Shared;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase;
class StringHelperTest extends TestCase
{
2020-04-27 10:28:36 +00:00
protected function setUp(): void
{
parent::setUp();
// Reset Currency Code
StringHelper::setCurrencyCode(null);
}
2020-05-18 04:49:57 +00:00
public function testGetIsIconvEnabled(): void
2015-05-17 13:00:02 +00:00
{
$result = StringHelper::getIsIconvEnabled();
self::assertTrue($result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testGetDecimalSeparator(): void
2015-05-17 13:00:02 +00:00
{
$localeconv = localeconv();
$expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ',';
$result = StringHelper::getDecimalSeparator();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testSetDecimalSeparator(): void
2015-05-17 13:00:02 +00:00
{
$expectedResult = ',';
StringHelper::setDecimalSeparator($expectedResult);
2015-05-17 13:00:02 +00:00
$result = StringHelper::getDecimalSeparator();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testGetThousandsSeparator(): void
2015-05-17 13:00:02 +00:00
{
$localeconv = localeconv();
$expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ',';
$result = StringHelper::getThousandsSeparator();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testSetThousandsSeparator(): void
2015-05-17 13:00:02 +00:00
{
$expectedResult = ' ';
StringHelper::setThousandsSeparator($expectedResult);
2015-05-17 13:00:02 +00:00
$result = StringHelper::getThousandsSeparator();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testGetCurrencyCode(): void
2015-05-17 13:00:02 +00:00
{
$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'] : '$'));
$result = StringHelper::getCurrencyCode();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testSetCurrencyCode(): void
2015-05-17 13:00:02 +00:00
{
$expectedResult = '£';
StringHelper::setCurrencyCode($expectedResult);
2015-05-17 13:00:02 +00:00
$result = StringHelper::getCurrencyCode();
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testControlCharacterPHP2OOXML(): void
{
$expectedResult = 'foo_x000B_bar';
$result = StringHelper::controlCharacterPHP2OOXML('foo' . chr(11) . 'bar');
self::assertEquals($expectedResult, $result);
}
2020-05-18 04:49:57 +00:00
public function testControlCharacterOOXML2PHP(): void
{
$expectedResult = 'foo' . chr(11) . 'bar';
$result = StringHelper::controlCharacterOOXML2PHP('foo_x000B_bar');
self::assertEquals($expectedResult, $result);
}
2020-05-18 04:49:57 +00:00
public function testSYLKtoUTF8(): void
{
$expectedResult = 'foo' . chr(11) . 'bar';
$result = StringHelper::SYLKtoUTF8("foo\x1B ;bar");
self::assertEquals($expectedResult, $result);
}
}