bac567fd5fb7fb81d5e4ab266c420b05f4421b99
[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\Dumper\FileDumper;
16 use Symfony\Component\Translation\MessageCatalogue;
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         @unlink($tempDir.'/messages.en.concrete');
33     }
34
35     /**
36      * @group legacy
37      */
38     public function testDumpBackupsFileIfExisting()
39     {
40         $tempDir = sys_get_temp_dir();
41         $file = $tempDir.'/messages.en.concrete';
42         $backupFile = $file.'~';
43
44         @touch($file);
45
46         $catalogue = new MessageCatalogue('en');
47         $catalogue->add(array('foo' => 'bar'));
48
49         $dumper = new ConcreteFileDumper();
50         $dumper->dump($catalogue, array('path' => $tempDir));
51
52         $this->assertFileExists($backupFile);
53
54         @unlink($file);
55         @unlink($backupFile);
56     }
57
58     public function testDumpCreatesNestedDirectoriesAndFile()
59     {
60         $tempDir = sys_get_temp_dir();
61         $translationsDir = $tempDir.'/test/translations';
62         $file = $translationsDir.'/messages.en.concrete';
63
64         $catalogue = new MessageCatalogue('en');
65         $catalogue->add(array('foo' => 'bar'));
66
67         $dumper = new ConcreteFileDumper();
68         $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%');
69         $dumper->dump($catalogue, array('path' => $tempDir));
70
71         $this->assertFileExists($file);
72
73         @unlink($file);
74         @rmdir($translationsDir);
75     }
76 }
77
78 class ConcreteFileDumper extends FileDumper
79 {
80     public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
81     {
82         return '';
83     }
84
85     protected function getExtension()
86     {
87         return 'concrete';
88     }
89 }