LocaleGeneratorTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
  4. use PhpOffice\PhpSpreadsheetInfra\LocaleGenerator;
  5. use PHPUnit\Framework\TestCase;
  6. use ReflectionClass;
  7. class LocaleGeneratorTest extends TestCase
  8. {
  9. public function testLocaleGenerator(): void
  10. {
  11. $directory = realpath(__DIR__ . '/../../src/PhpSpreadsheet/Calculation/locale/') ?: '';
  12. self::assertNotEquals('', $directory);
  13. $phpSpreadsheetFunctionsProperty = (new ReflectionClass(Calculation::class))
  14. ->getProperty('phpSpreadsheetFunctions');
  15. $phpSpreadsheetFunctionsProperty->setAccessible(true);
  16. $phpSpreadsheetFunctions = $phpSpreadsheetFunctionsProperty->getValue();
  17. $localeGenerator = new LocaleGenerator(
  18. $directory . DIRECTORY_SEPARATOR,
  19. 'Translations.xlsx',
  20. $phpSpreadsheetFunctions
  21. );
  22. $localeGenerator->generateLocales();
  23. $testLocales = [
  24. 'bg',
  25. 'cs',
  26. 'da',
  27. 'de',
  28. 'en',
  29. 'es',
  30. 'fi',
  31. 'fr',
  32. 'hu',
  33. 'it',
  34. 'nb',
  35. 'nl',
  36. 'pl',
  37. 'pt',
  38. 'ru',
  39. 'sv',
  40. 'tr',
  41. ];
  42. $count = count(glob($directory . DIRECTORY_SEPARATOR . '*') ?: []) - 1; // exclude Translations.xlsx
  43. self::assertCount($count, $testLocales);
  44. $testLocales[] = 'pt_br';
  45. $testLocales[] = 'en_uk';
  46. $noconfig = ['en'];
  47. $nofunctions = ['en', 'en_uk'];
  48. foreach ($testLocales as $originalLocale) {
  49. $locale = str_replace('_', DIRECTORY_SEPARATOR, $originalLocale);
  50. $path = $directory . DIRECTORY_SEPARATOR . $locale;
  51. if (in_array($originalLocale, $noconfig, true)) {
  52. self::assertFileDoesNotExist($path . DIRECTORY_SEPARATOR . 'config');
  53. } else {
  54. self::assertFileExists($path . DIRECTORY_SEPARATOR . 'config');
  55. }
  56. if (in_array($originalLocale, $nofunctions, true)) {
  57. self::assertFileDoesNotExist($path . DIRECTORY_SEPARATOR . 'functions');
  58. } else {
  59. self::assertFileExists($path . DIRECTORY_SEPARATOR . 'functions');
  60. }
  61. }
  62. }
  63. }