Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
- Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Feb 27, 2015
1 parent f712822 commit c1f5226
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/IPub/Flickr/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ protected function getUserFromAvailableData()

// use access_token to fetch user id if we have a user access_token, or if
// the cached access token has changed
if (($accessToken = $this->getAccessToken()) && !($user && $this->session->access_token === $accessToken)) {
if (($accessToken = $this->getAccessToken('access_token')) && !($user && $this->session->access_token === $accessToken)) {
if (!$user = $this->getUserFromAccessToken()) {
$this->session->clearAll();

Expand Down
39 changes: 20 additions & 19 deletions tests/IPubTests/Flickr/ClientTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ class ClientTest extends TestCase
{
$client = $this->buildClient();

$this->session->access_token = 'abcedf';
$this->session->access_token_secret = 'ghijklmn';
$this->session->set('user_id', 123321);
$session = $client->getSession();
$session->access_token = 'abcedf';
$session->access_token_secret = 'ghijklmn';
$session->user_id = 123321;

Assert::same(123321, $client->getUser());
}
/*

public function testAuthorized_readUserIdFromAccessToken()
{
$client = $this->buildClient();
Expand All @@ -55,43 +56,43 @@ class ClientTest extends TestCase
'access_token_secret' => 'ghijklmn',
]);

$this->httpClient->fakeResponse('{"stat":"ok","user":{"id":123321,"name":"Adam Kadlec"}}', 200, ['Content-Type' => 'application/json; charset=utf-8']);
$this->httpClient->fakeResponse('{"stat":"ok","user":{"id":"21207597%40N07","username":{"_content":"john.doe"}}}', 200, ['Content-Type' => 'application/json; charset=utf-8']);

Assert::same(123321, $client->getUser());
Assert::same('21207597%40N07', $client->getUser());
Assert::count(1, $this->httpClient->requests);

$secondRequest = $this->httpClient->requests[0];

Assert::same('GET', $secondRequest->getMethod());
Assert::match('https://api.flickr.com/services/', (string) $secondRequest->getUrl());
Assert::same(['Authorization' => 'token abcedf', 'Accept' => 'application/json'], $secondRequest->getHeaders());
Assert::match('https://api.flickr.com/services/rest', $secondRequest->getUrl()->getHostUrl() . $secondRequest->getUrl()->getPath());
Assert::same(['Accept' => 'application/json'], $secondRequest->getHeaders());
}

public function testAuthorized_authorizeFromCodeAndState()
{
$client = $this->buildClient(array('state' => 'abcdef123456', 'code' => '654321fedcba'));
$client = $this->buildClient(array('oauth_verifier' => 'abcedf', 'oauth_token' => 'ghijklmn'));

$this->session->state = 'abcdef123456'; // The method establishCSRFTokenState() is called in the LoginDialog
//$this->session->access_token = 'abcedf';
//$this->session->access_token_secret = 'ghijklmn';

$this->httpClient->fakeResponse('{"access_token":"6dc29d696930cb9b76914bd9d25c63c698957c60","token_type":"bearer","scope":"user:email"}', 200, array('Content-Type' => 'application/json; charset=utf-8'));
$this->httpClient->fakeResponse('{"login":"fprochazka","id":158625,"type":"User","site_admin":false,"name":"Filip Procházka","email":"filip@prochazka.su"}', 200, array('Content-Type' => 'application/json; charset=utf-8'));
$this->httpClient->fakeResponse('fullname=John%20Doe&oauth_token=72157626318069415-087bfc7b5816092c&oauth_token_secret=a202d1f853ec69de&user_nsid=21207597%40N07&username=john.doe', 200, ['Content-Type' => 'application/json; charset=utf-8']);
$this->httpClient->fakeResponse('{"stat":"ok","user":{"id":"21207597%40N07","username":{"_content":"john.doe"}}}', 200, ['Content-Type' => 'application/json; charset=utf-8']);

Assert::same(158625, $client->getUser());
Assert::same('21207597%40N07', $client->getUser());
Assert::count(2, $this->httpClient->requests);

$firstRequest = $this->httpClient->requests[0];

Assert::same('POST', $firstRequest->getMethod());
Assert::match('https://github.com/login/oauth/access_token?client_id=' . $this->config->appId . '&client_secret=' . $this->config->appSecret . '&code=%a%&redirect_uri=%a%', (string) $firstRequest->getUrl());
Assert::same(array('Accept' => 'application/json'), $firstRequest->getHeaders());
Assert::same('GET', $firstRequest->getMethod());
Assert::match('https://www.flickr.com/services/oauth/access_token', $firstRequest->getUrl()->getHostUrl() . $firstRequest->getUrl()->getPath());
Assert::same(['Accept' => 'application/json'], $firstRequest->getHeaders());

$secondRequest = $this->httpClient->requests[1];

Assert::same('GET', $secondRequest->getMethod());
Assert::match('https://api.github.com/user', (string) $secondRequest->getUrl());
Assert::same(array('Authorization' => 'token 6dc29d696930cb9b76914bd9d25c63c698957c60', 'Accept' => 'application/vnd.github.v3+json'), $secondRequest->getHeaders());
Assert::match('https://api.flickr.com/services/rest', $secondRequest->getUrl()->getHostUrl() . $secondRequest->getUrl()->getPath());
Assert::same(['Accept' => 'application/json'], $secondRequest->getHeaders());
}
*/
}

\run(new ClientTest());

0 comments on commit c1f5226

Please sign in to comment.