Skip to content

Commit 10526e3

Browse files
committed
Move middleware tests to separate file
1 parent 5074e49 commit 10526e3

File tree

2 files changed

+80
-70
lines changed

2 files changed

+80
-70
lines changed

tests/Unit/Macros/LocalizedRoutesMacroTest.php

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -144,49 +144,6 @@ public function it_does_not_permanently_change_the_locale_without_middleware()
144144
$this->assertEquals($originalLocale, $response->original);
145145
}
146146

147-
/** @test */
148-
public function it_sets_the_right_locale_when_accessing_localized_routes()
149-
{
150-
$this->setSupportedLocales(['en', 'nl']);
151-
$this->setUseLocaleMiddleware(true);
152-
153-
Route::localized(function () {
154-
Route::get('/', function () {
155-
return App::getLocale();
156-
});
157-
});
158-
159-
$response = $this->call('GET', '/en');
160-
$response->assertOk();
161-
$this->assertEquals('en', $response->original);
162-
163-
$response = $this->call('GET', '/nl');
164-
$response->assertOk();
165-
$this->assertEquals('nl', $response->original);
166-
}
167-
168-
/** @test */
169-
public function it_sets_the_right_locale_when_accessing_localized_routes_with_omitted_prefix()
170-
{
171-
$this->setSupportedLocales(['en', 'nl']);
172-
$this->setUseLocaleMiddleware(true);
173-
$this->setOmitUrlPrefixForLocale('en');
174-
175-
Route::localized(function () {
176-
Route::get('/', function () {
177-
return App::getLocale();
178-
});
179-
});
180-
181-
$response = $this->call('GET', '/');
182-
$response->assertOk();
183-
$this->assertEquals('en', $response->original);
184-
185-
$response = $this->call('GET', '/nl');
186-
$response->assertOk();
187-
$this->assertEquals('nl', $response->original);
188-
}
189-
190147
/** @test */
191148
public function it_correctly_uses_scoped_config_options()
192149
{
@@ -273,31 +230,4 @@ public function it_creates_localized_routes_within_route_groups()
273230
$this->call('GET', '/admin/en/route')->assertOk();
274231
$this->call('GET', '/admin/nl/route')->assertOk();
275232
}
276-
277-
/** @test */
278-
public function it_sets_the_locale_for_localized_routes_within_route_groups()
279-
{
280-
$this->setSupportedLocales(['en', 'nl']);
281-
$this->setUseLocaleMiddleware(true);
282-
283-
Route::group([
284-
'as' => 'admin.',
285-
'prefix' => 'admin'
286-
], function () {
287-
Route::localized(function () {
288-
Route::get('route', function () {
289-
return App::getLocale();
290-
})
291-
->name('route.name');
292-
});
293-
});
294-
295-
$response = $this->call('GET', '/admin/en/route');
296-
$response->assertOk();
297-
$this->assertEquals('en', $response->original);
298-
299-
$response = $this->call('GET', '/admin/nl/route');
300-
$response->assertOk();
301-
$this->assertEquals('nl', $response->original);
302-
}
303233
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace CodeZero\LocalizedRoutes\Tests\Unit\Macros;
4+
5+
use CodeZero\LocalizedRoutes\Middleware\LocalizedRouteLocaleHandler;
6+
use CodeZero\LocalizedRoutes\Tests\Stubs\Model;
7+
use CodeZero\LocalizedRoutes\Tests\TestCase;
8+
use Illuminate\Support\Facades\App;
9+
use Illuminate\Support\Facades\Route;
10+
11+
class LocalizedRouteLocaleHandlerTest extends TestCase
12+
{
13+
/** @test */
14+
public function it_sets_the_right_locale_when_accessing_localized_routes()
15+
{
16+
$this->setSupportedLocales(['en', 'nl']);
17+
$this->setUseLocaleMiddleware(true);
18+
19+
Route::localized(function () {
20+
Route::get('/', function () {
21+
return App::getLocale();
22+
});
23+
});
24+
25+
$response = $this->call('GET', '/en');
26+
$response->assertOk();
27+
$this->assertEquals('en', $response->original);
28+
29+
$response = $this->call('GET', '/nl');
30+
$response->assertOk();
31+
$this->assertEquals('nl', $response->original);
32+
}
33+
34+
/** @test */
35+
public function it_sets_the_right_locale_when_accessing_localized_routes_with_omitted_prefix()
36+
{
37+
$this->setSupportedLocales(['en', 'nl']);
38+
$this->setUseLocaleMiddleware(true);
39+
$this->setOmitUrlPrefixForLocale('nl');
40+
41+
Route::localized(function () {
42+
Route::get('/', function () {
43+
return App::getLocale();
44+
});
45+
});
46+
47+
$response = $this->call('GET', '/');
48+
$response->assertOk();
49+
$this->assertEquals('nl', $response->original);
50+
51+
$response = $this->call('GET', '/en');
52+
$response->assertOk();
53+
$this->assertEquals('en', $response->original);
54+
}
55+
56+
/** @test */
57+
public function it_sets_the_locale_for_localized_routes_within_route_groups()
58+
{
59+
$this->setSupportedLocales(['en', 'nl']);
60+
61+
Route::group([
62+
'as' => 'admin.',
63+
'prefix' => 'admin',
64+
], function () {
65+
Route::localized(function () {
66+
Route::get('route', function () {
67+
return App::getLocale();
68+
})->name('route.name')->middleware(['web', LocalizedRouteLocaleHandler::class]);
69+
});
70+
});
71+
72+
$response = $this->call('GET', '/admin/en/route');
73+
$response->assertOk();
74+
$this->assertEquals('en', $response->original);
75+
76+
$response = $this->call('GET', '/admin/nl/route');
77+
$response->assertOk();
78+
$this->assertEquals('nl', $response->original);
79+
}
80+
}

0 commit comments

Comments
 (0)