|
1 |
| -<?php |
2 |
| - |
3 |
| -use Facebook\FacebookRedirectLoginHelper; |
4 |
| -use Facebook\FacebookRequest; |
5 |
| - |
6 |
| -class FacebookRedirectLoginHelperTest extends PHPUnit_Framework_TestCase |
7 |
| -{ |
8 |
| - |
9 |
| - const REDIRECT_URL = 'http://invalid.zzz'; |
10 |
| - |
11 |
| - public function testLoginURL() |
12 |
| - { |
13 |
| - $helper = new FacebookRedirectLoginHelper( |
14 |
| - self::REDIRECT_URL, |
15 |
| - FacebookTestCredentials::$appId, |
16 |
| - FacebookTestCredentials::$appSecret |
17 |
| - ); |
18 |
| - $helper->disableSessionStatusCheck(); |
19 |
| - $loginUrl = $helper->getLoginUrl(); |
20 |
| - $state = $_SESSION['FBRLH_state']; |
21 |
| - $params = array( |
22 |
| - 'client_id' => FacebookTestCredentials::$appId, |
23 |
| - 'redirect_uri' => self::REDIRECT_URL, |
24 |
| - 'state' => $state, |
25 |
| - 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
26 |
| - 'scope' => implode(',', array()) |
27 |
| - ); |
28 |
| - $expectedUrl = 'https://www.facebook.com/v2.0/dialog/oauth?'; |
29 |
| - $this->assertTrue(strpos($loginUrl, $expectedUrl) !== false); |
30 |
| - foreach ($params as $key => $value) { |
31 |
| - $this->assertTrue( |
32 |
| - strpos($loginUrl, $key . '=' . urlencode($value)) !== false |
33 |
| - ); |
34 |
| - } |
35 |
| - } |
36 |
| - |
37 |
| - public function testLogoutURL() |
38 |
| - { |
39 |
| - $helper = new FacebookRedirectLoginHelper( |
40 |
| - self::REDIRECT_URL, |
41 |
| - FacebookTestCredentials::$appId, |
42 |
| - FacebookTestCredentials::$appSecret |
43 |
| - ); |
44 |
| - $helper->disableSessionStatusCheck(); |
45 |
| - $logoutUrl = $helper->getLogoutUrl( |
46 |
| - FacebookTestHelper::$testSession, self::REDIRECT_URL |
47 |
| - ); |
48 |
| - $params = array( |
49 |
| - 'next' => self::REDIRECT_URL, |
50 |
| - 'access_token' => FacebookTestHelper::$testSession->getToken() |
51 |
| - ); |
52 |
| - $expectedUrl = 'https://www.facebook.com/logout.php?'; |
53 |
| - $this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false); |
54 |
| - foreach ($params as $key => $value) { |
55 |
| - $this->assertTrue( |
56 |
| - strpos($logoutUrl, $key . '=' . urlencode($value)) !== false |
57 |
| - ); |
58 |
| - } |
59 |
| - } |
60 |
| - |
61 |
| -} |
| 1 | +<?php |
| 2 | + |
| 3 | +use Facebook\FacebookRedirectLoginHelper; |
| 4 | +use Facebook\FacebookRequest; |
| 5 | + |
| 6 | +class FacebookRedirectLoginHelperTest extends PHPUnit_Framework_TestCase |
| 7 | +{ |
| 8 | + |
| 9 | + const REDIRECT_URL = 'http://invalid.zzz'; |
| 10 | + |
| 11 | + public function testLoginURL() |
| 12 | + { |
| 13 | + $helper = new FacebookRedirectLoginHelper( |
| 14 | + self::REDIRECT_URL, |
| 15 | + FacebookTestCredentials::$appId, |
| 16 | + FacebookTestCredentials::$appSecret |
| 17 | + ); |
| 18 | + $helper->disableSessionStatusCheck(); |
| 19 | + $loginUrl = $helper->getLoginUrl(); |
| 20 | + $state = $_SESSION['FBRLH_state']; |
| 21 | + $params = array( |
| 22 | + 'client_id' => FacebookTestCredentials::$appId, |
| 23 | + 'redirect_uri' => self::REDIRECT_URL, |
| 24 | + 'state' => $state, |
| 25 | + 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, |
| 26 | + 'scope' => implode(',', array()) |
| 27 | + ); |
| 28 | + $expectedUrl = 'https://www.facebook.com/v2.0/dialog/oauth?'; |
| 29 | + $this->assertTrue(strpos($loginUrl, $expectedUrl) !== false); |
| 30 | + foreach ($params as $key => $value) { |
| 31 | + $this->assertTrue( |
| 32 | + strpos($loginUrl, $key . '=' . urlencode($value)) !== false |
| 33 | + ); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + public function testLogoutURL() |
| 38 | + { |
| 39 | + $helper = new FacebookRedirectLoginHelper( |
| 40 | + self::REDIRECT_URL, |
| 41 | + FacebookTestCredentials::$appId, |
| 42 | + FacebookTestCredentials::$appSecret |
| 43 | + ); |
| 44 | + $helper->disableSessionStatusCheck(); |
| 45 | + $logoutUrl = $helper->getLogoutUrl( |
| 46 | + FacebookTestHelper::$testSession, self::REDIRECT_URL |
| 47 | + ); |
| 48 | + $params = array( |
| 49 | + 'next' => self::REDIRECT_URL, |
| 50 | + 'access_token' => FacebookTestHelper::$testSession->getToken() |
| 51 | + ); |
| 52 | + $expectedUrl = 'https://www.facebook.com/logout.php?'; |
| 53 | + $this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false); |
| 54 | + foreach ($params as $key => $value) { |
| 55 | + $this->assertTrue( |
| 56 | + strpos($logoutUrl, $key . '=' . urlencode($value)) !== false |
| 57 | + ); |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + public function testCSPRNG() |
| 62 | + { |
| 63 | + $helper = new FacebookRedirectLoginHelper( |
| 64 | + self::REDIRECT_URL, |
| 65 | + FacebookTestCredentials::$appId, |
| 66 | + FacebookTestCredentials::$appSecret |
| 67 | + ); |
| 68 | + $this->assertTrue(preg_match('/^([0-9a-f]+)$/', $helper->random(32))); |
| 69 | + } |
| 70 | + |
| 71 | +} |
0 commit comments