CodePageTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. require_once 'testDataFileIterator.php';
  3. class CodePageTest extends PHPUnit_Framework_TestCase
  4. {
  5. public function setUp()
  6. {
  7. if (!defined('PHPEXCEL_ROOT')) {
  8. define('PHPEXCEL_ROOT', APPLICATION_PATH . '/');
  9. }
  10. require_once(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  11. }
  12. /**
  13. * @dataProvider providerCodePage
  14. */
  15. public function testCodePageNumberToName()
  16. {
  17. $args = func_get_args();
  18. $expectedResult = array_pop($args);
  19. $result = call_user_func_array(array('PHPExcel_Shared_CodePage','NumberToName'),$args);
  20. $this->assertEquals($expectedResult, $result);
  21. }
  22. public function providerCodePage()
  23. {
  24. return new testDataFileIterator('rawTestData/Shared/CodePage.data');
  25. }
  26. public function testNumberToNameWithInvalidCodePage()
  27. {
  28. $invalidCodePage = 12345;
  29. try {
  30. $result = call_user_func(array('PHPExcel_Shared_CodePage','NumberToName'),$invalidCodePage);
  31. } catch (Exception $e) {
  32. $this->assertEquals($e->getMessage(), 'Unknown codepage: 12345');
  33. return;
  34. }
  35. $this->fail('An expected exception has not been raised.');
  36. }
  37. public function testNumberToNameWithUnsupportedCodePage()
  38. {
  39. $unsupportedCodePage = 720;
  40. try {
  41. $result = call_user_func(array('PHPExcel_Shared_CodePage','NumberToName'),$unsupportedCodePage);
  42. } catch (Exception $e) {
  43. $this->assertEquals($e->getMessage(), 'Code page 720 not supported.');
  44. return;
  45. }
  46. $this->fail('An expected exception has not been raised.');
  47. }
  48. }