Permalink
Browse files

check the state is restored in the constructor

  • Loading branch information...
1 parent 21321ff commit 410947d9f9a1a751cf238bf89dcae65330233935 @daaku daaku committed Jul 16, 2012
Showing with 23 additions and 1 deletion.
  1. +1 −1 src/base_facebook.php
  2. +22 −0 tests/tests.php
View
2 src/base_facebook.php
@@ -219,7 +219,7 @@ public function __construct($config) {
$state = $this->getPersistentData('state');
if (!empty($state)) {
- $this->state = $this->getPersistentData('state');
+ $this->state = $state;
}
}
View
22 tests/tests.php
@@ -1148,6 +1148,14 @@ public function testEmptyResponseInCodeExchangeIsIgnored() {
$this->assertFalse($stub->publicGetAccessTokenFromCode('c', ''));
}
+ public function testExistingStateRestoredInConstructor() {
+ $fb = new FBPublicState(array(
+ 'appId' => self::APP_ID,
+ 'secret' => self::SECRET
+ ));
+ $this->assertEquals(FBPublicState::STATE, $fb->publicGetState());
+ }
+
public function testMissingAccessTokenInCodeExchangeIsIgnored() {
$methods_to_stub = array(
'_oauthRequest',
@@ -1331,3 +1339,17 @@ public function publicGetAccessTokenFromCode($code, $redirect_uri = null) {
return $this->getAccessTokenFromCode($code, $redirect_uri);
}
}
+
+class FBPublicState extends TransientFacebook {
+ const STATE = 'foo';
+ protected function getPersistentData($key, $default = false) {
+ if ($key === 'state') {
+ return self::STATE;
+ }
+ return parent::getPersistentData($key, $default);
+ }
+
+ public function publicGetState() {
+ return $this->state;
+ }
+}

0 comments on commit 410947d

Please sign in to comment.