LocaleScannerTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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()
  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.'/de.txt');
  37. $this->filesystem->touch($this->directory.'/de_alias.txt');
  38. $this->filesystem->touch($this->directory.'/fr.txt');
  39. $this->filesystem->touch($this->directory.'/fr_alias.txt');
  40. $this->filesystem->touch($this->directory.'/root.txt');
  41. $this->filesystem->touch($this->directory.'/supplementalData.txt');
  42. $this->filesystem->touch($this->directory.'/supplementaldata.txt');
  43. $this->filesystem->touch($this->directory.'/meta.txt');
  44. file_put_contents($this->directory.'/en_alias.txt', 'en_alias{"%%ALIAS"{"en"}}');
  45. file_put_contents($this->directory.'/de_alias.txt', 'de_alias{"%%ALIAS"{"de"}}');
  46. file_put_contents($this->directory.'/fr_alias.txt', 'fr_alias{"%%ALIAS"{"fr"}}');
  47. }
  48. protected function tearDown()
  49. {
  50. $this->filesystem->remove($this->directory);
  51. }
  52. public function testScanLocales()
  53. {
  54. $sortedLocales = array('de', 'de_alias', 'en', 'en_alias', 'fr', 'fr_alias');
  55. $this->assertSame($sortedLocales, $this->scanner->scanLocales($this->directory));
  56. }
  57. public function testScanAliases()
  58. {
  59. $sortedAliases = array('de_alias' => 'de', 'en_alias' => 'en', 'fr_alias' => 'fr');
  60. $this->assertSame($sortedAliases, $this->scanner->scanAliases($this->directory));
  61. }
  62. }