/src/Symfony/Component/Intl/Tests/Data/Util/LocaleScannerTest.php

https://github.com/FabienD/symfony · PHP · 90 lines · 56 code · 17 blank · 17 comment · 0 complexity · dea20a99a75e3d0455253d467ec973e7 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Intl\Tests\Data\Util;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Filesystem\Filesystem;
  13. use Symfony\Component\Intl\Data\Util\LocaleScanner;
  14. /**
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. */
  17. class LocaleScannerTest extends TestCase
  18. {
  19. private $directory;
  20. /**
  21. * @var Filesystem
  22. */
  23. private $filesystem;
  24. /**
  25. * @var LocaleScanner
  26. */
  27. private $scanner;
  28. protected function setUp(): void
  29. {
  30. $this->directory = sys_get_temp_dir().'/LocaleScannerTest/'.mt_rand(1000, 9999);
  31. $this->filesystem = new Filesystem();
  32. $this->scanner = new LocaleScanner();
  33. $this->filesystem->mkdir($this->directory);
  34. $this->filesystem->touch($this->directory.'/en.txt');
  35. $this->filesystem->touch($this->directory.'/en_alias.txt');
  36. $this->filesystem->touch($this->directory.'/en_child.txt');
  37. $this->filesystem->touch($this->directory.'/de.txt');
  38. $this->filesystem->touch($this->directory.'/de_alias.txt');
  39. $this->filesystem->touch($this->directory.'/de_child.txt');
  40. $this->filesystem->touch($this->directory.'/fr.txt');
  41. $this->filesystem->touch($this->directory.'/fr_alias.txt');
  42. $this->filesystem->touch($this->directory.'/fr_child.txt');
  43. $this->filesystem->touch($this->directory.'/root.txt');
  44. $this->filesystem->touch($this->directory.'/supplementalData.txt');
  45. $this->filesystem->touch($this->directory.'/supplementaldata.txt');
  46. $this->filesystem->touch($this->directory.'/meta.txt');
  47. file_put_contents($this->directory.'/en_alias.txt', 'en_alias{"%%ALIAS"{"en"}}');
  48. file_put_contents($this->directory.'/de_alias.txt', 'de_alias{"%%ALIAS"{"de"}}');
  49. file_put_contents($this->directory.'/fr_alias.txt', 'fr_alias{"%%ALIAS"{"fr"}}');
  50. file_put_contents($this->directory.'/en_child.txt', 'en_GB{%%Parent{"en"}}');
  51. file_put_contents($this->directory.'/de_child.txt', 'en_GB{%%Parent{"de"}}');
  52. file_put_contents($this->directory.'/fr_child.txt', 'en_GB{%%Parent{"fr"}}');
  53. }
  54. protected function tearDown(): void
  55. {
  56. $this->filesystem->remove($this->directory);
  57. }
  58. public function testScanLocales()
  59. {
  60. $sortedLocales = ['de', 'de_alias', 'de_child', 'en', 'en_alias', 'en_child', 'fr', 'fr_alias', 'fr_child'];
  61. $this->assertSame($sortedLocales, $this->scanner->scanLocales($this->directory));
  62. }
  63. public function testScanAliases()
  64. {
  65. $sortedAliases = ['de_alias' => 'de', 'en_alias' => 'en', 'fr_alias' => 'fr'];
  66. $this->assertSame($sortedAliases, $this->scanner->scanAliases($this->directory));
  67. }
  68. public function testScanParents()
  69. {
  70. $sortedParents = ['de_child' => 'de', 'en_child' => 'en', 'fr_child' => 'fr'];
  71. $this->assertSame($sortedParents, $this->scanner->scanParents($this->directory));
  72. }
  73. }