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