-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathLocalizatorTest.php
208 lines (168 loc) · 6.76 KB
/
LocalizatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
namespace Amirami\Localizator\Tests;
class LocalizatorTest extends TestCase
{
/**
* @return void
*/
public function testLocalizeCommandBasic(): void
{
$this->createTestView("{{ __('Localizator') }} {{ __('app.name') }}");
// Run localize command.
$this->artisan('localize')
->assertExitCode(0);
// Do created locale files exist?
self::assertDefaultLangFilesExist('en', ['app']);
self::assertJsonLangFilesExist('en');
// Do their contents match the expected results?
$enDefaultContents = $this->getDefaultLangContents('en', 'app');
$enJsonContents = $this->getJsonLangContents('en');
self::assertSame(['name' => ''], $enDefaultContents);
self::assertSame(['Localizator' => 'Localizator'], $enJsonContents);
// Cleanup.
self::flushDirectories('lang', 'views');
}
/**
* @return void
*/
public function testLocalizeCommandWithDefinedLocales(): void
{
$this->createTestView("{{ __('Localizator') }} {{ __('app.name') }}");
// Run localize command.
$this->artisan('localize', ['lang' => 'en,de'])
->assertExitCode(0);
// Do created locale files exist?
self::assertDefaultLangFilesExist(['en', 'de'], ['app']);
self::assertJsonLangFilesExist(['en', 'de']);
// Do their contents match the expected results?
$enDefaultContents = $this->getDefaultLangContents('en', 'app');
$enJsonContents = $this->getJsonLangContents('en');
$deDefaultContents = $this->getDefaultLangContents('de', 'app');
$deJsonContents = $this->getJsonLangContents('de');
self::assertSame(['name' => ''], $enDefaultContents);
self::assertSame(['name' => ''], $deDefaultContents);
self::assertSame(['Localizator' => 'Localizator'], $enJsonContents);
self::assertSame(['Localizator' => ''], $deJsonContents);
// Cleanup.
self::flushDirectories('lang', 'views');
}
/**
* @return void
*/
public function testLocalizeCommandWithSortingKeys(): void
{
$this->createTestView("{{ __('Delete') }} {{ __('Cancel') }} {{ __('Login') }}", 'test-1');
$this->createTestView("{{ __('auth.throttle') }} {{ __('auth.failed') }} {{ __('auth.password') }}", 'test-2');
// Run localize command.
$this->artisan('localize')
->assertExitCode(0);
// Do created locale files exist?
self::assertDefaultLangFilesExist('en', ['auth']);
self::assertJsonLangFilesExist('en');
// Do their contents match the expected results?
$enDefaultContents = $this->getDefaultLangContents('en', 'auth');
$enJsonContents = $this->getJsonLangContents('en');
// Did it sort the translation keys like we expected?
self::assertSame([
'failed' => '',
'password' => '',
'throttle' => '',
], $enDefaultContents);
self::assertSame([
'Cancel' => 'Cancel',
'Delete' => 'Delete',
'Login' => 'Login',
], $enJsonContents);
// Cleanup.
self::flushDirectories('lang', 'views');
}
/**
* @return void
*/
public function testLocalizeCommandByMergingTheExistingTranslations(): void
{
$this->createTestView("{{ __('Delete') }} {{ __('Cancel') }} {{ __('Login') }}", 'test-1');
$this->createTestView("{{ __('auth.throttle') }} {{ __('auth.failed') }} {{ __('auth.password') }}", 'test-2');
$this->createTestDefaultLangFile([
'password' => 'Das eingegebene Passwort ist nicht korrekt.',
], 'auth', 'de');
$this->createTestJsonLangFile([
'Login' => 'Anmelden',
'Delete' => 'Löschen',
], 'de');
// Run localize command.
$this->artisan('localize', ['lang' => 'de'])
->assertExitCode(0);
// Do created locale files exist?
self::assertDefaultLangFilesExist('de', ['auth']);
self::assertJsonLangFilesExist('de');
// Do their contents match the expected results?
$enDefaultContents = $this->getDefaultLangContents('de', 'auth');
$enJsonContents = $this->getJsonLangContents('de');
// Did it preserve the already translated keys?
self::assertSame([
'failed' => '',
'password' => 'Das eingegebene Passwort ist nicht korrekt.',
'throttle' => '',
], $enDefaultContents);
self::assertSame([
'Cancel' => '',
'Delete' => 'Löschen',
'Login' => 'Anmelden',
], $enJsonContents);
// Cleanup.
self::flushDirectories('lang', 'views');
}
/**
* @return void
*/
public function testLocalizeCommandWhereKeysAreEscapedWithSlashes(): void
{
$this->createTestView("{{ __('Amir\'s PC') }} {{ __('Jacob\'s Ladder') }} {{ __('mom\'s spaghetti') }}");
// Run localize command.
$this->artisan('localize')
->assertExitCode(0);
// Do created locale files exist?
self::assertJsonLangFilesExist('en');
// Do their contents match the expected results?
$enJsonContents = $this->getJsonLangContents('en');
// Did it sort the translation keys like we expected?
self::assertSame([
'Amir\'s PC' => 'Amir\'s PC',
'Jacob\'s Ladder' => 'Jacob\'s Ladder',
'mom\'s spaghetti' => 'mom\'s spaghetti',
], $enJsonContents);
// Cleanup.
self::flushDirectories('lang', 'views');
}
public function testLocalizeCommandReturnsNonZeroCodeWhenCiFlagIsOnAndSomeMissingTranslationsHaveBeenAdded(): void
{
$this->createTestView("{{ __('Hi mom') }}");
// Run localize command.
$this->artisan('localize', ['--ci' => true])
->assertExitCode(1);
// Cleanup.
self::flushDirectories('lang', 'views');
}
public function testLocalizeCommandReturnsZeroCodeWhenCiFlagIsOnAndNoMissingTranslationsHaveBeenFound(): void
{
$this->createTestView("");
// Run localize command.
$this->artisan('localize', ['--ci' => true])
->assertExitCode(0);
// Cleanup.
self::flushDirectories('lang', 'views');
}
public function testLocalizeCommandReturnsNonZeroCodeThenZeroCodeIfFileDidNotChangedBetweenTwoRun(): void
{
$this->createTestView("{{ __('Hi mom') }}");
// Run localize command.
$this->artisan('localize', ['--ci' => true])
->assertExitCode(1);
// Run localize command.
$this->artisan('localize', ['--ci' => true])
->assertExitCode(0);
// Cleanup.
self::flushDirectories('lang', 'views');
}
}