Nenhuma Descrição

FileDumperTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Translation\Tests\Dumper;
  11. use Symfony\Component\Translation\MessageCatalogue;
  12. use Symfony\Component\Translation\Dumper\FileDumper;
  13. class FileDumperTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testDump()
  16. {
  17. $tempDir = sys_get_temp_dir();
  18. $catalogue = new MessageCatalogue('en');
  19. $catalogue->add(array('foo' => 'bar'));
  20. $dumper = new ConcreteFileDumper();
  21. $dumper->dump($catalogue, array('path' => $tempDir));
  22. $this->assertFileExists($tempDir.'/messages.en.concrete');
  23. }
  24. /**
  25. * @group legacy
  26. */
  27. public function testDumpBackupsFileIfExisting()
  28. {
  29. $tempDir = sys_get_temp_dir();
  30. $file = $tempDir.'/messages.en.concrete';
  31. $backupFile = $file.'~';
  32. @touch($file);
  33. $catalogue = new MessageCatalogue('en');
  34. $catalogue->add(array('foo' => 'bar'));
  35. $dumper = new ConcreteFileDumper();
  36. $dumper->dump($catalogue, array('path' => $tempDir));
  37. $this->assertFileExists($backupFile);
  38. @unlink($file);
  39. @unlink($backupFile);
  40. }
  41. public function testDumpCreatesNestedDirectoriesAndFile()
  42. {
  43. $tempDir = sys_get_temp_dir();
  44. $translationsDir = $tempDir.'/test/translations';
  45. $file = $translationsDir.'/messages.en.concrete';
  46. $catalogue = new MessageCatalogue('en');
  47. $catalogue->add(array('foo' => 'bar'));
  48. $dumper = new ConcreteFileDumper();
  49. $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
  50. $dumper->dump($catalogue, array('path' => $tempDir));
  51. $this->assertFileExists($file);
  52. @unlink($file);
  53. @rmdir($translationsDir);
  54. }
  55. }
  56. class ConcreteFileDumper extends FileDumper
  57. {
  58. public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
  59. {
  60. return '';
  61. }
  62. protected function getExtension()
  63. {
  64. return 'concrete';
  65. }
  66. }