mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-12-01 17:56:04 +03:00
Unit tests for Shared components,
and unit test adjustment for TextData locale formatting
This commit is contained in:
parent
f6af776b13
commit
ad0e299cf7
@ -324,6 +324,11 @@ class TextDataTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTEXT()
|
public function testTEXT()
|
||||||
{
|
{
|
||||||
|
// Enforce decimal and thousands separator values to UK/US, and currency code to USD
|
||||||
|
call_user_func(array('PHPExcel_Shared_String','setDecimalSeparator'),'.');
|
||||||
|
call_user_func(array('PHPExcel_Shared_String','setThousandsSeparator'),',');
|
||||||
|
call_user_func(array('PHPExcel_Shared_String','setCurrencyCode'),'$');
|
||||||
|
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$expectedResult = array_pop($args);
|
$expectedResult = array_pop($args);
|
||||||
$result = call_user_func_array(array('PHPExcel_Calculation_TextData','TEXTFORMAT'),$args);
|
$result = call_user_func_array(array('PHPExcel_Calculation_TextData','TEXTFORMAT'),$args);
|
||||||
|
58
unitTests/PHPExcel/Shared/CodePageTest.php
Normal file
58
unitTests/PHPExcel/Shared/CodePageTest.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once 'testDataFileIterator.php';
|
||||||
|
|
||||||
|
class CodePageTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
if (!defined('PHPEXCEL_ROOT'))
|
||||||
|
{
|
||||||
|
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
|
||||||
|
}
|
||||||
|
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider providerCodePage
|
||||||
|
*/
|
||||||
|
public function testCodePageNumberToName()
|
||||||
|
{
|
||||||
|
$args = func_get_args();
|
||||||
|
$expectedResult = array_pop($args);
|
||||||
|
$result = call_user_func_array(array('PHPExcel_Shared_CodePage','NumberToName'),$args);
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providerCodePage()
|
||||||
|
{
|
||||||
|
return new testDataFileIterator('rawTestData/Shared/CodePage.data');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNumberToNameWithInvalidCodePage()
|
||||||
|
{
|
||||||
|
$invalidCodePage = 12345;
|
||||||
|
try {
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_CodePage','NumberToName'),$invalidCodePage);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->assertEquals($e->getMessage(), 'Unknown codepage: 12345');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->fail('An expected exception has not been raised.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNumberToNameWithUnsupportedCodePage()
|
||||||
|
{
|
||||||
|
$unsupportedCodePage = 720;
|
||||||
|
try {
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_CodePage','NumberToName'),$unsupportedCodePage);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->assertEquals($e->getMessage(), 'Code page 720 not supported.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->fail('An expected exception has not been raised.');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
84
unitTests/PHPExcel/Shared/StringTest.php
Normal file
84
unitTests/PHPExcel/Shared/StringTest.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
require_once 'testDataFileIterator.php';
|
||||||
|
|
||||||
|
class StringTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
if (!defined('PHPEXCEL_ROOT'))
|
||||||
|
{
|
||||||
|
define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
|
||||||
|
}
|
||||||
|
require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetIsMbStringEnabled()
|
||||||
|
{
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getIsMbstringEnabled'));
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetIsIconvEnabled()
|
||||||
|
{
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getIsIconvEnabled'));
|
||||||
|
$this->assertTrue($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetDecimalSeparator()
|
||||||
|
{
|
||||||
|
$localeconv = localeconv();
|
||||||
|
|
||||||
|
$expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ',';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getDecimalSeparator'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetDecimalSeparator()
|
||||||
|
{
|
||||||
|
$expectedResult = ',';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','setDecimalSeparator'),$expectedResult);
|
||||||
|
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getDecimalSeparator'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetThousandsSeparator()
|
||||||
|
{
|
||||||
|
$localeconv = localeconv();
|
||||||
|
|
||||||
|
$expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ',';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getThousandsSeparator'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetThousandsSeparator()
|
||||||
|
{
|
||||||
|
$expectedResult = ' ';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','setThousandsSeparator'),$expectedResult);
|
||||||
|
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getThousandsSeparator'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetCurrencyCode()
|
||||||
|
{
|
||||||
|
$localeconv = localeconv();
|
||||||
|
|
||||||
|
$expectedResult = (!empty($localeconv['currency_symbol'])) ? $localeconv['currency_symbol'] : '$';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getCurrencyCode'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetCurrencyCode()
|
||||||
|
{
|
||||||
|
$expectedResult = '£';
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','setCurrencyCode'),$expectedResult);
|
||||||
|
|
||||||
|
$result = call_user_func(array('PHPExcel_Shared_String','getCurrencyCode'));
|
||||||
|
$this->assertEquals($expectedResult, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
unitTests/rawTestData/Shared/CodePage.data
Normal file
43
unitTests/rawTestData/Shared/CodePage.data
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
367, "ASCII" // ASCII
|
||||||
|
437, "CP437" // OEM US
|
||||||
|
737, "CP737" // OEM Greek
|
||||||
|
775, "CP775" // OEM Baltic
|
||||||
|
850, "CP850" // OEM Latin I
|
||||||
|
852, "CP852" // OEM Latin II (Central European)
|
||||||
|
855, "CP855" // OEM Cyrillic
|
||||||
|
857, "CP857" // OEM Turkish
|
||||||
|
858, "CP858" // OEM Multilingual Latin I with Euro
|
||||||
|
860, "CP860" // OEM Portugese
|
||||||
|
861, "CP861" // OEM Icelandic
|
||||||
|
862, "CP862" // OEM Hebrew
|
||||||
|
863, "CP863" // OEM Canadian (French)
|
||||||
|
864, "CP864" // OEM Arabic
|
||||||
|
865, "CP865" // OEM Nordic
|
||||||
|
866, "CP866" // OEM Cyrillic (Russian)
|
||||||
|
869, "CP869" // OEM Greek (Modern)
|
||||||
|
874, "CP874" // ANSI Thai
|
||||||
|
932, "CP932" // ANSI Japanese Shift-JIS
|
||||||
|
936, "CP936" // ANSI Chinese Simplified GBK
|
||||||
|
949, "CP949" // ANSI Korean (Wansung)
|
||||||
|
950, "CP950" // ANSI Chinese Traditional BIG5
|
||||||
|
1200, "UTF-16LE" // UTF-16 (BIFF8)
|
||||||
|
1250, "CP1250" // ANSI Latin II (Central European)
|
||||||
|
1251, "CP1251" // ANSI Cyrillic
|
||||||
|
0, "CP1252" // ANSI Latin I (BIFF4-BIFF7)
|
||||||
|
1252, "CP1252" // ANSI Latin I (BIFF4-BIFF7)
|
||||||
|
1253, "CP1253" // ANSI Greek
|
||||||
|
1254, "CP1254" // ANSI Turkish
|
||||||
|
1255, "CP1255" // ANSI Hebrew
|
||||||
|
1256, "CP1256" // ANSI Arabic
|
||||||
|
1257, "CP1257" // ANSI Baltic
|
||||||
|
1258, "CP1258" // ANSI Vietnamese
|
||||||
|
1361, "CP1361" // ANSI Korean (Johab)
|
||||||
|
10000, "MAC" // Apple Roman
|
||||||
|
10006, "MACGREEK" // Macintosh Greek
|
||||||
|
10007, "MACCYRILLIC" // Macintosh Cyrillic
|
||||||
|
10029, "MACCENTRALEUROPE" // Macintosh Central Europe
|
||||||
|
10079, "MACICELAND" // Macintosh Icelandic
|
||||||
|
10081, "MACTURKISH" // Macintosh Turkish
|
||||||
|
32768, "MAC" // Apple Roman
|
||||||
|
65000, "UTF-7" // Unicode (UTF-7)
|
||||||
|
65001, "UTF-8" // Unicode (UTF-8)
|
Loading…
Reference in New Issue
Block a user