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\Exception;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
|
2017-11-08 15:48:01 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-08-14 04:08:43 +00:00
|
|
|
|
2017-11-08 15:48:01 +00:00
|
|
|
class CodePageTest extends TestCase
|
2012-06-18 20:35:21 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider providerCodePage
|
2017-01-23 05:49:10 +00:00
|
|
|
*
|
|
|
|
* @param mixed $expectedResult
|
2012-06-18 20:35:21 +00:00
|
|
|
*/
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testCodePageNumberToName($expectedResult, ...$args): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
2017-01-23 05:49:10 +00:00
|
|
|
$result = CodePage::numberToName(...$args);
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($expectedResult, $result);
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-18 20:35:21 +00:00
|
|
|
|
|
|
|
public function providerCodePage()
|
|
|
|
{
|
2020-05-17 09:35:55 +00:00
|
|
|
return require 'tests/data/Shared/CodePage.php';
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-18 20:35:21 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testNumberToNameWithInvalidCodePage(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$invalidCodePage = 12345;
|
2017-10-01 11:07:04 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
try {
|
2016-08-26 06:39:29 +00:00
|
|
|
CodePage::numberToName($invalidCodePage);
|
2016-08-14 04:08:43 +00:00
|
|
|
} catch (Exception $e) {
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($e->getMessage(), 'Unknown codepage: 12345');
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-18 04:49:57 +00:00
|
|
|
self::fail('An expected exception has not been raised.');
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-18 20:35:21 +00:00
|
|
|
|
2020-05-18 04:49:57 +00:00
|
|
|
public function testNumberToNameWithUnsupportedCodePage(): void
|
2015-05-17 13:00:02 +00:00
|
|
|
{
|
|
|
|
$unsupportedCodePage = 720;
|
2017-10-01 11:07:04 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
try {
|
2016-08-26 06:39:29 +00:00
|
|
|
CodePage::numberToName($unsupportedCodePage);
|
2016-08-14 04:08:43 +00:00
|
|
|
} catch (Exception $e) {
|
2017-09-20 05:55:42 +00:00
|
|
|
self::assertEquals($e->getMessage(), 'Code page 720 not supported.');
|
2016-08-16 15:33:57 +00:00
|
|
|
|
2015-05-17 13:00:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-05-18 04:49:57 +00:00
|
|
|
self::fail('An expected exception has not been raised.');
|
2015-05-17 13:00:02 +00:00
|
|
|
}
|
2012-06-18 20:35:21 +00:00
|
|
|
}
|