Vous êtes connecté en tant que anonymous Se Deconnecter
Browse code

Application modulaire fonctionnelle !

Emmanuel ROY authored on 12/08/2019 15:10:25
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,218 +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\Command;
13
-
14
-use PHPUnit\Framework\TestCase;
15
-use Symfony\Component\Console\Application;
16
-use Symfony\Component\Console\Output\OutputInterface;
17
-use Symfony\Component\Console\Tester\CommandTester;
18
-use Symfony\Component\Translation\Command\XliffLintCommand;
19
-
20
-/**
21
- * Tests the XliffLintCommand.
22
- *
23
- * @author Javier Eguiluz <javier.eguiluz@gmail.com>
24
- */
25
-class XliffLintCommandTest extends TestCase
26
-{
27
-    private $files;
28
-
29
-    public function testLintCorrectFile()
30
-    {
31
-        $tester = $this->createCommandTester();
32
-        $filename = $this->createFile();
33
-
34
-        $tester->execute(
35
-            ['filename' => $filename],
36
-            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
37
-        );
38
-
39
-        $this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
40
-        $this->assertContains('OK', trim($tester->getDisplay()));
41
-    }
42
-
43
-    public function testLintCorrectFiles()
44
-    {
45
-        $tester = $this->createCommandTester();
46
-        $filename1 = $this->createFile();
47
-        $filename2 = $this->createFile();
48
-
49
-        $tester->execute(
50
-            ['filename' => [$filename1, $filename2]],
51
-            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
52
-        );
53
-
54
-        $this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
55
-        $this->assertContains('OK', trim($tester->getDisplay()));
56
-    }
57
-
58
-    /**
59
-     * @dataProvider provideStrictFilenames
60
-     */
61
-    public function testStrictFilenames($requireStrictFileNames, $fileNamePattern, $targetLanguage, $mustFail)
62
-    {
63
-        $tester = $this->createCommandTester($requireStrictFileNames);
64
-        $filename = $this->createFile('note', $targetLanguage, $fileNamePattern);
65
-
66
-        $tester->execute(
67
-            ['filename' => $filename],
68
-            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
69
-        );
70
-
71
-        $this->assertEquals($mustFail ? 1 : 0, $tester->getStatusCode());
72
-        $this->assertContains($mustFail ? '[WARNING] 0 XLIFF files have valid syntax and 1 contain errors.' : '[OK] All 1 XLIFF files contain valid syntax.', $tester->getDisplay());
73
-    }
74
-
75
-    public function testLintIncorrectXmlSyntax()
76
-    {
77
-        $tester = $this->createCommandTester();
78
-        $filename = $this->createFile('note <target>');
79
-
80
-        $tester->execute(['filename' => $filename], ['decorated' => false]);
81
-
82
-        $this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
83
-        $this->assertContains('Opening and ending tag mismatch: target line 6 and source', trim($tester->getDisplay()));
84
-    }
85
-
86
-    public function testLintIncorrectTargetLanguage()
87
-    {
88
-        $tester = $this->createCommandTester();
89
-        $filename = $this->createFile('note', 'es');
90
-
91
-        $tester->execute(['filename' => $filename], ['decorated' => false]);
92
-
93
-        $this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
94
-        $this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
95
-    }
96
-
97
-    public function testLintTargetLanguageIsCaseInsensitive()
98
-    {
99
-        $tester = $this->createCommandTester();
100
-        $filename = $this->createFile('note', 'zh-cn', 'messages.zh_CN.xlf');
101
-
102
-        $tester->execute(['filename' => $filename], ['decorated' => false]);
103
-
104
-        $this->assertEquals(0, $tester->getStatusCode());
105
-        $this->assertContains('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
106
-    }
107
-
108
-    /**
109
-     * @expectedException \RuntimeException
110
-     */
111
-    public function testLintFileNotReadable()
112
-    {
113
-        $tester = $this->createCommandTester();
114
-        $filename = $this->createFile();
115
-        unlink($filename);
116
-
117
-        $tester->execute(['filename' => $filename], ['decorated' => false]);
118
-    }
119
-
120
-    public function testGetHelp()
121
-    {
122
-        $command = new XliffLintCommand();
123
-        $expected = <<<EOF
124
-The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
125
-the first encountered syntax error.
126
-
127
-You can validates XLIFF contents passed from STDIN:
128
-
129
-  <info>cat filename | php %command.full_name%</info>
130
-
131
-You can also validate the syntax of a file:
132
-
133
-  <info>php %command.full_name% filename</info>
134
-
135
-Or of a whole directory:
136
-
137
-  <info>php %command.full_name% dirname</info>
138
-  <info>php %command.full_name% dirname --format=json</info>
139
-
140
-EOF;
141
-
142
-        $this->assertEquals($expected, $command->getHelp());
143
-    }
144
-
145
-    /**
146
-     * @return string Path to the new file
147
-     */
148
-    private function createFile($sourceContent = 'note', $targetLanguage = 'en', $fileNamePattern = 'messages.%locale%.xlf')
149
-    {
150
-        $xliffContent = <<<XLIFF
151
-<?xml version="1.0"?>
152
-<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
153
-    <file source-language="en" target-language="$targetLanguage" datatype="plaintext" original="file.ext">
154
-        <body>
155
-            <trans-unit id="note">
156
-                <source>$sourceContent</source>
157
-                <target>NOTE</target>
158
-            </trans-unit>
159
-        </body>
160
-    </file>
161
-</xliff>
162
-XLIFF;
163
-
164
-        $filename = sprintf('%s/translation-xliff-lint-test/%s', sys_get_temp_dir(), str_replace('%locale%', 'en', $fileNamePattern));
165
-        file_put_contents($filename, $xliffContent);
166
-
167
-        $this->files[] = $filename;
168
-
169
-        return $filename;
170
-    }
171
-
172
-    /**
173
-     * @return CommandTester
174
-     */
175
-    private function createCommandTester($requireStrictFileNames = true, $application = null)
176
-    {
177
-        if (!$application) {
178
-            $application = new Application();
179
-            $application->add(new XliffLintCommand(null, null, null, $requireStrictFileNames));
180
-        }
181
-
182
-        $command = $application->find('lint:xliff');
183
-
184
-        if ($application) {
185
-            $command->setApplication($application);
186
-        }
187
-
188
-        return new CommandTester($command);
189
-    }
190
-
191
-    protected function setUp()
192
-    {
193
-        $this->files = [];
194
-        @mkdir(sys_get_temp_dir().'/translation-xliff-lint-test');
195
-    }
196
-
197
-    protected function tearDown()
198
-    {
199
-        foreach ($this->files as $file) {
200
-            if (file_exists($file)) {
201
-                unlink($file);
202
-            }
203
-        }
204
-        rmdir(sys_get_temp_dir().'/translation-xliff-lint-test');
205
-    }
206
-
207
-    public function provideStrictFilenames()
208
-    {
209
-        yield [false, 'messages.%locale%.xlf', 'en', false];
210
-        yield [false, 'messages.%locale%.xlf', 'es', true];
211
-        yield [false, '%locale%.messages.xlf', 'en', false];
212
-        yield [false, '%locale%.messages.xlf', 'es', true];
213
-        yield [true, 'messages.%locale%.xlf', 'en', false];
214
-        yield [true, 'messages.%locale%.xlf', 'es', true];
215
-        yield [true, '%locale%.messages.xlf', 'en', true];
216
-        yield [true, '%locale%.messages.xlf', 'es', true];
217
-    }
218
-}
Browse code

initial commit

Emmanuel ROY authored on 09/08/2019 08:39:02
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,218 @@
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\Command;
13
+
14
+use PHPUnit\Framework\TestCase;
15
+use Symfony\Component\Console\Application;
16
+use Symfony\Component\Console\Output\OutputInterface;
17
+use Symfony\Component\Console\Tester\CommandTester;
18
+use Symfony\Component\Translation\Command\XliffLintCommand;
19
+
20
+/**
21
+ * Tests the XliffLintCommand.
22
+ *
23
+ * @author Javier Eguiluz <javier.eguiluz@gmail.com>
24
+ */
25
+class XliffLintCommandTest extends TestCase
26
+{
27
+    private $files;
28
+
29
+    public function testLintCorrectFile()
30
+    {
31
+        $tester = $this->createCommandTester();
32
+        $filename = $this->createFile();
33
+
34
+        $tester->execute(
35
+            ['filename' => $filename],
36
+            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
37
+        );
38
+
39
+        $this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
40
+        $this->assertContains('OK', trim($tester->getDisplay()));
41
+    }
42
+
43
+    public function testLintCorrectFiles()
44
+    {
45
+        $tester = $this->createCommandTester();
46
+        $filename1 = $this->createFile();
47
+        $filename2 = $this->createFile();
48
+
49
+        $tester->execute(
50
+            ['filename' => [$filename1, $filename2]],
51
+            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
52
+        );
53
+
54
+        $this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
55
+        $this->assertContains('OK', trim($tester->getDisplay()));
56
+    }
57
+
58
+    /**
59
+     * @dataProvider provideStrictFilenames
60
+     */
61
+    public function testStrictFilenames($requireStrictFileNames, $fileNamePattern, $targetLanguage, $mustFail)
62
+    {
63
+        $tester = $this->createCommandTester($requireStrictFileNames);
64
+        $filename = $this->createFile('note', $targetLanguage, $fileNamePattern);
65
+
66
+        $tester->execute(
67
+            ['filename' => $filename],
68
+            ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]
69
+        );
70
+
71
+        $this->assertEquals($mustFail ? 1 : 0, $tester->getStatusCode());
72
+        $this->assertContains($mustFail ? '[WARNING] 0 XLIFF files have valid syntax and 1 contain errors.' : '[OK] All 1 XLIFF files contain valid syntax.', $tester->getDisplay());
73
+    }
74
+
75
+    public function testLintIncorrectXmlSyntax()
76
+    {
77
+        $tester = $this->createCommandTester();
78
+        $filename = $this->createFile('note <target>');
79
+
80
+        $tester->execute(['filename' => $filename], ['decorated' => false]);
81
+
82
+        $this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
83
+        $this->assertContains('Opening and ending tag mismatch: target line 6 and source', trim($tester->getDisplay()));
84
+    }
85
+
86
+    public function testLintIncorrectTargetLanguage()
87
+    {
88
+        $tester = $this->createCommandTester();
89
+        $filename = $this->createFile('note', 'es');
90
+
91
+        $tester->execute(['filename' => $filename], ['decorated' => false]);
92
+
93
+        $this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
94
+        $this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
95
+    }
96
+
97
+    public function testLintTargetLanguageIsCaseInsensitive()
98
+    {
99
+        $tester = $this->createCommandTester();
100
+        $filename = $this->createFile('note', 'zh-cn', 'messages.zh_CN.xlf');
101
+
102
+        $tester->execute(['filename' => $filename], ['decorated' => false]);
103
+
104
+        $this->assertEquals(0, $tester->getStatusCode());
105
+        $this->assertContains('[OK] All 1 XLIFF files contain valid syntax.', trim($tester->getDisplay()));
106
+    }
107
+
108
+    /**
109
+     * @expectedException \RuntimeException
110
+     */
111
+    public function testLintFileNotReadable()
112
+    {
113
+        $tester = $this->createCommandTester();
114
+        $filename = $this->createFile();
115
+        unlink($filename);
116
+
117
+        $tester->execute(['filename' => $filename], ['decorated' => false]);
118
+    }
119
+
120
+    public function testGetHelp()
121
+    {
122
+        $command = new XliffLintCommand();
123
+        $expected = <<<EOF
124
+The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
125
+the first encountered syntax error.
126
+
127
+You can validates XLIFF contents passed from STDIN:
128
+
129
+  <info>cat filename | php %command.full_name%</info>
130
+
131
+You can also validate the syntax of a file:
132
+
133
+  <info>php %command.full_name% filename</info>
134
+
135
+Or of a whole directory:
136
+
137
+  <info>php %command.full_name% dirname</info>
138
+  <info>php %command.full_name% dirname --format=json</info>
139
+
140
+EOF;
141
+
142
+        $this->assertEquals($expected, $command->getHelp());
143
+    }
144
+
145
+    /**
146
+     * @return string Path to the new file
147
+     */
148
+    private function createFile($sourceContent = 'note', $targetLanguage = 'en', $fileNamePattern = 'messages.%locale%.xlf')
149
+    {
150
+        $xliffContent = <<<XLIFF
151
+<?xml version="1.0"?>
152
+<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
153
+    <file source-language="en" target-language="$targetLanguage" datatype="plaintext" original="file.ext">
154
+        <body>
155
+            <trans-unit id="note">
156
+                <source>$sourceContent</source>
157
+                <target>NOTE</target>
158
+            </trans-unit>
159
+        </body>
160
+    </file>
161
+</xliff>
162
+XLIFF;
163
+
164
+        $filename = sprintf('%s/translation-xliff-lint-test/%s', sys_get_temp_dir(), str_replace('%locale%', 'en', $fileNamePattern));
165
+        file_put_contents($filename, $xliffContent);
166
+
167
+        $this->files[] = $filename;
168
+
169
+        return $filename;
170
+    }
171
+
172
+    /**
173
+     * @return CommandTester
174
+     */
175
+    private function createCommandTester($requireStrictFileNames = true, $application = null)
176
+    {
177
+        if (!$application) {
178
+            $application = new Application();
179
+            $application->add(new XliffLintCommand(null, null, null, $requireStrictFileNames));
180
+        }
181
+
182
+        $command = $application->find('lint:xliff');
183
+
184
+        if ($application) {
185
+            $command->setApplication($application);
186
+        }
187
+
188
+        return new CommandTester($command);
189
+    }
190
+
191
+    protected function setUp()
192
+    {
193
+        $this->files = [];
194
+        @mkdir(sys_get_temp_dir().'/translation-xliff-lint-test');
195
+    }
196
+
197
+    protected function tearDown()
198
+    {
199
+        foreach ($this->files as $file) {
200
+            if (file_exists($file)) {
201
+                unlink($file);
202
+            }
203
+        }
204
+        rmdir(sys_get_temp_dir().'/translation-xliff-lint-test');
205
+    }
206
+
207
+    public function provideStrictFilenames()
208
+    {
209
+        yield [false, 'messages.%locale%.xlf', 'en', false];
210
+        yield [false, 'messages.%locale%.xlf', 'es', true];
211
+        yield [false, '%locale%.messages.xlf', 'en', false];
212
+        yield [false, '%locale%.messages.xlf', 'es', true];
213
+        yield [true, 'messages.%locale%.xlf', 'en', false];
214
+        yield [true, 'messages.%locale%.xlf', 'es', true];
215
+        yield [true, '%locale%.messages.xlf', 'en', true];
216
+        yield [true, '%locale%.messages.xlf', 'es', true];
217
+    }
218
+}