I have a link on a page /my/example/page
which links to a laravel route my.route
.
Route
Route::group(['middleware' => ['auth']], function () {
Route::group(['middleware' => ['Some\Custom\Auth\Middleware:1']], function () {
Route::match(['GET', 'POST'], '/my/route/to/external/controller', 'exampleController@externalLink')->name('my.route');
}
}
Link on /my/example/page
<a href="/my/route/to/external/controller">Link</a>
此路由/my/route/to/external/controller
指向exampleController
控制器中的此控制器方法externalLink
,该方法返回要使用的HREF的url
public function externalLink()
{
return $this->redirect->away('www.externalsite.com');
}
My test is
$this->visit(/my/example/page)
->click('Link')
->assertRedirectedToRoute('my.route');
I constantly get the error
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
when I use the click()
testing method.
我可以用@expectedException
捕捉到这一点,但他的没有帮助,因为我期待看到不同的页面.
我也试过(不是一起);
->assertResponseStatus(200);
->seePageIs('www.externalsite.com');
->assertRedirect();
->followRedirects();
通过浏览器判断,当点击url时,我得到
http://www.example.com/my/route/to/external 302
http://www.externalsite.com 200
How can I functionally test the button being clicked and redirecting to an external site?