OAuthUnitCommonStorageRedisTest

The Gravity Forms Salesforce Add-On OAuth Unit Common Storage RedisTest class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/tests/Unit/Common/Storage/RedisTest.php  
  1. class RedisTest extends \PHPUnit_Framework_TestCase 
  2. protected $storage; 
  3.  
  4. public function setUp() 
  5. // connect to a redis daemon 
  6. $predis = new Predis(array( 
  7. 'host' => $_ENV['redis_host'],  
  8. 'port' => $_ENV['redis_port'],  
  9. )); 
  10.  
  11. // set it 
  12. $this->storage = new Redis($predis, 'test_user_token', 'test_user_state'); 
  13.  
  14. try { 
  15. $predis->connect(); 
  16. } catch (\Predis\Connection\ConnectionException $e) { 
  17. $this->markTestSkipped('No redis instance available: ' . $e->getMessage()); 
  18.  
  19. public function tearDown() 
  20. // delete 
  21. $this->storage->clearAllTokens(); 
  22.  
  23. // close connection 
  24. $this->storage->getRedis()->quit(); 
  25.  
  26. /** 
  27. * Check that the token gets properly stored. 
  28. */ 
  29. public function testStorage() 
  30. // arrange 
  31. $service_1 = 'Facebook'; 
  32. $service_2 = 'Foursquare'; 
  33.  
  34. $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  35. $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  36.  
  37. // act 
  38. $this->storage->storeAccessToken($service_1, $token_1); 
  39. $this->storage->storeAccessToken($service_2, $token_2); 
  40.  
  41. // assert 
  42. $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); 
  43. $this->assertEquals('param', $extraParams['extra']); 
  44. $this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); 
  45. $this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); 
  46.  
  47. /** 
  48. * Test hasAccessToken. 
  49. */ 
  50. public function testHasAccessToken() 
  51. // arrange 
  52. $service = 'Facebook'; 
  53. $this->storage->clearToken($service); 
  54.  
  55. // act 
  56. // assert 
  57. $this->assertFalse($this->storage->hasAccessToken($service)); 
  58.  
  59. /** 
  60. * Check that the token gets properly deleted. 
  61. */ 
  62. public function testStorageClears() 
  63. // arrange 
  64. $service = 'Facebook'; 
  65. $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  66.  
  67. // act 
  68. $this->storage->storeAccessToken($service, $token); 
  69. $this->storage->clearToken($service); 
  70.  
  71. // assert 
  72. $this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); 
  73. $this->storage->retrieveAccessToken($service);