AddressInternationalTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  4. use PhpOffice\PhpSpreadsheet\Settings;
  5. class AddressInternationalTest extends AllSetupTeardown
  6. {
  7. /** @var string */
  8. private $locale;
  9. protected function setUp(): void
  10. {
  11. parent::setUp();
  12. $this->locale = Settings::getLocale();
  13. }
  14. protected function tearDown(): void
  15. {
  16. Settings::setLocale($this->locale);
  17. // CompatibilityMode is restored in parent
  18. parent::tearDown();
  19. }
  20. /**
  21. * @dataProvider providerInternational
  22. */
  23. public function testR1C1International(string $locale, string $r, string $c): void
  24. {
  25. if ($locale !== '') {
  26. Settings::setLocale($locale);
  27. }
  28. $sheet = $this->getSheet();
  29. $sheet->getCell('A1')->setValue('=LEFT(ADDRESS(1,1,1,0),1)');
  30. $sheet->getCell('A2')->setValue('=MID(ADDRESS(1,1,1,0),3,1)');
  31. self::assertSame($r, $sheet->getCell('A1')->getCalculatedValue());
  32. self::assertSame($c, $sheet->getCell('A2')->getCalculatedValue());
  33. }
  34. public function providerInternational(): array
  35. {
  36. return [
  37. 'Default' => ['', 'R', 'C'],
  38. 'English' => ['en', 'R', 'C'],
  39. 'French' => ['fr', 'L', 'C'],
  40. 'German' => ['de', 'Z', 'S'],
  41. 'Made-up' => ['xx', 'R', 'C'],
  42. 'Spanish' => ['es', 'F', 'C'],
  43. 'Bulgarian' => ['bg', 'R', 'C'],
  44. 'Czech' => ['cs', 'R', 'C'], // maybe should be R/S
  45. 'Polish' => ['pl', 'R', 'C'], // maybe should be W/K
  46. 'Turkish' => ['tr', 'R', 'C'],
  47. ];
  48. }
  49. /**
  50. * @dataProvider providerCompatibility
  51. */
  52. public function testCompatibilityInternational(string $compatibilityMode, string $r, string $c): void
  53. {
  54. Functions::setCompatibilityMode($compatibilityMode);
  55. Settings::setLocale('de');
  56. $sheet = $this->getSheet();
  57. $sheet->getCell('A1')->setValue('=LEFT(ADDRESS(1,1,1,0),1)');
  58. $sheet->getCell('A2')->setValue('=MID(ADDRESS(1,1,1,0),3,1)');
  59. self::assertSame($r, $sheet->getCell('A1')->getCalculatedValue());
  60. self::assertSame($c, $sheet->getCell('A2')->getCalculatedValue());
  61. }
  62. public function providerCompatibility(): array
  63. {
  64. return [
  65. [Functions::COMPATIBILITY_EXCEL, 'Z', 'S'],
  66. [Functions::COMPATIBILITY_OPENOFFICE, 'R', 'C'],
  67. [Functions::COMPATIBILITY_GNUMERIC, 'R', 'C'],
  68. ];
  69. }
  70. }