|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +use Illuminate\Support\Facades\Config; |
| 4 | + |
3 | 5 | beforeEach(function () { |
4 | 6 | $this->testPath = __DIR__ . '/..'; |
5 | 7 | $this->rootPath = __DIR__ . '/../..'; |
|
22 | 24 | }); |
23 | 25 |
|
24 | 26 | test('template should have handlebars', function () { |
| 27 | + $template = "$this->rootPath/src/Generators/Templates/messages.js"; |
| 28 | + $this->assertFileExists($template); |
| 29 | + |
| 30 | + $contents = file_get_contents($template); |
| 31 | + $this->assertNotEmpty($contents); |
| 32 | + $this->assertHasHandlebars('messages', $contents); |
| 33 | +}); |
| 34 | + |
| 35 | +test('template messages should have handlebars', function () { |
25 | 36 | $template = "$this->rootPath/src/Generators/Templates/langjs_with_messages.js"; |
26 | 37 | $this->assertFileExists($template); |
27 | 38 |
|
|
45 | 56 |
|
46 | 57 | $this->cleanupOutputDirectory($this->testPath); |
47 | 58 | }); |
| 59 | + |
| 60 | +test('all files should be converted', function () { |
| 61 | + $this->artisan('lang:js', ['target' => $this->outputFilePath, '--source' => $this->langPath]) |
| 62 | + ->assertExitCode(0); |
| 63 | + |
| 64 | + $this->assertFileExists($this->outputFilePath); |
| 65 | + |
| 66 | + $contents = file_get_contents($this->outputFilePath); |
| 67 | + |
| 68 | + $this->assertStringContainsString('gm8ft2hrrlq1u6m54we9udi', $contents); |
| 69 | + |
| 70 | + $this->assertStringNotContainsString('vendor.nonameinc.en.messages', $contents); |
| 71 | + $this->assertStringNotContainsString('vendor.nonameinc.es.messages', $contents); |
| 72 | + $this->assertStringNotContainsString('vendor.nonameinc.ht.messages', $contents); |
| 73 | + |
| 74 | + $this->assertStringContainsString('en.nonameinc::messages', $contents); |
| 75 | + $this->assertStringContainsString('es.nonameinc::messages', $contents); |
| 76 | + $this->assertStringContainsString('ht.nonameinc::messages', $contents); |
| 77 | + |
| 78 | + $this->assertStringContainsString('en.forum.thread', $contents); |
| 79 | + |
| 80 | + $this->cleanupOutputDirectory($this->testPath); |
| 81 | +}); |
| 82 | + |
| 83 | +test('selected files in config should be converted', function () { |
| 84 | + Config::set('localization-js.messages', ['messages']); |
| 85 | + |
| 86 | + $this->artisan('lang:js', ['target' => $this->outputFilePath, '--source' => $this->langPath]) |
| 87 | + ->assertExitCode(0); |
| 88 | + |
| 89 | + $this->assertFileExists($this->outputFilePath); |
| 90 | + |
| 91 | + $contents = file_get_contents($this->outputFilePath); |
| 92 | + |
| 93 | + $this->assertStringContainsString('en.messages', $contents); |
| 94 | + $this->assertStringNotContainsString('en.validation', $contents); |
| 95 | + |
| 96 | + $this->cleanupOutputDirectory($this->testPath); |
| 97 | +}); |
| 98 | + |
| 99 | +test('nested directory files in config should be converted', function () { |
| 100 | + Config::set('localization-js.messages', ['forum/thread']); |
| 101 | + |
| 102 | + $this->artisan('lang:js', ['target' => $this->outputFilePath, '--source' => $this->langPath]) |
| 103 | + ->assertExitCode(0); |
| 104 | + |
| 105 | + $this->assertFileExists($this->outputFilePath); |
| 106 | + |
| 107 | + $contents = file_get_contents($this->outputFilePath); |
| 108 | + |
| 109 | + $this->assertStringContainsString('en.forum.thread', $contents); |
| 110 | + |
| 111 | + $this->cleanupOutputDirectory($this->testPath); |
| 112 | +}); |
| 113 | + |
| 114 | +test('should use default output path from config', function () { |
| 115 | + $customOutputFilePath = "{$this->testPath}/output/lang-with-custom-path.js"; |
| 116 | + Config::set('localization-js.path', $customOutputFilePath); |
| 117 | + |
| 118 | + $this->artisan('lang:js') |
| 119 | + ->expectsOutputToContain('Created:') |
| 120 | + ->assertExitCode(0); |
| 121 | + |
| 122 | + $this->assertFileExists($customOutputFilePath); |
| 123 | + |
| 124 | + $template = "$this->rootPath/src/Generators/Templates/langjs_with_messages.js"; |
| 125 | + $this->assertFileExists($template); |
| 126 | + $this->assertFileNotEquals($template, $customOutputFilePath); |
| 127 | + |
| 128 | + $this->cleanupOutputDirectory($this->testPath); |
| 129 | +}); |
| 130 | + |
| 131 | +test('should ignore default output path from config if target argument exists', function () { |
| 132 | + $customOutputFilePath = "{$this->testPath}/output/lang-with-custom-path.js"; |
| 133 | + Config::set('localization-js.path', $customOutputFilePath); |
| 134 | + |
| 135 | + $this->artisan('lang:js', ['target' => $this->outputFilePath]) |
| 136 | + ->expectsOutputToContain('Created:') |
| 137 | + ->assertExitCode(0); |
| 138 | + |
| 139 | + $this->assertFileExists($this->outputFilePath); |
| 140 | + $this->assertFileDoesNotExist($customOutputFilePath); |
| 141 | + |
| 142 | + $template = "$this->rootPath/src/Generators/Templates/langjs_with_messages.js"; |
| 143 | + $this->assertFileExists($template); |
| 144 | + $this->assertFileNotEquals($template, $this->outputFilePath); |
| 145 | + |
| 146 | + $this->cleanupOutputDirectory($this->testPath); |
| 147 | +}); |
| 148 | + |
| 149 | +test('only messages should export', function () { |
| 150 | + $this->artisan('lang:js', ['target' => $this->outputFilePath, '--no-lib' => true]) |
| 151 | + ->assertExitCode(0); |
| 152 | + |
| 153 | + $this->assertFileExists($this->outputFilePath); |
| 154 | + |
| 155 | + $contents = file_get_contents($this->outputFilePath); |
| 156 | + $this->assertNotEmpty($contents); |
| 157 | + $this->assertHasNotHandlebars('messages', $contents); |
| 158 | + $this->cleanupOutputDirectory($this->testPath); |
| 159 | +}); |
| 160 | + |
| 161 | +test('only messages json should export', function () { |
| 162 | + $this->artisan('lang:js', ['target' => $this->outputFilePath, '--json' => true]) |
| 163 | + ->assertExitCode(0); |
| 164 | + |
| 165 | + $this->assertFileExists($this->outputFilePath); |
| 166 | + |
| 167 | + $contents = file_get_contents($this->outputFilePath); |
| 168 | + $this->assertNotEmpty($contents); |
| 169 | + $this->assertHasNotHandlebars('messages', $contents); |
| 170 | + $this->cleanupOutputDirectory($this->testPath); |
| 171 | +}); |
0 commit comments