Jan 8, 2020
5
Level 8
is it possible to test if all routes are redirected to login page when user is not logged-id ?
Hello ,
Here bellow I made a test to know if a non-loged user when he request / is redirected to the login page .
the question is : this test is only for / route , is there any way to test the rest of routes without typing theme all ? someting like $this->get('/*') ?
public function test_if_user_is_not_logged_must_redirect_to_login_page(){
$this->get('/')
->assertStatus(302);
}
Level 104
You could instead get the RouteCollection and iterate over each Route registered in the application, checking that the auth middleware has been applied to each.
$routes = app('router')->getRoutes()->getRoutes();
foreach ($routes as $route) {
$this->assertTrue(
in_array('auth', $route->gatherMiddleware()),
"Failed because {$route->uri()} is not protected by auth middleware"
);
})
Please or to participate in this conversation.