Skip to content

Commit 343b6c0

Browse files
committed
Basic single output file tests
1 parent ddc5289 commit 343b6c0

35 files changed

+421
-547
lines changed

tests/GenerateTest.php

Lines changed: 0 additions & 547 deletions
This file was deleted.

tests/MultiFileGeneratorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use MartinLindhe\VueInternationalizationGenerator\Generator;
4+
5+
class MultiFileGeneratorTest extends \PHPUnit_Framework_TestCase
6+
{
7+
private $config = [];
8+
9+
private function evaluateMultiOutput($input, $expected, $format = 'es6', $withVendor = false)
10+
{
11+
$this->assertEquals(
12+
file_get_contents(__DIR__ . '/result/' . $expected),
13+
(new Generator($this->config))->generateMultiple(__DIR__ . '/input/' . $input, $format, $withVendor));
14+
15+
$this->config = [];
16+
}
17+
18+
public function testBasic()
19+
{
20+
$input = 'basic';
21+
$out = (new Generator($this->config))->generateMultiple(__DIR__ . '/input/' . $input);
22+
dd($out);
23+
}
24+
}

tests/SingleFileGeneratorTest.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
use MartinLindhe\VueInternationalizationGenerator\Generator;
4+
5+
class SingleFileGeneratorTest extends \PHPUnit_Framework_TestCase
6+
{
7+
private $config = [];
8+
9+
private function evaluateSingleOutput($input, $expected, $format = 'es6', $withVendor = false)
10+
{
11+
$this->assertEquals(
12+
file_get_contents(__DIR__ . '/result/' . $expected),
13+
(new Generator($this->config))->generateFromPath(__DIR__ . '/input/' . $input, $format, $withVendor));
14+
15+
$this->config = [];
16+
}
17+
18+
function testBasic()
19+
{
20+
$this->evaluateSingleOutput('basic', 'basic.js');
21+
}
22+
23+
function testBasicES6Format()
24+
{
25+
$this->evaluateSingleOutput('basic', 'basic_es6.js', 'es6');
26+
}
27+
28+
function testBasicWithUMDFormat()
29+
{
30+
$this->evaluateSingleOutput('basic', 'basic_umd.js', 'umd');
31+
}
32+
33+
function testBasicWithJSONFormat()
34+
{
35+
$this->evaluateSingleOutput('basic', 'basic.json', 'json');
36+
}
37+
38+
function testBasicMultipleInput()
39+
{
40+
$this->evaluateSingleOutput('multiple', 'basic_multi_in.js');
41+
}
42+
43+
function testInvalidFormat()
44+
{
45+
$format = 'es5';
46+
$inputDir = __DIR__ . '/input/basic';
47+
48+
try {
49+
(new Generator([]))->generateFromPath($inputDir, $format);
50+
} catch(RuntimeException $e) {
51+
$this->assertEquals('Invalid format passed: ' . $format, $e->getMessage());
52+
return;
53+
}
54+
55+
// FIXME $this->fail('No exception thrown for invalid format.');
56+
}
57+
58+
function testBasicWithTranslationString()
59+
{
60+
$this->evaluateSingleOutput('translation', 'translation.js');
61+
}
62+
63+
function testBasicWithEscapedTranslationString()
64+
{
65+
$this->evaluateSingleOutput('escaped', 'escaped.js');
66+
}
67+
68+
function testBasicWithVendor()
69+
{
70+
$this->evaluateSingleOutput('vendor', 'vendor.js', 'es6', true);
71+
}
72+
73+
function testBasicWithVuexLib()
74+
{
75+
$this->config = ['i18nLib' => 'vuex-i18n'];
76+
$this->evaluateSingleOutput('basic', 'basic_vuex.js');
77+
}
78+
79+
function testNamed()
80+
{
81+
$this->evaluateSingleOutput('named', 'named.js');
82+
}
83+
84+
function testNamedWithEscaped()
85+
{
86+
$this->evaluateSingleOutput('named_escaped', 'named_escaped.js');
87+
}
88+
89+
function testEscapedEscapeCharacter()
90+
{
91+
$this->evaluateSingleOutput('escaped_escape', 'escaped_escape.js');
92+
}
93+
94+
function testShouldNotTouchHtmlTags()
95+
{
96+
$this->evaluateSingleOutput('html', 'html.js');
97+
}
98+
99+
function testPluralization()
100+
{
101+
$this->evaluateSingleOutput('plural', 'plural.js');
102+
$this->config = ['i18nLib' => 'vuex-i18n'];
103+
$this->evaluateSingleOutput('plural', 'plural_vuex.js');
104+
}
105+
}

tests/input/basic/en/help.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
'yes' => 'yes',
4+
'no' => 'no',
5+
];

tests/input/basic/sv/help.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
'yes' => 'ja',
4+
'no' => 'nej',
5+
];

tests/input/escaped/en/main.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
'hello :name' => 'Hello :name',
4+
'time test 10!:00' => 'Time test 10!:00',
5+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
return [
3+
'test escaped' => 'escaped escape char not !!:touched',
4+
];

tests/input/html/en/help.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
return [
3+
'yes' => 'see <a href="mailto:mail@com">',
4+
'no' => 'see <a href=":link">',
5+
'maybe' => 'It is a <strong>Test</strong> ok!',
6+
];

tests/input/multiple/en/help.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
'yes' => 'yes',
4+
'no' => 'no',
5+
];

tests/input/multiple/en/main.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return [
3+
'up' => 'up',
4+
'down' => 'down',
5+
];

0 commit comments

Comments
 (0)