Skip to content

Commit 55995d4

Browse files
committed
Test localized root route registration
1 parent 18a9a66 commit 55995d4

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

tests/Unit/Macros/LocalizedRoutesMacroTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App;
66
use CodeZero\LocalizedRoutes\Tests\TestCase;
77
use Config;
8+
use Illuminate\Support\Collection;
89
use Route;
910

1011
class LocalizedRoutesMacroTest extends TestCase
@@ -14,6 +15,14 @@ protected function setAvailableLocales($locales)
1415
Config::set('localized-routes.supported-locales', $locales);
1516
}
1617

18+
protected function getRoutes()
19+
{
20+
// Route::has() doesn't seem to be working
21+
// when you create routes on the fly.
22+
// So this is a bit of a workaround...
23+
return new Collection(Route::getRoutes());
24+
}
25+
1726
/** @test */
1827
public function it_registers_a_route_for_each_locale()
1928
{
@@ -24,10 +33,7 @@ public function it_registers_a_route_for_each_locale()
2433
->name('route.name');
2534
});
2635

27-
// Route::has() doesn't seem to be working
28-
// when you create routes on the fly.
29-
// So this is a bit of a workaround...
30-
$routes = collect(Route::getRoutes());
36+
$routes = $this->getRoutes();
3137
$names = $routes->pluck('action.as');
3238
$uris = $routes->pluck('uri');
3339

@@ -40,6 +46,29 @@ public function it_registers_a_route_for_each_locale()
4046
$this->assertContains('nl/route', $uris);
4147
}
4248

49+
/** @test */
50+
public function it_registers_a_root_route_for_each_locale()
51+
{
52+
$this->setAvailableLocales(['en', 'nl']);
53+
54+
Route::localized(function () {
55+
Route::get('/', function () {})
56+
->name('home');
57+
});
58+
59+
$routes = $this->getRoutes();
60+
$names = $routes->pluck('action.as');
61+
$uris = $routes->pluck('uri');
62+
63+
$this->assertNotContains('home', $names);
64+
$this->assertContains('en.home', $names);
65+
$this->assertContains('nl.home', $names);
66+
67+
$this->assertNotContains('/', $uris);
68+
$this->assertContains('en', $uris);
69+
$this->assertContains('nl', $uris);
70+
}
71+
4372
/** @test */
4473
public function it_temporarily_changes_the_app_locale_when_registering_the_routes()
4574
{

0 commit comments

Comments
 (0)