2012-11-23 12:22:04 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Mockery as m;
|
2013-02-11 14:02:14 +00:00
|
|
|
use JacobKiers\OAuth\SignatureMethod\SignatureMethod;
|
2012-11-23 12:22:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create concrete class from abstract SignatureMethod.
|
|
|
|
*
|
|
|
|
* Have to define two methods which are abstract in SignatureMethod.
|
|
|
|
*/
|
|
|
|
class FooBarSignatureMethod extends SignatureMethod
|
|
|
|
{
|
|
|
|
public function getName() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSignature(
|
2013-02-11 14:02:14 +00:00
|
|
|
\JacobKiers\OAuth\Request\RequestInterface $request,
|
|
|
|
\JacobKiers\OAuth\Consumer\ConsumerInterface $consumer,
|
|
|
|
\JacobKiers\OAuth\Token\TokenInterface $token = null
|
2012-11-23 12:22:04 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class SignatureTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
m::close();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSignatureKeyWithoutToken()
|
|
|
|
{
|
|
|
|
// Create instance of class to test, with mock objects passed in.
|
|
|
|
$signature_method = $this->getSignatureMethod();
|
|
|
|
|
|
|
|
// Get mock objects
|
2013-02-11 14:02:14 +00:00
|
|
|
$consumer = $this->getConsumer();
|
2012-11-23 12:22:04 +00:00
|
|
|
|
|
|
|
// Run method being tested
|
2013-02-11 14:02:14 +00:00
|
|
|
$signature_key = $signature_method->getSignatureKey($consumer);
|
2012-11-23 12:22:04 +00:00
|
|
|
|
|
|
|
// Check results
|
|
|
|
$this->assertEquals('secret&', $signature_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSignatureKeyWithToken()
|
|
|
|
{
|
|
|
|
// Create instance of class to test, with mock objects passed in.
|
|
|
|
$signature_method = $this->getSignatureMethod();
|
|
|
|
|
|
|
|
// Get mock objects
|
2013-02-11 14:02:14 +00:00
|
|
|
$consumer = $this->getConsumer();
|
2012-11-23 12:22:04 +00:00
|
|
|
$token = $this->getToken();
|
|
|
|
|
|
|
|
// Run method being tested
|
2013-02-11 14:02:14 +00:00
|
|
|
$signature_key = $signature_method->getSignatureKey($consumer, $token);
|
2012-11-23 12:22:04 +00:00
|
|
|
|
|
|
|
// Check results
|
|
|
|
$this->assertEquals('secret&token_secret', $signature_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getSignatureMethod()
|
|
|
|
{
|
|
|
|
return new FooBarSignatureMethod;
|
|
|
|
}
|
|
|
|
|
2013-02-11 14:02:14 +00:00
|
|
|
private function getConsumer()
|
2012-11-23 12:22:04 +00:00
|
|
|
{
|
2013-02-11 14:02:14 +00:00
|
|
|
return m::mock('JacobKiers\OAuth\Consumer\Consumer', function ($mock) {
|
2012-11-23 12:22:04 +00:00
|
|
|
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getToken()
|
|
|
|
{
|
2013-02-11 14:02:14 +00:00
|
|
|
return m::mock('JacobKiers\OAuth\Token\Token', function ($mock) {
|
2012-11-23 12:22:04 +00:00
|
|
|
$mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|