2012-11-22 16:24:21 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Mockery as m;
|
2013-02-08 10:32:26 +00:00
|
|
|
use JacobKiers\OAuth\HmacSha1;
|
2012-11-22 16:24:21 +00:00
|
|
|
|
|
|
|
class HmacSha1Test extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
m::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSignatureName()
|
|
|
|
{
|
|
|
|
$hmacsha1 = $this->getSignatureMethod();
|
|
|
|
$this->assertEquals('HMAC-SHA1', $hmacsha1->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBuildSignatureWithoutToken()
|
|
|
|
{
|
|
|
|
// Create instance of class to test
|
|
|
|
$hmacsha1 = $this->getSignatureMethod();
|
|
|
|
|
|
|
|
// Get mock objects
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$client = $this->getClient();
|
|
|
|
|
|
|
|
// Run method being tested
|
|
|
|
$signature = $hmacsha1->buildSignature($request, $client);
|
|
|
|
|
|
|
|
// Check results
|
|
|
|
$this->assertEquals('RaZU4UG/wwJ/E5Df2/pePmwaS1Q=', $signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBuildSignatureWithToken()
|
|
|
|
{
|
|
|
|
// Create instance of class to test
|
|
|
|
$hmacsha1 = $this->getSignatureMethod();
|
|
|
|
|
|
|
|
// Get mock objects
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$client = $this->getClient();
|
|
|
|
$token = $this->getToken();
|
|
|
|
|
|
|
|
// Run method being tested
|
|
|
|
$signature = $hmacsha1->buildSignature($request, $client, $token);
|
|
|
|
|
|
|
|
// Check results
|
|
|
|
$this->assertEquals('1P/rfHzjnxBcNzngW9BEuT01goM=', $signature);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSignatureMethod()
|
|
|
|
{
|
|
|
|
return new HmacSha1;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getRequest()
|
|
|
|
{
|
2013-02-08 10:32:26 +00:00
|
|
|
return m::mock('JacobKiers\OAuth\Request', function ($mock) {
|
2013-02-08 10:57:53 +00:00
|
|
|
$mock->shouldReceive('getOAuthSignatureBaseString')
|
2012-11-22 16:24:21 +00:00
|
|
|
->withNoArgs()
|
|
|
|
->andReturn('POST&http%3A%2F%2Fexample.com%2Ffoobar&oauth_signature_method%3DHMAC-SHA1')->once();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getClient()
|
|
|
|
{
|
2013-02-08 10:32:26 +00:00
|
|
|
return m::mock('JacobKiers\OAuth\Client', function ($mock) {
|
2012-11-22 16:24:21 +00:00
|
|
|
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getToken()
|
|
|
|
{
|
2013-02-08 10:32:26 +00:00
|
|
|
return m::mock('JacobKiers\OAuth\Token', function ($mock) {
|
2012-11-22 16:24:21 +00:00
|
|
|
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|