Skip to content

Commit

Permalink
Add test to check independece of getLocale and hideDefaultLocale (#657)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
iwasherefirst2 authored and Marc Cámara committed Oct 13, 2019
1 parent a871283 commit 4f7e882
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions tests/LocalizerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ protected function getPackageAliases($app)
];
}

public function setUp(): void
{
parent::setUp();
}

/**
* Set routes for testing.
*
Expand Down Expand Up @@ -89,6 +84,41 @@ protected function refreshApplication($locale = false)
$this->setRoutes($locale);
}

/**
* Create fake request
* @param [type] $method [description]
* @param [type] $content [description]
* @param string $uri [description]
* @param array $server [description]
* @param array $parameters [description]
* @param array $cookies [description]
* @param array $files [description]
* @return [type] [description]
*/
protected function createRequest(
$uri = '/test',
$method = 'GET',
$parameters = [],
$cookies = [],
$files = [],
$server = ['CONTENT_TYPE' => 'application/json'],
$content = null
)
{
$request = new \Illuminate\Http\Request;
return $request->createFromBase(
\Symfony\Component\HttpFoundation\Request::create(
$uri,
$method,
$parameters,
$cookies,
$files,
$server,
$content
)
);
}

/**
* Define environment setup.
*
Expand Down Expand Up @@ -138,6 +168,22 @@ public function testSetLocale()
$this->assertEquals('en', app('laravellocalization')->getCurrentLocale());
}

// LaravelLocalization setLocale method should return the locale of
// the request uri (if any). This behavior should be independet
// of the `hideDefaultLocaleInURL` setting
public function testHideDefaultLocaleInUrlShouldNotChangeSetLocaleBehaviour()
{
app('config')->set('laravellocalization.hideDefaultLocaleInURL', true);

app()['request'] = $this->createRequest(
$uri = '/en/test'
);

$laravelLocalization = new \Mcamara\LaravelLocalization\LaravelLocalization();

$this->assertEquals('en', $laravelLocalization->setLocale());
}

public function testLocalizeURL()
{
$this->assertEquals(
Expand Down

0 comments on commit 4f7e882

Please sign in to comment.