2
votes

I am trying to test the routing mechanism of my app (which is a Laravel PHP App) that was based on the documentation (http://laravel.com/docs/routing#route-prefixing). The case is: We are trying to handle the app localisation based on the route, for example:

www.example.com/en/something -> Should use EN as language,  
www.example.com/es/something -> Should use ES as language,  
www.example.com/de/something -> Should use DE as language.  

We accomplished the behaviour described before by using prefixes and it works perfect. The thing is that I am not able to write tests to test this behaviour. I did a little bit of research, and I found this third party library (https://github.com/mcamara/laravel-localization/blob/master/tests/LocalizerTests.php), that uses a similar approach, and I think it might help you understand which is the situation.

If you take a look in there, he is not testing the scenario that I want to test (I mean, with the locale code on the path).Btw: I've already turned on the filters with Route::enableFilters() and it does not work :(

Thanks a lot

1
Well, we've been using routing with prefixes as can be seen on the documentation, and the scenarios with the location on the route works, the thing is that, when I try to test them out, I am receiving an HTTP 500 Error, saying that the route is not valid. - facundofarias
could you explain better " I am not able to write tests to test this behaviour." ? what code is there on your test? - Stormsson
Alright, here you have my test: /** * A basic functional test example. * * @return void */ public function testBasicExample() { $crawler = $this->client->request('GET', '/myproduct/en/list'); $this->assertTrue($this->client->getResponse()->isOk()); } And this is throwing the following exception: 1) ExampleTest::testBasicExample Symfony\Component\HttpKernel\Exception\NotFoundHttpException: - facundofarias
Any thoughts on this? - facundofarias

1 Answers

1
votes

If you use route inside the group.

Route::group(array('domain' => {account}.'.$domain), function()
{
    Route::get('myproduct/en/list', 'HomeController@showWelcome');
});

then try this.

  public function testBasicExample() { 
    $crawler = $this->client->request('GET', 'http://subdomain.domain.local/myproduct/en/list');           
$this->assertTrue($this->client->getResponse()->isOk()); 
    }