/** * @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); }