3 require_once 'PHPUnit/Framework/TestCase.php';
4 require_once 'Zend/Oauth/Http/AccessToken.php';
6 class Zend_Oauth_Http_AccessTokenTest
extends PHPUnit_Framework_TestCase
9 protected $stubConsumer = null;
11 public function setup()
13 $this->stubConsumer
= new Test_Consumer_39745
;
14 $this->stubHttpUtility
= new Test_Http_Utility_39745
;
15 Zend_Oauth
::setHttpClient(new Test_Client_39745
);
18 public function teardown()
20 Zend_Oauth
::clearHttpClient();
23 public function testConstructorSetsConsumerInstance()
25 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, null, $this->stubHttpUtility
);
26 $this->assertType('Test_Consumer_39745', $request->getConsumer());
29 public function testConstructorSetsCustomServiceParameters()
31 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, array(1,2,3), $this->stubHttpUtility
);
32 $this->assertEquals(array(1,2,3), $request->getParameters());
35 public function testAssembleParametersCorrectlyAggregatesOauthParameters()
37 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, null, $this->stubHttpUtility
);
38 $expectedParams = array (
39 'oauth_consumer_key' => '1234567890',
40 'oauth_nonce' => 'e807f1fcf82d132f9bb018ca6738a19f',
41 'oauth_signature_method' => 'HMAC-SHA1',
42 'oauth_timestamp' => '12345678901',
43 'oauth_token' => '0987654321',
44 'oauth_version' => '1.0',
45 'oauth_signature' => '6fb42da0e32e07b61c9f0251fe627a9c'
47 $this->assertEquals($expectedParams, $request->assembleParams());
49 public function testAssembleParametersCorrectlyIgnoresCustomParameters()
51 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, array(
52 'custom_param1'=>'foo',
53 'custom_param2'=>'bar'
54 ), $this->stubHttpUtility
);
55 $expectedParams = array (
56 'oauth_consumer_key' => '1234567890',
57 'oauth_nonce' => 'e807f1fcf82d132f9bb018ca6738a19f',
58 'oauth_signature_method' => 'HMAC-SHA1',
59 'oauth_timestamp' => '12345678901',
60 'oauth_token' => '0987654321',
61 'oauth_version' => '1.0',
62 'oauth_signature' => '6fb42da0e32e07b61c9f0251fe627a9c'
64 $this->assertEquals($expectedParams, $request->assembleParams());
67 public function testGetRequestSchemeHeaderClientSetsCorrectlyEncodedAuthorizationHeader()
69 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, null, $this->stubHttpUtility
);
71 'oauth_consumer_key' => '1234567890',
72 'oauth_nonce' => 'e807f1fcf82d132f9bb018ca6738a19f',
73 'oauth_signature_method' => 'HMAC-SHA1',
74 'oauth_timestamp' => '12345678901',
75 'oauth_token' => '0987654321',
76 'oauth_version' => '1.0',
77 'oauth_signature' => '6fb42da0e32e07b61c9f0251fe627a9c~',
78 'custom_param1' => 'foo',
79 'custom_param2' => 'bar'
81 $client = $request->getRequestSchemeHeaderClient($params);
83 'OAuth realm="",oauth_consumer_key="1234567890",oauth_nonce="e807f1fcf82d132f9b'
84 .'b018ca6738a19f",oauth_signature_method="HMAC-SHA1",oauth_timestamp="'
85 .'12345678901",oauth_token="0987654321",oauth_version="1.0",oauth_sign'
86 .'ature="6fb42da0e32e07b61c9f0251fe627a9c~"',
87 $client->getHeader('Authorization')
91 public function testGetRequestSchemePostBodyClientSetsCorrectlyEncodedRawData()
93 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, null, $this->stubHttpUtility
);
95 'oauth_consumer_key' => '1234567890',
96 'oauth_nonce' => 'e807f1fcf82d132f9bb018ca6738a19f',
97 'oauth_signature_method' => 'HMAC-SHA1',
98 'oauth_timestamp' => '12345678901',
99 'oauth_token' => '0987654321',
100 'oauth_version' => '1.0',
101 'oauth_signature' => '6fb42da0e32e07b61c9f0251fe627a9c~',
102 'custom_param1' => 'foo',
103 'custom_param2' => 'bar'
105 $client = $request->getRequestSchemePostBodyClient($params);
107 'oauth_consumer_key=1234567890&oauth_nonce=e807f1fcf82d132f9bb018c'
108 .'a6738a19f&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345'
109 .'678901&oauth_token=0987654321&oauth_version=1.0&oauth_signature='
110 .'6fb42da0e32e07b61c9f0251fe627a9c~',
111 $client->getRawData()
115 public function testGetRequestSchemeQueryStringClientSetsCorrectlyEncodedQueryString()
117 $request = new Zend_Oauth_Http_AccessToken($this->stubConsumer
, null, $this->stubHttpUtility
);
119 'oauth_consumer_key' => '1234567890',
120 'oauth_nonce' => 'e807f1fcf82d132f9bb018ca6738a19f',
121 'oauth_signature_method' => 'HMAC-SHA1',
122 'oauth_timestamp' => '12345678901',
123 'oauth_token' => '0987654321',
124 'oauth_version' => '1.0',
125 'oauth_signature' => '6fb42da0e32e07b61c9f0251fe627a9c',
126 'custom_param1' => 'foo',
127 'custom_param2' => 'bar'
129 $client = $request->getRequestSchemeQueryStringClient($params, 'http://www.example.com');
131 'oauth_consumer_key=1234567890&oauth_nonce=e807f1fcf82d132f9bb018c'
132 .'a6738a19f&oauth_signature_method=HMAC-SHA1&oauth_timestamp=12345'
133 .'678901&oauth_token=0987654321&oauth_version=1.0&oauth_signature='
134 .'6fb42da0e32e07b61c9f0251fe627a9c',
135 $client->getUri()->getQuery()
141 class Test_Consumer_39745
extends Zend_Oauth_Consumer
143 public function getConsumerKey(){return '1234567890';}
144 public function getSignatureMethod(){return 'HMAC-SHA1';}
145 public function getVersion(){return '1.0';}
146 public function getAccessTokenUrl(){return 'http://www.example.com/access';}
147 public function getLastRequestToken()
149 $return = new Test_Token_39745
;
154 class Test_Http_Utility_39745
extends Zend_Oauth_Http_Utility
156 public function __construct(){}
157 public function generateNonce(){return md5('1234567890');}
158 public function generateTimestamp(){return '12345678901';}
159 public function sign(array $params, $signatureMethod, $consumerSecret,
160 $accessTokenSecret = null, $method = null, $url = null)
162 return md5('0987654321');
166 class Test_Client_39745
extends Zend_Http_Client
168 public function getRawData(){return $this->raw_post_data
;}
171 class Test_Token_39745
extends Zend_Oauth_Token_Request
173 public function getToken(){return '0987654321';}