-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mailable render() respects locale (#25990)
In production, this allows: (new Mailable)->locale('es')->render()
- Loading branch information
1 parent
f59f0bd
commit d1be6e4
Showing
2 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Mail; | ||
|
||
use Illuminate\Mail\Mailable; | ||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\View; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class RenderingMailWithLocaleTest extends TestCase | ||
{ | ||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.locale', 'en'); | ||
|
||
View::addLocation(__DIR__.'/Fixtures'); | ||
|
||
app('translator')->setLoaded([ | ||
'*' => [ | ||
'*' => [ | ||
'en' => ['nom' => 'name'], | ||
'es' => ['nom' => 'nombre'], | ||
], | ||
], | ||
]); | ||
} | ||
|
||
public function testMailableRendersInDefaultLocale() | ||
{ | ||
$mail = new RenderedTestMail; | ||
|
||
$this->assertEquals("name\n", $mail->render()); | ||
} | ||
|
||
public function testMailableRendersInSelectedLocale() | ||
{ | ||
$mail = (new RenderedTestMail)->locale('es'); | ||
|
||
$this->assertEquals("nombre\n", $mail->render()); | ||
} | ||
|
||
public function testMailableRendersInAppSelectedLocale() | ||
{ | ||
$this->app->setLocale('es'); | ||
|
||
$mail = new RenderedTestMail; | ||
|
||
$this->assertEquals("nombre\n", $mail->render()); | ||
} | ||
} | ||
|
||
class RenderedTestMail extends Mailable | ||
{ | ||
public function build() | ||
{ | ||
return $this->view('view'); | ||
} | ||
} |