Skip to content

Commit 4f7e882

Browse files
niels-numbersMarc Cámara
authored andcommitted
Add test to check independece of getLocale and hideDefaultLocale (#657)
* Add test to check independece of getLocale and hideDefaultLocale A recent change in `setLocale` caused that `hideDefaultLocaleInURL` is causing a `404` error when an uri with default locale is accessed. A test for this scenario has been created, but it currently fails in release 1.4.2. See #656 for more * Update LocalizerTests.php
1 parent a871283 commit 4f7e882

File tree

1 file changed

+51
-5
lines changed

1 file changed

+51
-5
lines changed

tests/LocalizerTests.php

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ protected function getPackageAliases($app)
2525
];
2626
}
2727

28-
public function setUp(): void
29-
{
30-
parent::setUp();
31-
}
32-
3328
/**
3429
* Set routes for testing.
3530
*
@@ -89,6 +84,41 @@ protected function refreshApplication($locale = false)
8984
$this->setRoutes($locale);
9085
}
9186

87+
/**
88+
* Create fake request
89+
* @param [type] $method [description]
90+
* @param [type] $content [description]
91+
* @param string $uri [description]
92+
* @param array $server [description]
93+
* @param array $parameters [description]
94+
* @param array $cookies [description]
95+
* @param array $files [description]
96+
* @return [type] [description]
97+
*/
98+
protected function createRequest(
99+
$uri = '/test',
100+
$method = 'GET',
101+
$parameters = [],
102+
$cookies = [],
103+
$files = [],
104+
$server = ['CONTENT_TYPE' => 'application/json'],
105+
$content = null
106+
)
107+
{
108+
$request = new \Illuminate\Http\Request;
109+
return $request->createFromBase(
110+
\Symfony\Component\HttpFoundation\Request::create(
111+
$uri,
112+
$method,
113+
$parameters,
114+
$cookies,
115+
$files,
116+
$server,
117+
$content
118+
)
119+
);
120+
}
121+
92122
/**
93123
* Define environment setup.
94124
*
@@ -138,6 +168,22 @@ public function testSetLocale()
138168
$this->assertEquals('en', app('laravellocalization')->getCurrentLocale());
139169
}
140170

171+
// LaravelLocalization setLocale method should return the locale of
172+
// the request uri (if any). This behavior should be independet
173+
// of the `hideDefaultLocaleInURL` setting
174+
public function testHideDefaultLocaleInUrlShouldNotChangeSetLocaleBehaviour()
175+
{
176+
app('config')->set('laravellocalization.hideDefaultLocaleInURL', true);
177+
178+
app()['request'] = $this->createRequest(
179+
$uri = '/en/test'
180+
);
181+
182+
$laravelLocalization = new \Mcamara\LaravelLocalization\LaravelLocalization();
183+
184+
$this->assertEquals('en', $laravelLocalization->setLocale());
185+
}
186+
141187
public function testLocalizeURL()
142188
{
143189
$this->assertEquals(

0 commit comments

Comments
 (0)