|
| 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 | +} |
0 commit comments