Include all vendor files in the repo to be easier for people
This commit is contained in:
132
vendor/lusitanian/oauth/tests/Unit/Common/Storage/MemoryTest.php
vendored
Normal file
132
vendor/lusitanian/oauth/tests/Unit/Common/Storage/MemoryTest.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace OAuthTest\Unit\Common\Storage;
|
||||
|
||||
use OAuth\Common\Storage\Memory;
|
||||
|
||||
class MemoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
*/
|
||||
public function testConstructCorrectInterface()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::storeAccessToken
|
||||
*/
|
||||
public function testStoreAccessToken()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'\\OAuth\\Common\\Storage\\Memory',
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::retrieveAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::hasAccessToken
|
||||
*/
|
||||
public function testRetrieveAccessTokenValid()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::retrieveAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::hasAccessToken
|
||||
*/
|
||||
public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound()
|
||||
{
|
||||
$this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException');
|
||||
|
||||
$storage = new Memory();
|
||||
|
||||
$storage->retrieveAccessToken('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::hasAccessToken
|
||||
*/
|
||||
public function testHasAccessTokenTrue()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::hasAccessToken
|
||||
*/
|
||||
public function testHasAccessTokenFalse()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::clearToken
|
||||
*/
|
||||
public function testClearTokenIsNotSet()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::clearToken
|
||||
*/
|
||||
public function testClearTokenSet()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearToken('foo'));
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Memory::__construct
|
||||
* @covers OAuth\Common\Storage\Memory::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Memory::clearAllTokens
|
||||
*/
|
||||
public function testClearAllTokens()
|
||||
{
|
||||
$storage = new Memory();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
$storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
$this->assertTrue($storage->hasAccessToken('bar'));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Memory', $storage->clearAllTokens());
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
$this->assertFalse($storage->hasAccessToken('bar'));
|
||||
}
|
||||
}
|
||||
102
vendor/lusitanian/oauth/tests/Unit/Common/Storage/RedisTest.php
vendored
Normal file
102
vendor/lusitanian/oauth/tests/Unit/Common/Storage/RedisTest.php
vendored
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @category OAuth
|
||||
* @package Tests
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
namespace OAuth\Unit\Common\Storage;
|
||||
|
||||
use OAuth\Common\Storage\Redis;
|
||||
use Predis\Client as Predis;
|
||||
use OAuth\OAuth2\Token\StdOAuth2Token;
|
||||
|
||||
class RedisTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $storage;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// connect to a redis daemon
|
||||
$predis = new Predis(array(
|
||||
'host' => $_ENV['redis_host'],
|
||||
'port' => $_ENV['redis_port'],
|
||||
));
|
||||
|
||||
// set it
|
||||
$this->storage = new Redis($predis, 'test_user_token', 'test_user_state');
|
||||
|
||||
try {
|
||||
$predis->connect();
|
||||
} catch (\Predis\Connection\ConnectionException $e) {
|
||||
$this->markTestSkipped('No redis instance available: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// delete
|
||||
$this->storage->clearAllTokens();
|
||||
|
||||
// close connection
|
||||
$this->storage->getRedis()->quit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token gets properly stored.
|
||||
*/
|
||||
public function testStorage()
|
||||
{
|
||||
// arrange
|
||||
$service_1 = 'Facebook';
|
||||
$service_2 = 'Foursquare';
|
||||
|
||||
$token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
$token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service_1, $token_1);
|
||||
$this->storage->storeAccessToken($service_2, $token_2);
|
||||
|
||||
// assert
|
||||
$extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams();
|
||||
$this->assertEquals('param', $extraParams['extra']);
|
||||
$this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1));
|
||||
$this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hasAccessToken.
|
||||
*/
|
||||
public function testHasAccessToken()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// act
|
||||
// assert
|
||||
$this->assertFalse($this->storage->hasAccessToken($service));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token gets properly deleted.
|
||||
*/
|
||||
public function testStorageClears()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service, $token);
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// assert
|
||||
$this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException');
|
||||
$this->storage->retrieveAccessToken($service);
|
||||
}
|
||||
}
|
||||
245
vendor/lusitanian/oauth/tests/Unit/Common/Storage/SessionTest.php
vendored
Normal file
245
vendor/lusitanian/oauth/tests/Unit/Common/Storage/SessionTest.php
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
namespace OAuthTest\Unit\Common\Storage;
|
||||
|
||||
use OAuth\Common\Storage\Session;
|
||||
|
||||
class SessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConstructCorrectInterface()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConstructWithoutStartingSession()
|
||||
{
|
||||
session_start();
|
||||
|
||||
$storage = new Session(false);
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConstructTryingToStartWhileSessionAlreadyExists()
|
||||
{
|
||||
session_start();
|
||||
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testConstructWithExistingSessionKey()
|
||||
{
|
||||
session_start();
|
||||
|
||||
$_SESSION['lusitanian_oauth_token'] = array();
|
||||
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testStoreAccessTokenIsAlreadyArray()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'\\OAuth\\Common\\Storage\\Session',
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testStoreAccessTokenIsNotArray()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$_SESSION['lusitanian_oauth_token'] = 'foo';
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'\\OAuth\\Common\\Storage\\Session',
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::retrieveAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::hasAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testRetrieveAccessTokenValid()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::retrieveAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::hasAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound()
|
||||
{
|
||||
$this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException');
|
||||
|
||||
$storage = new Session();
|
||||
|
||||
$storage->retrieveAccessToken('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::hasAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testHasAccessTokenTrue()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::hasAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testHasAccessTokenFalse()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::clearToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testClearTokenIsNotSet()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::clearToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testClearTokenSet()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo'));
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::clearAllTokens
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testClearAllTokens()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
$storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
$storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface'));
|
||||
|
||||
$this->assertTrue($storage->hasAccessToken('foo'));
|
||||
$this->assertTrue($storage->hasAccessToken('bar'));
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearAllTokens());
|
||||
$this->assertFalse($storage->hasAccessToken('foo'));
|
||||
$this->assertFalse($storage->hasAccessToken('bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::__construct
|
||||
* @covers OAuth\Common\Storage\Session::__destruct
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testDestruct()
|
||||
{
|
||||
$storage = new Session();
|
||||
|
||||
unset($storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers OAuth\Common\Storage\Session::storeAccessToken
|
||||
* @covers OAuth\Common\Storage\Session::retrieveAccessToken
|
||||
*
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$mock = $this->getMock('\\OAuth\\Common\\Token\\AbstractToken', array('__sleep'));
|
||||
$mock->expects($this->once())
|
||||
->method('__sleep')
|
||||
->will($this->returnValue(array('accessToken')));
|
||||
|
||||
$storage = new Session();
|
||||
$storage->storeAccessToken('foo', $mock);
|
||||
$retrievedToken = $storage->retrieveAccessToken('foo');
|
||||
|
||||
$this->assertInstanceOf('\\OAuth\\Common\\Token\\AbstractToken', $retrievedToken);
|
||||
}
|
||||
}
|
||||
74
vendor/lusitanian/oauth/tests/Unit/Common/Storage/StorageTest.php
vendored
Normal file
74
vendor/lusitanian/oauth/tests/Unit/Common/Storage/StorageTest.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @category OAuth
|
||||
* @package Tests
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @author Hannes Van De Vreken <vandevreken.hannes@gmail.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
namespace OAuth\Unit\Common\Storage;
|
||||
|
||||
use \OAuth\OAuth2\Token\StdOAuth2Token;
|
||||
|
||||
abstract class StorageTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $storage;
|
||||
|
||||
/**
|
||||
* Check that the token gets properly stored.
|
||||
*/
|
||||
public function testStorage()
|
||||
{
|
||||
// arrange
|
||||
$service_1 = 'Facebook';
|
||||
$service_2 = 'Foursquare';
|
||||
|
||||
$token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
$token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service_1, $token_1);
|
||||
$this->storage->storeAccessToken($service_2, $token_2);
|
||||
|
||||
// assert
|
||||
$extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams();
|
||||
$this->assertEquals('param', $extraParams['extra']);
|
||||
$this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1));
|
||||
$this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hasAccessToken.
|
||||
*/
|
||||
public function testHasAccessToken()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// act
|
||||
// assert
|
||||
$this->assertFalse($this->storage->hasAccessToken($service));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token gets properly deleted.
|
||||
*/
|
||||
public function testStorageClears()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service, $token);
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// assert
|
||||
$this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException');
|
||||
$this->storage->retrieveAccessToken($service);
|
||||
}
|
||||
}
|
||||
111
vendor/lusitanian/oauth/tests/Unit/Common/Storage/SymfonySessionTest.php
vendored
Normal file
111
vendor/lusitanian/oauth/tests/Unit/Common/Storage/SymfonySessionTest.php
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @category OAuth
|
||||
* @package Tests
|
||||
* @author David Desberg <david@daviddesberg.com>
|
||||
* @copyright Copyright (c) 2012 The authors
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
namespace OAuth\Unit\Common\Storage;
|
||||
|
||||
use OAuth\Common\Storage\SymfonySession;
|
||||
use OAuth\OAuth2\Token\StdOAuth2Token;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class SymfonySessionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $session;
|
||||
|
||||
protected $storage;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
// set it
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
$this->storage = new SymfonySession($this->session);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// delete
|
||||
$this->storage->getSession()->clear();
|
||||
unset($this->storage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token survives the constructor
|
||||
*/
|
||||
public function testStorageSurvivesConstructor()
|
||||
{
|
||||
$service = 'Facebook';
|
||||
$token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service, $token);
|
||||
$this->storage = null;
|
||||
$this->storage = new SymfonySession($this->session);
|
||||
|
||||
// assert
|
||||
$extraParams = $this->storage->retrieveAccessToken($service)->getExtraParams();
|
||||
$this->assertEquals('param', $extraParams['extra']);
|
||||
$this->assertEquals($token, $this->storage->retrieveAccessToken($service));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token gets properly stored.
|
||||
*/
|
||||
public function testStorage()
|
||||
{
|
||||
// arrange
|
||||
$service_1 = 'Facebook';
|
||||
$service_2 = 'Foursquare';
|
||||
|
||||
$token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
$token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service_1, $token_1);
|
||||
$this->storage->storeAccessToken($service_2, $token_2);
|
||||
|
||||
// assert
|
||||
$extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams();
|
||||
$this->assertEquals('param', $extraParams['extra']);
|
||||
$this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1));
|
||||
$this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test hasAccessToken.
|
||||
*/
|
||||
public function testHasAccessToken()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// act
|
||||
// assert
|
||||
$this->assertFalse($this->storage->hasAccessToken($service));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that the token gets properly deleted.
|
||||
*/
|
||||
public function testStorageClears()
|
||||
{
|
||||
// arrange
|
||||
$service = 'Facebook';
|
||||
$token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param'));
|
||||
|
||||
// act
|
||||
$this->storage->storeAccessToken($service, $token);
|
||||
$this->storage->clearToken($service);
|
||||
|
||||
// assert
|
||||
$this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException');
|
||||
$this->storage->retrieveAccessToken($service);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user