b8065cb74c86d7950d4598cdbf87ad74075bec4f
[yaffs-website] / vendor / symfony / translation / Tests / Dumper / FileDumperTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\Translation\Tests\Dumper;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\MessageCatalogue;
16 use Symfony\Component\Translation\Dumper\FileDumper;
17
18 class FileDumperTest extends TestCase
19 {
20     public function testDump()
21     {
22         $tempDir = sys_get_temp_dir();
23
24         $catalogue = new MessageCatalogue('en');
25         $catalogue->add(array('foo' => 'bar'));
26
27         $dumper = new ConcreteFileDumper();
28         $dumper->dump($catalogue, array('path' => $tempDir));
29
30         $this->assertFileExists($tempDir.'/messages.en.concrete');
31     }
32
33     public function testDumpBackupsFileIfExisting()
34     {
35         $tempDir = sys_get_temp_dir();
36         $file = $tempDir.'/messages.en.concrete';
37         $backupFile = $file.'~';
38
39         @touch($file);
40
41         $catalogue = new MessageCatalogue('en');
42         $catalogue->add(array('foo' => 'bar'));
43
44         $dumper = new ConcreteFileDumper();
45         $dumper->dump($catalogue, array('path' => $tempDir));
46
47         $this->assertFileExists($backupFile);
48
49         @unlink($file);
50         @unlink($backupFile);
51     }
52
53     public function testDumpCreatesNestedDirectoriesAndFile()
54     {
55         $tempDir = sys_get_temp_dir();
56         $translationsDir = $tempDir.'/test/translations';
57         $file = $translationsDir.'/messages.en.concrete';
58
59         $catalogue = new MessageCatalogue('en');
60         $catalogue->add(array('foo' => 'bar'));
61
62         $dumper = new ConcreteFileDumper();
63         $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
64         $dumper->dump($catalogue, array('path' => $tempDir));
65
66         $this->assertFileExists($file);
67
68         @unlink($file);
69         @rmdir($translationsDir);
70     }
71 }
72
73 class ConcreteFileDumper extends FileDumper
74 {
75     public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
76     {
77         return '';
78     }
79
80     protected function getExtension()
81     {
82         return 'concrete';
83     }
84 }