// We should be able to access the route with basic authentication.
$this->basicAuthGet($protected_url, $this->user->getAccountName(), $this->user->passRaw); $this->assertSession()->statusCodeEquals(200);
// Check that the correct user is logged in.
$this->assertEquals($this->user->id(), json_decode($session->getPage()->getContent())->user, 'The correct user is authenticated on a route with basic authentication.'); $session->restart();
// If we now try to access a page without basic authentication then we
// should no longer be logged in.
$this->drupalGet($unprotected_url); $this->assertSession()->statusCodeEquals(200); $this->assertEquals(0, json_decode($session->getPage()->getContent())->user, 'The user is no longer authenticated after visiting a page without basic authentication.');