/** * @test */ public function it_removes_the_minimal_user_info_when_logging_out() { $this->service->setMinimalUserInfo($this->minimalUserInfo); $this->service->logout(); $this->assertNull($this->service->getMinimalUserInfo()); $this->assertNull($this->service->getUser()); }
/** * @test */ public function it_redirects_to_a_destination_after_authorisation() { $oauthVerifier = 'verification'; // The authorisation method should get the stored request token. $this->authService->expects($this->any())->method('getStoredRequestToken')->willReturn($this->requestToken); // Based on the stored request token and the oauth verifier it should // get the user from the authentication service. $userId = 1; $tokenCredentials = new TokenCredentials('token2', 'secret2'); $user = new User($userId, $tokenCredentials); $this->authService->expects($this->any())->method('getAccessToken')->with($this->requestToken, $oauthVerifier)->willReturn($user); // Afterwards it should remove the stored request token. $this->authService->expects($this->any())->method('removeStoredRequestToken'); // Perform a fake request to the route with the query parameters. $query = ['oauth_token' => $this->requestToken->getToken(), 'oauth_verifier' => $oauthVerifier, 'destination' => $this->destination]; $request = new Request($query); $response = $this->controller->authorize($request); // Make sure the response is a redirect to the destination that // was set in the query parameters. $this->assertEquals(new RedirectResponse($this->destination), $response); // Make sure that the minimal user info has been stored in the session. $this->assertEquals($this->userSessionService->getMinimalUserInfo(), $user); // Perform the fake request again, but this time without destination // parameter in the query. $this->urlGenerator->expects($this->once())->method('generate')->with($this->defaultDestination)->willReturn($this->defaultDestinationUrl); $query = ['oauth_token' => $this->requestToken->getToken(), 'oauth_verifier' => $oauthVerifier]; $request = new Request($query); $response = $this->controller->authorize($request); // Make sure that the response now redirects to the default // destination. $this->assertEquals(new RedirectResponse($this->defaultDestinationUrl), $response); }
/** * @test */ public function it_grants_access_when_authenticated() { $this->userSessionService->setMinimalUserInfo($this->minimalUserInfo); $user = new User(); $user->id = $this->minimalUserInfo->getId(); $authToken = new UiTIDToken($user->getRoles()); $authToken->setUser($user); $this->authenticationManager->expects($this->once())->method('authenticate')->with($this->minimalToken)->willReturn($authToken); $this->tokenStorage->expects($this->once())->method('setToken')->with($authToken); // Make sure no Response is set, so the request can be handled by the // actual controllers. $this->event->expects($this->never())->method('setResponse'); $this->listener->handle($this->event); }
/** * @test */ public function it_invalidates_the_session_when_logging_out() { $this->userSessionService->expects($this->once())->method('logout'); $response = $this->controller->logout(); $this->assertEquals($response->getStatusCode(), Response::HTTP_OK); }