Skip to content

Commit 85238c4

Browse files
committed
added tests for #133
1 parent 4cf9130 commit 85238c4

15 files changed

Lines changed: 173 additions & 6 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"require-dev": {
2525
"illuminate/view": "*",
26-
"twig/twig": "*",
26+
"twig/twig": "^1.31",
2727
"twig/extensions": "*",
2828
"symfony/yaml": "~2"
2929
},

src/Utils/PhpFunctionsScanner.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public function getFunctions(array $constants = [])
148148
protected function parsePhpComment($value)
149149
{
150150
$result = null;
151+
151152
if ($this->extractComments !== false) {
152153
if ($value[0] === '#') {
153154
$value = substr($value, 1);
@@ -156,21 +157,23 @@ protected function parsePhpComment($value)
156157
} else {
157158
$value = substr($value, 2, -2);
158159
}
160+
159161
$value = trim($value);
162+
160163
if ($value !== '') {
161-
if ($this->extractComments === '' || strpos($value, $this->extractComments) === 0) {
162-
$result = $value;
163-
}
164-
elseif (is_array($this->extractComments)) {
164+
if (is_array($this->extractComments)) {
165165
foreach ($this->extractComments as $string) {
166166
if (strpos($value, $string) === 0) {
167167
$result = $value;
168168
break;
169169
}
170170
}
171+
} elseif ($this->extractComments === '' || strpos($value, $this->extractComments) === 0) {
172+
$result = $value;
171173
}
172174
}
173175
}
176+
174177
return $result;
175178
}
176179
}

tests/AssetsTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function testPhpCode2()
288288
{
289289
$translations = static::get('phpcode2/input', 'PhpCode', [
290290
'constants' => [
291-
'CONTEXT' => 'my-context'
291+
'CONTEXT' => 'my-context',
292292
]
293293
]);
294294
$countTranslations = 9;
@@ -323,6 +323,44 @@ public function testPhpCode2()
323323
$this->runTestFormat('phpcode2/YamlDictionary', $countTranslations);
324324
}
325325

326+
public function testPhpCode3()
327+
{
328+
$translations = static::get('phpcode3/input', 'PhpCode', [
329+
'extractComments' => ['allowed1', 'allowed2'],
330+
]);
331+
$countTranslations = 1;
332+
$countHeaders = 8;
333+
334+
$this->assertCount($countTranslations, $translations);
335+
$this->assertCount($countHeaders, $translations->getHeaders());
336+
$this->assertEquals(0, $translations->countTranslated());
337+
338+
self::saveContent($translations, 'phpcode3/Po');
339+
$this->assertContent($translations, 'phpcode3/Po');
340+
$this->assertContent($translations, 'phpcode3/Mo');
341+
$this->assertContent($translations, 'phpcode3/PhpArray');
342+
$this->assertContent($translations, 'phpcode3/Jed');
343+
$this->assertContent($translations, 'phpcode3/Json');
344+
$this->assertContent($translations, 'phpcode3/JsonDictionary');
345+
$this->assertContent($translations, 'phpcode3/Csv');
346+
$this->assertContent($translations, 'phpcode3/CsvDictionary');
347+
$this->assertContent($translations, 'phpcode3/Xliff');
348+
$this->assertContent($translations, 'phpcode3/Yaml');
349+
$this->assertContent($translations, 'phpcode3/YamlDictionary');
350+
351+
$this->runTestFormat('phpcode3/Po', $countTranslations, $countHeaders);
352+
$this->runTestFormat('phpcode3/Mo', 0, $countHeaders);
353+
$this->runTestFormat('phpcode3/PhpArray', $countTranslations, $countHeaders);
354+
$this->runTestFormat('phpcode3/Jed', $countTranslations, 10);
355+
$this->runTestFormat('phpcode3/Xliff', $countTranslations, $countHeaders);
356+
$this->runTestFormat('phpcode3/Json', $countTranslations, $countHeaders);
357+
$this->runTestFormat('phpcode3/JsonDictionary', $countTranslations);
358+
$this->runTestFormat('phpcode3/Csv', $countTranslations, $countHeaders);
359+
$this->runTestFormat('phpcode3/CsvDictionary', $countTranslations);
360+
$this->runTestFormat('phpcode3/Yaml', $countTranslations, $countHeaders);
361+
$this->runTestFormat('phpcode3/YamlDictionary', $countTranslations);
362+
}
363+
326364
public function testTwig()
327365
{
328366
$translations = static::get('twig/input', 'Twig');

tests/assets/phpcode3/Csv.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
,,"Content-Transfer-Encoding: 8bit
2+
Content-Type: text/plain; charset=UTF-8
3+
Language:
4+
Language-Team:
5+
Last-Translator:
6+
MIME-Version: 1.0
7+
Project-Id-Version:
8+
Report-Msgid-Bugs-To:
9+
"
10+
,"Translation with comments",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Translation with comments",

tests/assets/phpcode3/Jed.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"messages": {
3+
"": {
4+
"domain": "messages",
5+
"lang": "en",
6+
"plural-forms": "nplurals=2; plural=(n != 1);"
7+
},
8+
"Translation with comments": [
9+
""
10+
]
11+
}
12+
}

tests/assets/phpcode3/Json.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"domain": null,
3+
"plural-forms": null,
4+
"messages": {
5+
"": {
6+
"": [
7+
"Content-Transfer-Encoding: 8bit\nContent-Type: text\/plain; charset=UTF-8\nLanguage: \nLanguage-Team: \nLast-Translator: \nMIME-Version: 1.0\nProject-Id-Version: \nReport-Msgid-Bugs-To: \n"
8+
],
9+
"Translation with comments": [
10+
""
11+
]
12+
}
13+
}
14+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Translation with comments": ""
3+
}

tests/assets/phpcode3/Mo.mo

225 Bytes
Binary file not shown.

tests/assets/phpcode3/PhpArray.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php return array (
2+
'domain' => NULL,
3+
'plural-forms' => NULL,
4+
'messages' =>
5+
array (
6+
'' =>
7+
array (
8+
'' =>
9+
array (
10+
0 => 'Content-Transfer-Encoding: 8bit
11+
Content-Type: text/plain; charset=UTF-8
12+
Language:
13+
Language-Team:
14+
Last-Translator:
15+
MIME-Version: 1.0
16+
Project-Id-Version:
17+
Report-Msgid-Bugs-To:
18+
',
19+
),
20+
'Translation with comments' =>
21+
array (
22+
0 => '',
23+
),
24+
),
25+
),
26+
);

0 commit comments

Comments
 (0)