1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,90 +0,0 @@ |
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(['foo' => 'bar']); |
|
26 |
- |
|
27 |
- $dumper = new ConcreteFileDumper(); |
|
28 |
- $dumper->dump($catalogue, ['path' => $tempDir]); |
|
29 |
- |
|
30 |
- $this->assertFileExists($tempDir.'/messages.en.concrete'); |
|
31 |
- |
|
32 |
- @unlink($tempDir.'/messages.en.concrete'); |
|
33 |
- } |
|
34 |
- |
|
35 |
- public function testDumpIntl() |
|
36 |
- { |
|
37 |
- $tempDir = sys_get_temp_dir(); |
|
38 |
- |
|
39 |
- $catalogue = new MessageCatalogue('en'); |
|
40 |
- $catalogue->add(['foo' => 'bar'], 'd1'); |
|
41 |
- $catalogue->add(['bar' => 'foo'], 'd1+intl-icu'); |
|
42 |
- $catalogue->add(['bar' => 'foo'], 'd2+intl-icu'); |
|
43 |
- |
|
44 |
- $dumper = new ConcreteFileDumper(); |
|
45 |
- @unlink($tempDir.'/d2.en.concrete'); |
|
46 |
- $dumper->dump($catalogue, ['path' => $tempDir]); |
|
47 |
- |
|
48 |
- $this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar'); |
|
49 |
- @unlink($tempDir.'/d1.en.concrete'); |
|
50 |
- |
|
51 |
- $this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo'); |
|
52 |
- @unlink($tempDir.'/d1+intl-icu.en.concrete'); |
|
53 |
- |
|
54 |
- $this->assertFileNotExists($tempDir.'/d2.en.concrete'); |
|
55 |
- $this->assertStringEqualsFile($tempDir.'/d2+intl-icu.en.concrete', 'bar=foo'); |
|
56 |
- @unlink($tempDir.'/d2+intl-icu.en.concrete'); |
|
57 |
- } |
|
58 |
- |
|
59 |
- public function testDumpCreatesNestedDirectoriesAndFile() |
|
60 |
- { |
|
61 |
- $tempDir = sys_get_temp_dir(); |
|
62 |
- $translationsDir = $tempDir.'/test/translations'; |
|
63 |
- $file = $translationsDir.'/messages.en.concrete'; |
|
64 |
- |
|
65 |
- $catalogue = new MessageCatalogue('en'); |
|
66 |
- $catalogue->add(['foo' => 'bar']); |
|
67 |
- |
|
68 |
- $dumper = new ConcreteFileDumper(); |
|
69 |
- $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%'); |
|
70 |
- $dumper->dump($catalogue, ['path' => $tempDir]); |
|
71 |
- |
|
72 |
- $this->assertFileExists($file); |
|
73 |
- |
|
74 |
- @unlink($file); |
|
75 |
- @rmdir($translationsDir); |
|
76 |
- } |
|
77 |
-} |
|
78 |
- |
|
79 |
-class ConcreteFileDumper extends FileDumper |
|
80 |
-{ |
|
81 |
- public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = []) |
|
82 |
- { |
|
83 |
- return http_build_query($messages->all($domain), '', '&'); |
|
84 |
- } |
|
85 |
- |
|
86 |
- protected function getExtension() |
|
87 |
- { |
|
88 |
- return 'concrete'; |
|
89 |
- } |
|
90 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,90 @@ |
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(['foo' => 'bar']); |
|
26 |
+ |
|
27 |
+ $dumper = new ConcreteFileDumper(); |
|
28 |
+ $dumper->dump($catalogue, ['path' => $tempDir]); |
|
29 |
+ |
|
30 |
+ $this->assertFileExists($tempDir.'/messages.en.concrete'); |
|
31 |
+ |
|
32 |
+ @unlink($tempDir.'/messages.en.concrete'); |
|
33 |
+ } |
|
34 |
+ |
|
35 |
+ public function testDumpIntl() |
|
36 |
+ { |
|
37 |
+ $tempDir = sys_get_temp_dir(); |
|
38 |
+ |
|
39 |
+ $catalogue = new MessageCatalogue('en'); |
|
40 |
+ $catalogue->add(['foo' => 'bar'], 'd1'); |
|
41 |
+ $catalogue->add(['bar' => 'foo'], 'd1+intl-icu'); |
|
42 |
+ $catalogue->add(['bar' => 'foo'], 'd2+intl-icu'); |
|
43 |
+ |
|
44 |
+ $dumper = new ConcreteFileDumper(); |
|
45 |
+ @unlink($tempDir.'/d2.en.concrete'); |
|
46 |
+ $dumper->dump($catalogue, ['path' => $tempDir]); |
|
47 |
+ |
|
48 |
+ $this->assertStringEqualsFile($tempDir.'/d1.en.concrete', 'foo=bar'); |
|
49 |
+ @unlink($tempDir.'/d1.en.concrete'); |
|
50 |
+ |
|
51 |
+ $this->assertStringEqualsFile($tempDir.'/d1+intl-icu.en.concrete', 'bar=foo'); |
|
52 |
+ @unlink($tempDir.'/d1+intl-icu.en.concrete'); |
|
53 |
+ |
|
54 |
+ $this->assertFileNotExists($tempDir.'/d2.en.concrete'); |
|
55 |
+ $this->assertStringEqualsFile($tempDir.'/d2+intl-icu.en.concrete', 'bar=foo'); |
|
56 |
+ @unlink($tempDir.'/d2+intl-icu.en.concrete'); |
|
57 |
+ } |
|
58 |
+ |
|
59 |
+ public function testDumpCreatesNestedDirectoriesAndFile() |
|
60 |
+ { |
|
61 |
+ $tempDir = sys_get_temp_dir(); |
|
62 |
+ $translationsDir = $tempDir.'/test/translations'; |
|
63 |
+ $file = $translationsDir.'/messages.en.concrete'; |
|
64 |
+ |
|
65 |
+ $catalogue = new MessageCatalogue('en'); |
|
66 |
+ $catalogue->add(['foo' => 'bar']); |
|
67 |
+ |
|
68 |
+ $dumper = new ConcreteFileDumper(); |
|
69 |
+ $dumper->setRelativePathTemplate('test/translations/%domain%.%locale%.%extension%'); |
|
70 |
+ $dumper->dump($catalogue, ['path' => $tempDir]); |
|
71 |
+ |
|
72 |
+ $this->assertFileExists($file); |
|
73 |
+ |
|
74 |
+ @unlink($file); |
|
75 |
+ @rmdir($translationsDir); |
|
76 |
+ } |
|
77 |
+} |
|
78 |
+ |
|
79 |
+class ConcreteFileDumper extends FileDumper |
|
80 |
+{ |
|
81 |
+ public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = []) |
|
82 |
+ { |
|
83 |
+ return http_build_query($messages->all($domain), '', '&'); |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ protected function getExtension() |
|
87 |
+ { |
|
88 |
+ return 'concrete'; |
|
89 |
+ } |
|
90 |
+} |