CalculationSettingsTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PHPUnit\Framework\TestCase;
  6. class CalculationSettingsTest extends TestCase
  7. {
  8. /**
  9. * @var string
  10. */
  11. private $compatibilityMode;
  12. /**
  13. * @var string
  14. */
  15. private $locale;
  16. protected function setUp(): void
  17. {
  18. $this->compatibilityMode = Functions::getCompatibilityMode();
  19. $calculation = Calculation::getInstance();
  20. $this->locale = $calculation->getLocale();
  21. Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
  22. }
  23. protected function tearDown(): void
  24. {
  25. Functions::setCompatibilityMode($this->compatibilityMode);
  26. $calculation = Calculation::getInstance();
  27. $calculation->setLocale($this->locale);
  28. }
  29. /**
  30. * @dataProvider providerCanLoadAllSupportedLocales
  31. *
  32. * @param string $locale
  33. */
  34. public function testCanLoadAllSupportedLocales($locale): void
  35. {
  36. $calculation = Calculation::getInstance();
  37. self::assertTrue($calculation->setLocale($locale));
  38. }
  39. public function testInvalidLocaleReturnsFalse(): void
  40. {
  41. $calculation = Calculation::getInstance();
  42. self::assertFalse($calculation->setLocale('xx'));
  43. }
  44. public function providerCanLoadAllSupportedLocales(): array
  45. {
  46. return [
  47. ['bg'],
  48. ['cs'],
  49. ['da'],
  50. ['de'],
  51. ['en_us'],
  52. ['es'],
  53. ['fi'],
  54. ['fr'],
  55. ['hu'],
  56. ['it'],
  57. ['nl'],
  58. ['nb'],
  59. ['pl'],
  60. ['pt'],
  61. ['pt_br'],
  62. ['ru'],
  63. ['sv'],
  64. ['tr'],
  65. ];
  66. }
  67. }