Skip to content

Commit 6ab372d

Browse files
Tests added
1 parent 3e70283 commit 6ab372d

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

tests/Feature/LangJsCommandTest.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Illuminate\Support\Facades\Config;
4+
35
beforeEach(function () {
46
$this->testPath = __DIR__ . '/..';
57
$this->rootPath = __DIR__ . '/../..';
@@ -22,6 +24,15 @@
2224
});
2325

2426
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 () {
2536
$template = "$this->rootPath/src/Generators/Templates/langjs_with_messages.js";
2637
$this->assertFileExists($template);
2738

@@ -45,3 +56,116 @@
4556

4657
$this->cleanupOutputDirectory($this->testPath);
4758
});
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

Comments
 (0)