Skip to content

Commit 949cc46

Browse files
committed
Make translation tests reading the messages from original files
1 parent 47472bf commit 949cc46

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

tests/TranslationTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,33 @@ class TranslationTest extends TestCase
1616
*/
1717
protected $validator;
1818

19+
/**
20+
* @var string
21+
*/
22+
protected $translationDirectory;
23+
1924
public function setUp()
2025
{
2126
parent::setUp();
2227
$this->validator = $this->app['validator'];
28+
$this->translationDirectory = __DIR__.'/../lang';
2329
}
2430

2531
protected function getPackageProviders($app)
2632
{
2733
return [ServiceProvider::class];
2834
}
2935

36+
protected function getMessage($locale, $filename, $key, $field)
37+
{
38+
$filePath = sprintf('%s/%s/%s.php', $this->translationDirectory, $locale, $filename);
39+
$arrayContent = include $filePath;
40+
41+
if (isset($arrayContent[$key])) {
42+
return str_replace(':attribute', $field, $arrayContent[$key]);
43+
}
44+
}
45+
3046
public function testENMessages()
3147
{
3248
$this->app->setLocale('en');
@@ -37,7 +53,8 @@ public function testENMessages()
3753
if ($validator->fails()) {
3854
$messages = $validator->errors()->get('country');
3955
$first = array_shift($messages);
40-
$this->assertEquals($first, 'The country field is not a valid country code.');
56+
$expectedMessage = $this->getMessage('en', 'validation', 'country_code', 'country');
57+
$this->assertEquals($first, $expectedMessage);
4158
}
4259
}
4360

@@ -51,7 +68,8 @@ public function testPT_BRMessages()
5168
if ($validator->fails()) {
5269
$messages = $validator->errors()->get('country');
5370
$first = array_shift($messages);
54-
$this->assertEquals($first, 'O campo country não possui um código de país válido.');
71+
$expectedMessage = $this->getMessage('pt-br', 'validation', 'country_code', 'country');
72+
$this->assertEquals($first, $expectedMessage);
5573
}
5674
}
5775

@@ -65,7 +83,8 @@ public function testENMessagesForAdministrativeAreaValidator()
6583
if ($validator->fails()) {
6684
$messages = $validator->errors()->get('state');
6785
$first = array_shift($messages);
68-
$this->assertEquals($first, 'The state field is not a valid state/province.');
86+
$expectedMessage = $this->getMessage('en', 'validation', 'administrative_area', 'state');
87+
$this->assertEquals($first, $expectedMessage);
6988
}
7089
}
7190
}

0 commit comments

Comments
 (0)