dimanche 2 avril 2017

Laravel 5.4 HTTP Testing

I am writing a test for a json route in laravel 5.4, I am supposed to be redirected if the GET request is not ajax, the code works correctly on the browser chrome but when I test it does not work as expected. I tried different variation to add headers to the request none worked.

When I changed the request to POST it worked as excepted, I am not sure what I am missing. here is the code

routes.php

// Redirect all none-ajax routes to the main edit test route
if (!Request::ajax()) {
  Route::get('{vue?}', ['as'=>'vue_redirect', 'uses' => 'TestController@vueHandler'])->where('vue', '[\/\w\.-]*');
}
    /*
     * General route to the test instructions
     */
    Route::get('getInstructions', ['as' => 'getInstructions', 'uses' => 'TestController@getInstructions']);

This is the test code

public function testgetTest()
{

  $x = $this->actingAs($this->customer)->json('GET', '/test/edit/' . $this->test->id . '/getInstructions');
  var_dump($x->getContent());


}

I tried variation like

$this->actingAs($this->customer)->call('GET', '/test/edit/' . $this->test->id . '/getInstructions', [], [], ['X-Requested-With' => 'XMLHttpRequest']

Put also did not work.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire