OAuthUnitCommonStorageSymfonySessionTest

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

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/Common/Storage/SymfonySessionTest.php  
  1. class SymfonySessionTest extends \PHPUnit_Framework_TestCase 
  2. protected $session; 
  3.  
  4. protected $storage; 
  5.  
  6. public function setUp() 
  7. // set it 
  8. $this->session = new Session(new MockArraySessionStorage()); 
  9. $this->storage = new SymfonySession($this->session); 
  10.  
  11. public function tearDown() 
  12. // delete 
  13. $this->storage->getSession()->clear(); 
  14. unset($this->storage); 
  15.  
  16. /** 
  17. * Check that the token survives the constructor 
  18. */ 
  19. public function testStorageSurvivesConstructor() 
  20. $service = 'Facebook'; 
  21. $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  22.  
  23. // act 
  24. $this->storage->storeAccessToken($service, $token); 
  25. $this->storage = null; 
  26. $this->storage = new SymfonySession($this->session); 
  27.  
  28. // assert 
  29. $extraParams = $this->storage->retrieveAccessToken($service)->getExtraParams(); 
  30. $this->assertEquals('param', $extraParams['extra']); 
  31. $this->assertEquals($token, $this->storage->retrieveAccessToken($service)); 
  32.  
  33. /** 
  34. * Check that the token gets properly stored. 
  35. */ 
  36. public function testStorage() 
  37. // arrange 
  38. $service_1 = 'Facebook'; 
  39. $service_2 = 'Foursquare'; 
  40.  
  41. $token_1 = new StdOAuth2Token('access_1', 'refresh_1', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  42. $token_2 = new StdOAuth2Token('access_2', 'refresh_2', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  43.  
  44. // act 
  45. $this->storage->storeAccessToken($service_1, $token_1); 
  46. $this->storage->storeAccessToken($service_2, $token_2); 
  47.  
  48. // assert 
  49. $extraParams = $this->storage->retrieveAccessToken($service_1)->getExtraParams(); 
  50. $this->assertEquals('param', $extraParams['extra']); 
  51. $this->assertEquals($token_1, $this->storage->retrieveAccessToken($service_1)); 
  52. $this->assertEquals($token_2, $this->storage->retrieveAccessToken($service_2)); 
  53.  
  54. /** 
  55. * Test hasAccessToken. 
  56. */ 
  57. public function testHasAccessToken() 
  58. // arrange 
  59. $service = 'Facebook'; 
  60. $this->storage->clearToken($service); 
  61.  
  62. // act 
  63. // assert 
  64. $this->assertFalse($this->storage->hasAccessToken($service)); 
  65.  
  66. /** 
  67. * Check that the token gets properly deleted. 
  68. */ 
  69. public function testStorageClears() 
  70. // arrange 
  71. $service = 'Facebook'; 
  72. $token = new StdOAuth2Token('access', 'refresh', StdOAuth2Token::EOL_NEVER_EXPIRES, array('extra' => 'param')); 
  73.  
  74. // act 
  75. $this->storage->storeAccessToken($service, $token); 
  76. $this->storage->clearToken($service); 
  77.  
  78. // assert 
  79. $this->setExpectedException('OAuth\Common\Storage\Exception\TokenNotFoundException'); 
  80. $this->storage->retrieveAccessToken($service);