OAuthTestUnitCommonStorageSessionTest

The Gravity Forms Salesforce Add-On OAuthTest Unit Common Storage SessionTest class.

Defined (1)

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

/lib/PHPoAuthLib/tests/Unit/Common/Storage/SessionTest.php  
  1. class SessionTest extends \PHPUnit_Framework_TestCase 
  2. /** 
  3. * @covers OAuth\Common\Storage\Session::__construct 
  4. * @runInSeparateProcess 
  5. */ 
  6. public function testConstructCorrectInterface() 
  7. $storage = new Session(); 
  8.  
  9. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); 
  10.  
  11. /** 
  12. * @covers OAuth\Common\Storage\Session::__construct 
  13. * @runInSeparateProcess 
  14. */ 
  15. public function testConstructWithoutStartingSession() 
  16. session_start(); 
  17.  
  18. $storage = new Session(false); 
  19.  
  20. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); 
  21.  
  22. /** 
  23. * @covers OAuth\Common\Storage\Session::__construct 
  24. * @runInSeparateProcess 
  25. */ 
  26. public function testConstructTryingToStartWhileSessionAlreadyExists() 
  27. session_start(); 
  28.  
  29. $storage = new Session(); 
  30.  
  31. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); 
  32.  
  33. /** 
  34. * @covers OAuth\Common\Storage\Session::__construct 
  35. * @runInSeparateProcess 
  36. */ 
  37. public function testConstructWithExistingSessionKey() 
  38. session_start(); 
  39.  
  40. $_SESSION['lusitanian_oauth_token'] = array(); 
  41.  
  42. $storage = new Session(); 
  43.  
  44. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\TokenStorageInterface', $storage); 
  45.  
  46. /** 
  47. * @covers OAuth\Common\Storage\Session::__construct 
  48. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  49. * @runInSeparateProcess 
  50. */ 
  51. public function testStoreAccessTokenIsAlreadyArray() 
  52. $storage = new Session(); 
  53.  
  54. $this->assertInstanceOf( 
  55. '\\OAuth\\Common\\Storage\\Session',  
  56. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) 
  57. ); 
  58.  
  59. /** 
  60. * @covers OAuth\Common\Storage\Session::__construct 
  61. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  62. * @runInSeparateProcess 
  63. */ 
  64. public function testStoreAccessTokenIsNotArray() 
  65. $storage = new Session(); 
  66.  
  67. $_SESSION['lusitanian_oauth_token'] = 'foo'; 
  68.  
  69. $this->assertInstanceOf( 
  70. '\\OAuth\\Common\\Storage\\Session',  
  71. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')) 
  72. ); 
  73.  
  74. /** 
  75. * @covers OAuth\Common\Storage\Session::__construct 
  76. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  77. * @covers OAuth\Common\Storage\Session::retrieveAccessToken 
  78. * @covers OAuth\Common\Storage\Session::hasAccessToken 
  79. * @runInSeparateProcess 
  80. */ 
  81. public function testRetrieveAccessTokenValid() 
  82. $storage = new Session(); 
  83.  
  84. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); 
  85.  
  86. $this->assertInstanceOf('\\OAuth\\Common\\Token\\TokenInterface', $storage->retrieveAccessToken('foo')); 
  87.  
  88. /** 
  89. * @covers OAuth\Common\Storage\Session::__construct 
  90. * @covers OAuth\Common\Storage\Session::retrieveAccessToken 
  91. * @covers OAuth\Common\Storage\Session::hasAccessToken 
  92. * @runInSeparateProcess 
  93. */ 
  94. public function testRetrieveAccessTokenThrowsExceptionWhenTokenIsNotFound() 
  95. $this->setExpectedException('\\OAuth\\Common\\Storage\\Exception\\TokenNotFoundException'); 
  96.  
  97. $storage = new Session(); 
  98.  
  99. $storage->retrieveAccessToken('foo'); 
  100.  
  101. /** 
  102. * @covers OAuth\Common\Storage\Session::__construct 
  103. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  104. * @covers OAuth\Common\Storage\Session::hasAccessToken 
  105. * @runInSeparateProcess 
  106. */ 
  107. public function testHasAccessTokenTrue() 
  108. $storage = new Session(); 
  109.  
  110. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); 
  111.  
  112. $this->assertTrue($storage->hasAccessToken('foo')); 
  113.  
  114. /** 
  115. * @covers OAuth\Common\Storage\Session::__construct 
  116. * @covers OAuth\Common\Storage\Session::hasAccessToken 
  117. * @runInSeparateProcess 
  118. */ 
  119. public function testHasAccessTokenFalse() 
  120. $storage = new Session(); 
  121.  
  122. $this->assertFalse($storage->hasAccessToken('foo')); 
  123.  
  124. /** 
  125. * @covers OAuth\Common\Storage\Session::__construct 
  126. * @covers OAuth\Common\Storage\Session::clearToken 
  127. * @runInSeparateProcess 
  128. */ 
  129. public function testClearTokenIsNotSet() 
  130. $storage = new Session(); 
  131.  
  132. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo')); 
  133.  
  134. /** 
  135. * @covers OAuth\Common\Storage\Session::__construct 
  136. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  137. * @covers OAuth\Common\Storage\Session::clearToken 
  138. * @runInSeparateProcess 
  139. */ 
  140. public function testClearTokenSet() 
  141. $storage = new Session(); 
  142.  
  143. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); 
  144.  
  145. $this->assertTrue($storage->hasAccessToken('foo')); 
  146. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearToken('foo')); 
  147. $this->assertFalse($storage->hasAccessToken('foo')); 
  148.  
  149. /** 
  150. * @covers OAuth\Common\Storage\Session::__construct 
  151. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  152. * @covers OAuth\Common\Storage\Session::clearAllTokens 
  153. * @runInSeparateProcess 
  154. */ 
  155. public function testClearAllTokens() 
  156. $storage = new Session(); 
  157.  
  158. $storage->storeAccessToken('foo', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); 
  159. $storage->storeAccessToken('bar', $this->getMock('\\OAuth\\Common\\Token\\TokenInterface')); 
  160.  
  161. $this->assertTrue($storage->hasAccessToken('foo')); 
  162. $this->assertTrue($storage->hasAccessToken('bar')); 
  163. $this->assertInstanceOf('\\OAuth\\Common\\Storage\\Session', $storage->clearAllTokens()); 
  164. $this->assertFalse($storage->hasAccessToken('foo')); 
  165. $this->assertFalse($storage->hasAccessToken('bar')); 
  166.  
  167. /** 
  168. * @covers OAuth\Common\Storage\Session::__construct 
  169. * @covers OAuth\Common\Storage\Session::__destruct 
  170. * @runInSeparateProcess 
  171. */ 
  172. public function testDestruct() 
  173. $storage = new Session(); 
  174.  
  175. unset($storage); 
  176.  
  177. /** 
  178. * @covers OAuth\Common\Storage\Session::storeAccessToken 
  179. * @covers OAuth\Common\Storage\Session::retrieveAccessToken 
  180. * @runInSeparateProcess 
  181. */ 
  182. public function testSerializeUnserialize() 
  183. $mock = $this->getMock('\\OAuth\\Common\\Token\\AbstractToken', array('__sleep')); 
  184. $mock->expects($this->once()) 
  185. ->method('__sleep') 
  186. ->will($this->returnValue(array('accessToken'))); 
  187.  
  188. $storage = new Session(); 
  189. $storage->storeAccessToken('foo', $mock); 
  190. $retrievedToken = $storage->retrieveAccessToken('foo'); 
  191.  
  192. $this->assertInstanceOf('\\OAuth\\Common\\Token\\AbstractToken', $retrievedToken);