1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Shared; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\CodePage; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class CodePageTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @dataProvider providerCodePage |
13
|
|
|
* |
14
|
|
|
* @param mixed $expectedResult |
15
|
|
|
*/ |
16
|
|
|
public function testCodePageNumberToName($expectedResult, ...$args): void |
17
|
|
|
{ |
18
|
|
|
$result = CodePage::numberToName(...$args); |
|
|
|
|
19
|
|
|
self::assertEquals($expectedResult, $result); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function providerCodePage() |
23
|
|
|
{ |
24
|
|
|
return require 'tests/data/Shared/CodePage.php'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testCoverage(): void |
28
|
|
|
{ |
29
|
|
|
$covered = []; |
30
|
|
|
$expected = CodePage::getEncodings(); |
31
|
|
|
foreach ($expected as $key => $val) { |
32
|
|
|
$covered[$key] = 0; |
33
|
|
|
} |
34
|
|
|
$tests = $this->providerCodePage(); |
35
|
|
|
foreach ($tests as $test) { |
36
|
|
|
$covered[$test[1]] = 1; |
37
|
|
|
} |
38
|
|
|
foreach ($covered as $key => $val) { |
39
|
|
|
self::assertEquals(1, $val, "Codepage $key not tested"); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testNumberToNameWithInvalidCodePage(): void |
44
|
|
|
{ |
45
|
|
|
$invalidCodePage = 12345; |
46
|
|
|
|
47
|
|
|
try { |
48
|
|
|
CodePage::numberToName($invalidCodePage); |
49
|
|
|
} catch (Exception $e) { |
50
|
|
|
self::assertEquals($e->getMessage(), 'Unknown codepage: 12345'); |
51
|
|
|
|
52
|
|
|
return; |
53
|
|
|
} |
54
|
|
|
self::fail('An expected exception has not been raised.'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testNumberToNameWithUnsupportedCodePage(): void |
58
|
|
|
{ |
59
|
|
|
$unsupportedCodePage = 720; |
60
|
|
|
|
61
|
|
|
try { |
62
|
|
|
CodePage::numberToName($unsupportedCodePage); |
63
|
|
|
} catch (Exception $e) { |
64
|
|
|
self::assertEquals($e->getMessage(), 'Code page 720 not supported.'); |
65
|
|
|
|
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
self::fail('An expected exception has not been raised.'); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|