diff options
Diffstat (limited to 'lib/facebook-graph-sdk/tests')
69 files changed, 1504 insertions, 316 deletions
diff --git a/lib/facebook-graph-sdk/tests/Authentication/AccessTokenMetadataTest.php b/lib/facebook-graph-sdk/tests/Authentication/AccessTokenMetadataTest.php new file mode 100644 index 0000000..1900492 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Authentication/AccessTokenMetadataTest.php @@ -0,0 +1,138 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Authentication; + +use Facebook\Authentication\AccessTokenMetadata; + +class AccessTokenMetadataTest extends \PHPUnit_Framework_TestCase +{ + + protected $graphResponseData = [ + 'data' => [ + 'app_id' => '123', + 'application' => 'Foo App', + 'error' => [ + 'code' => 190, + 'message' => 'Foo error message.', + 'subcode' => 463, + ], + 'issued_at' => 1422110200, + 'expires_at' => 1422115200, + 'is_valid' => false, + 'metadata' => [ + 'sso' => 'iphone-sso', + 'auth_type' => 'rerequest', + 'auth_nonce' => 'no-replicatey', + ], + 'scopes' => ['public_profile', 'basic_info', 'user_friends'], + 'profile_id' => '1000', + 'user_id' => '1337', + ], + ]; + + public function testDatesGetCastToDateTime() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + + $expires = $metadata->getExpiresAt(); + $issuedAt = $metadata->getIssuedAt(); + + $this->assertInstanceOf('DateTime', $expires); + $this->assertInstanceOf('DateTime', $issuedAt); + } + + public function testAllTheGettersReturnTheProperValue() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + + $this->assertEquals('123', $metadata->getAppId()); + $this->assertEquals('Foo App', $metadata->getApplication()); + $this->assertTrue($metadata->isError(), 'Expected an error'); + $this->assertEquals('190', $metadata->getErrorCode()); + $this->assertEquals('Foo error message.', $metadata->getErrorMessage()); + $this->assertEquals('463', $metadata->getErrorSubcode()); + $this->assertFalse($metadata->getIsValid(), 'Expected the access token to not be valid'); + $this->assertEquals('iphone-sso', $metadata->getSso()); + $this->assertEquals('rerequest', $metadata->getAuthType()); + $this->assertEquals('no-replicatey', $metadata->getAuthNonce()); + $this->assertEquals('1000', $metadata->getProfileId()); + $this->assertEquals(['public_profile', 'basic_info', 'user_friends'], $metadata->getScopes()); + $this->assertEquals('1337', $metadata->getUserId()); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testInvalidMetadataWillThrow() + { + new AccessTokenMetadata(['foo' => 'bar']); + } + + public function testAnExpectedAppIdWillNotThrow() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateAppId('123'); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testAnUnexpectedAppIdWillThrow() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateAppId('foo'); + } + + public function testAnExpectedUserIdWillNotThrow() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateUserId('1337'); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testAnUnexpectedUserIdWillThrow() + { + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateUserId('foo'); + } + + public function testAnActiveAccessTokenWillNotThrow() + { + $this->graphResponseData['data']['expires_at'] = time() + 1000; + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateExpiration(); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testAnExpiredAccessTokenWillThrow() + { + $this->graphResponseData['data']['expires_at'] = time() - 1000; + $metadata = new AccessTokenMetadata($this->graphResponseData); + $metadata->validateExpiration(); + } +} diff --git a/lib/facebook-graph-sdk/tests/Authentication/AccessTokenTest.php b/lib/facebook-graph-sdk/tests/Authentication/AccessTokenTest.php index d66a5ba..39e42d4 100644 --- a/lib/facebook-graph-sdk/tests/Authentication/AccessTokenTest.php +++ b/lib/facebook-graph-sdk/tests/Authentication/AccessTokenTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Authentication/FooFacebookClientForOAuth2Test.php b/lib/facebook-graph-sdk/tests/Authentication/FooFacebookClientForOAuth2Test.php index 1199b00..8c59ae1 100644 --- a/lib/facebook-graph-sdk/tests/Authentication/FooFacebookClientForOAuth2Test.php +++ b/lib/facebook-graph-sdk/tests/Authentication/FooFacebookClientForOAuth2Test.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Authentication/OAuth2ClientTest.php b/lib/facebook-graph-sdk/tests/Authentication/OAuth2ClientTest.php index 72a8e2a..5b144d7 100644 --- a/lib/facebook-graph-sdk/tests/Authentication/OAuth2ClientTest.php +++ b/lib/facebook-graph-sdk/tests/Authentication/OAuth2ClientTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -23,7 +23,6 @@ */ namespace Facebook\Tests\Authentication; -use Mockery as m; use Facebook\Facebook; use Facebook\FacebookApp; use Facebook\Authentication\OAuth2Client; @@ -46,7 +45,7 @@ class OAuth2ClientTest extends \PHPUnit_Framework_TestCase */ protected $oauth; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_secret'); $this->client = new FooFacebookClientForOAuth2Test(); diff --git a/lib/facebook-graph-sdk/tests/Exceptions/FacebookResponseExceptionTest.php b/lib/facebook-graph-sdk/tests/Exceptions/FacebookResponseExceptionTest.php index 107a9b9..ae18fde 100644 --- a/lib/facebook-graph-sdk/tests/Exceptions/FacebookResponseExceptionTest.php +++ b/lib/facebook-graph-sdk/tests/Exceptions/FacebookResponseExceptionTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -36,7 +36,7 @@ class FacebookResponseExceptionTest extends \PHPUnit_Framework_TestCase */ protected $request; - public function setUp() + protected function setUp() { $this->request = new FacebookRequest(new FacebookApp('123', 'foo')); } diff --git a/lib/facebook-graph-sdk/tests/FacebookAppTest.php b/lib/facebook-graph-sdk/tests/FacebookAppTest.php index d1b453d..de08477 100644 --- a/lib/facebook-graph-sdk/tests/FacebookAppTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookAppTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -32,7 +32,7 @@ class FacebookAppTest extends \PHPUnit_Framework_TestCase */ private $app; - public function setUp() + protected function setUp() { $this->app = new FacebookApp('id', 'secret'); } @@ -63,4 +63,19 @@ class FacebookAppTest extends \PHPUnit_Framework_TestCase $this->assertEquals('id', $newApp->getId()); $this->assertEquals('secret', $newApp->getSecret()); } + + /** + * @expectedException \Facebook\Exceptions\FacebookSDKException + */ + public function testOverflowIntegersWillThrow() + { + new FacebookApp(PHP_INT_MAX + 1, "foo"); + } + + public function testUnserializedIdsWillBeString() + { + $newApp = unserialize(serialize(new FacebookApp(1, "foo"))); + + $this->assertSame('1', $newApp->getId()); + } } diff --git a/lib/facebook-graph-sdk/tests/FacebookBatchRequestTest.php b/lib/facebook-graph-sdk/tests/FacebookBatchRequestTest.php index cef0586..a77e754 100755 --- a/lib/facebook-graph-sdk/tests/FacebookBatchRequestTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookBatchRequestTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -36,7 +36,7 @@ class FacebookBatchRequestTest extends \PHPUnit_Framework_TestCase */ private $app; - public function setUp() + protected function setUp() { $this->app = new FacebookApp('123', 'foo_secret'); } @@ -280,6 +280,31 @@ class FacebookBatchRequestTest extends \PHPUnit_Framework_TestCase ], $batchRequestArray); } + public function testBatchRequestsWithOptionsGetConvertedToAnArray() + { + $request = new FacebookRequest(null, null, 'GET', '/bar'); + $batchRequest = $this->createBatchRequest(); + $batchRequest->add($request, [ + 'name' => 'foo_name', + 'omit_response_on_success' => false, + ]); + + $requests = $batchRequest->getRequests(); + + $options = $requests[0]['options']; + $options['name'] = $requests[0]['name']; + + $batchRequestArray = $batchRequest->requestEntityToBatchArray($requests[0]['request'], $options); + + $this->assertEquals([ + 'headers' => $this->defaultHeaders(), + 'method' => 'GET', + 'relative_url' => '/' . Facebook::DEFAULT_GRAPH_VERSION . '/bar?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', + 'name' => 'foo_name', + 'omit_response_on_success' => false, + ], $batchRequestArray); + } + public function testPreppingABatchRequestProperlySetsThePostParams() { $batchRequest = $this->createBatchRequest(); @@ -328,6 +353,30 @@ class FacebookBatchRequestTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedBatchParams, $params); } + public function testPreppingABatchRequestWithOptionsProperlySetsThePostParams() + { + $batchRequest = $this->createBatchRequest(); + $batchRequest->add(new FacebookRequest(null, null, 'GET', '/foo'), [ + 'name' => 'foo_name', + 'omit_response_on_success' => false, + ]); + + $batchRequest->prepareRequestsForBatch(); + $params = $batchRequest->getParams(); + + $expectedHeaders = json_encode($this->defaultHeaders()); + $version = Facebook::DEFAULT_GRAPH_VERSION; + + $expectedBatchParams = [ + 'batch' => '[{"headers":' . $expectedHeaders . ',"method":"GET","relative_url":"\\/' . $version . '\\/foo?access_token=foo_token&appsecret_proof=df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9",' + . '"name":"foo_name","omit_response_on_success":false}]', + 'include_headers' => true, + 'access_token' => 'foo_token', + 'appsecret_proof' => 'df4256903ba4e23636cc142117aa632133d75c642bd2a68955be1443bd14deb9', + ]; + $this->assertEquals($expectedBatchParams, $params); + } + private function assertRequestContainsAppAndToken(FacebookRequest $request, FacebookApp $expectedApp, $expectedToken) { $app = $request->getApp(); @@ -373,7 +422,9 @@ class FacebookBatchRequestTest extends \PHPUnit_Framework_TestCase foreach ($requests as $name => $request) { $expectedRequests[] = [ 'name' => $name, - 'request' => $request + 'request' => $request, + 'attached_files' => null, + 'options' => [], ]; } $this->assertEquals($expectedRequests, $formattedRequests); diff --git a/lib/facebook-graph-sdk/tests/FacebookBatchResponseTest.php b/lib/facebook-graph-sdk/tests/FacebookBatchResponseTest.php index dec92a1..8f4e5a8 100755 --- a/lib/facebook-graph-sdk/tests/FacebookBatchResponseTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookBatchResponseTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -41,7 +41,7 @@ class FacebookBatchResponseTest extends \PHPUnit_Framework_TestCase */ protected $request; - public function setUp() + protected function setUp() { $this->app = new FacebookApp('123', 'foo_secret'); $this->request = new FacebookRequest( @@ -135,4 +135,30 @@ class FacebookBatchResponseTest extends \PHPUnit_Framework_TestCase $this->assertEquals('foo_token_two', $batchResponse[1]->getAccessToken()); $this->assertEquals('foo_token_three', $batchResponse[2]->getAccessToken()); } + + public function testHeadersFromBatchRequestCanBeAccessed() + { + $graphResponseJson = '['; + $graphResponseJson .= '{"code":200,"headers":[{"name":"Facebook-API-Version","value":"v2.0"},{"name":"ETag","value":"\"fooTag\""}],"body":"{\"foo\":\"bar\"}"}'; + $graphResponseJson .= ',{"code":200,"headers":[{"name":"Facebook-API-Version","value":"v2.5"},{"name":"ETag","value":"\"barTag\""}],"body":"{\"foo\":\"bar\"}"}'; + $graphResponseJson .= ']'; + $response = new FacebookResponse($this->request, $graphResponseJson, 200); + + $requests = [ + new FacebookRequest($this->app, 'foo_token_one', 'GET', '/me'), + new FacebookRequest($this->app, 'foo_token_two', 'GET', '/you'), + ]; + + $batchRequest = new FacebookBatchRequest($this->app, $requests); + $batchResponse = new FacebookBatchResponse($batchRequest, $response); + + $this->assertEquals('v2.0', $batchResponse[0]->getGraphVersion()); + $this->assertEquals('"fooTag"', $batchResponse[0]->getETag()); + $this->assertEquals('v2.5', $batchResponse[1]->getGraphVersion()); + $this->assertEquals('"barTag"', $batchResponse[1]->getETag()); + $this->assertEquals([ + 'Facebook-API-Version' => 'v2.5', + 'ETag' => '"barTag"', + ], $batchResponse[1]->getHeaders()); + } } diff --git a/lib/facebook-graph-sdk/tests/FacebookClientTest.php b/lib/facebook-graph-sdk/tests/FacebookClientTest.php index 6e9bb6c..9a08fb6 100644 --- a/lib/facebook-graph-sdk/tests/FacebookClientTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookClientTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -29,36 +29,14 @@ use Facebook\FacebookApp; use Facebook\FacebookRequest; use Facebook\FacebookBatchRequest; use Facebook\FacebookClient; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; use Facebook\FileUpload\FacebookFile; use Facebook\FileUpload\FacebookVideo; // These are needed when you uncomment the HTTP clients below. use Facebook\HttpClients\FacebookCurlHttpClient; use Facebook\HttpClients\FacebookGuzzleHttpClient; use Facebook\HttpClients\FacebookStreamHttpClient; - -class MyFooClientHandler implements FacebookHttpClientInterface -{ - public function send($url, $method, $body, array $headers, $timeOut) - { - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", - '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' - ); - } -} - -class MyFooBatchClientHandler implements FacebookHttpClientInterface -{ - public function send($url, $method, $body, array $headers, $timeOut) - { - return new GraphRawResponse( - "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", - '[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]' - ); - } -} +use Facebook\Tests\Fixtures\MyFooBatchClientHandler; +use Facebook\Tests\Fixtures\MyFooClientHandler; class FacebookClientTest extends \PHPUnit_Framework_TestCase { @@ -82,7 +60,7 @@ class FacebookClientTest extends \PHPUnit_Framework_TestCase */ public static $testFacebookClient; - public function setUp() + protected function setUp() { $this->fbApp = new FacebookApp('id', 'shhhh!'); $this->fbClient = new FacebookClient(new MyFooClientHandler()); @@ -94,7 +72,7 @@ class FacebookClientTest extends \PHPUnit_Framework_TestCase $client = new FacebookClient($handler); $httpHandler = $client->getHttpClientHandler(); - $this->assertInstanceOf('Facebook\Tests\MyFooClientHandler', $httpHandler); + $this->assertInstanceOf('Facebook\Tests\Fixtures\MyFooClientHandler', $httpHandler); } public function testTheHttpClientWillFallbackToDefault() @@ -218,6 +196,14 @@ class FacebookClientTest extends \PHPUnit_Framework_TestCase $this->assertContains('multipart/form-data; boundary=', $headersSent['Content-Type']); } + public function testAFacebookRequestValidatesTheAccessTokenWhenOneIsNotProvided() + { + $this->setExpectedException('Facebook\Exceptions\FacebookSDKException'); + + $fbRequest = new FacebookRequest($this->fbApp, null, 'GET', '/foo'); + $this->fbClient->sendRequest($fbRequest); + } + /** * @group integration */ diff --git a/lib/facebook-graph-sdk/tests/FacebookRequestTest.php b/lib/facebook-graph-sdk/tests/FacebookRequestTest.php index fdea644..697fd94 100755 --- a/lib/facebook-graph-sdk/tests/FacebookRequestTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookRequestTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/FacebookResponseTest.php b/lib/facebook-graph-sdk/tests/FacebookResponseTest.php index 21f90ae..be37cbd 100755 --- a/lib/facebook-graph-sdk/tests/FacebookResponseTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookResponseTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -34,7 +34,7 @@ class FacebookResponseTest extends \PHPUnit_Framework_TestCase */ protected $request; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_secret'); $this->request = new FacebookRequest( diff --git a/lib/facebook-graph-sdk/tests/FacebookTest.php b/lib/facebook-graph-sdk/tests/FacebookTest.php index 3648665..035e8d7 100644 --- a/lib/facebook-graph-sdk/tests/FacebookTest.php +++ b/lib/facebook-graph-sdk/tests/FacebookTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -25,53 +25,14 @@ namespace Facebook\Tests; use Facebook\Facebook; use Facebook\FacebookClient; -use Facebook\Http\GraphRawResponse; -use Facebook\HttpClients\FacebookHttpClientInterface; -use Facebook\PersistentData\PersistentDataInterface; -use Facebook\Url\UrlDetectionInterface; -use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface; use Facebook\FacebookRequest; use Facebook\Authentication\AccessToken; use Facebook\GraphNodes\GraphEdge; - -class FooClientInterface implements FacebookHttpClientInterface -{ - public function send($url, $method, $body, array $headers, $timeOut) - { - return new GraphRawResponse( - "HTTP/1.1 1337 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", - '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' - ); - } -} - -class FooPersistentDataInterface implements PersistentDataInterface -{ - public function get($key) - { - return 'foo'; - } - - public function set($key, $value) - { - } -} - -class FooUrlDetectionInterface implements UrlDetectionInterface -{ - public function getCurrentUrl() - { - return 'https://foo.bar'; - } -} - -class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface -{ - public function getPseudoRandomString($length) - { - return 'csprs123'; - } -} +use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload; +use Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator; +use Facebook\Tests\Fixtures\FooClientInterface; +use Facebook\Tests\Fixtures\FooPersistentDataInterface; +use Facebook\Tests\Fixtures\FooUrlDetectionInterface; class FacebookTest extends \PHPUnit_Framework_TestCase { @@ -90,7 +51,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $config = [ 'app_secret' => 'foo_secret', ]; - $fb = new Facebook($config); + new Facebook($config); } /** @@ -103,7 +64,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $config = [ 'app_id' => 'foo_id', ]; - $fb = new Facebook($config); + new Facebook($config); } /** @@ -114,11 +75,14 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $config = array_merge($this->config, [ 'http_client_handler' => 'foo_handler', ]); - $fb = new Facebook($config); + new Facebook($config); } public function testCurlHttpClientHandlerCanBeForced() { + if (!extension_loaded('curl')) { + $this->markTestSkipped('cURL must be installed to test cURL client handler.'); + } $config = array_merge($this->config, [ 'http_client_handler' => 'curl' ]); @@ -161,7 +125,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $config = array_merge($this->config, [ 'persistent_data_handler' => 'foo_handler', ]); - $fb = new Facebook($config); + new Facebook($config); } public function testPersistentDataHandlerCanBeForced() @@ -176,15 +140,18 @@ class FacebookTest extends \PHPUnit_Framework_TestCase ); } - /** - * @expectedException \InvalidArgumentException - */ public function testSettingAnInvalidUrlHandlerThrows() { + $expectedException = (PHP_MAJOR_VERSION > 5 && class_exists('TypeError')) + ? 'TypeError' + : 'PHPUnit_Framework_Error'; + + $this->setExpectedException($expectedException); + $config = array_merge($this->config, [ 'url_detection_handler' => 'foo_handler', ]); - $fb = new Facebook($config); + new Facebook($config); } public function testTheUrlHandlerWillDefaultToTheFacebookImplementation() @@ -224,6 +191,25 @@ class FacebookTest extends \PHPUnit_Framework_TestCase new Facebook($config); } + public function testRandomBytesCsprgCanBeForced() + { + if (!function_exists('random_bytes')) { + $this->markTestSkipped( + 'Must have PHP 7 or paragonie/random_compat installed to test random_bytes().' + ); + } + + $config = array_merge($this->config, [ + 'persistent_data_handler' => 'memory', // To keep session errors from happening + 'pseudo_random_string_generator' => 'random_bytes' + ]); + $fb = new Facebook($config); + $this->assertInstanceOf( + 'Facebook\PseudoRandomString\RandomBytesPseudoRandomStringGenerator', + $fb->getRedirectLoginHelper()->getPseudoRandomStringGenerator() + ); + } + public function testMcryptCsprgCanBeForced() { if (!function_exists('mcrypt_create_iv')) { @@ -295,7 +281,7 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $config = array_merge($this->config, [ 'default_access_token' => 123, ]); - $fb = new Facebook($config); + new Facebook($config); } public function testCreatingANewRequestWillDefaultToTheProperConfig() @@ -318,6 +304,28 @@ class FacebookTest extends \PHPUnit_Framework_TestCase ); } + public function testCreatingANewBatchRequestWillDefaultToTheProperConfig() + { + $config = array_merge($this->config, [ + 'default_access_token' => 'foo_token', + 'enable_beta_mode' => true, + 'default_graph_version' => 'v1337', + ]); + $fb = new Facebook($config); + + $batchRequest = $fb->newBatchRequest(); + $this->assertEquals('1337', $batchRequest->getApp()->getId()); + $this->assertEquals('foo_secret', $batchRequest->getApp()->getSecret()); + $this->assertEquals('foo_token', (string)$batchRequest->getAccessToken()); + $this->assertEquals('v1337', $batchRequest->getGraphVersion()); + $this->assertEquals( + FacebookClient::BASE_GRAPH_URL_BETA, + $fb->getClient()->getBaseGraphUrl() + ); + $this->assertInstanceOf('Facebook\FacebookBatchRequest', $batchRequest); + $this->assertEquals(0, count($batchRequest->getRequests())); + } + public function testCanInjectCustomHandlers() { $config = array_merge($this->config, [ @@ -329,19 +337,19 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $fb = new Facebook($config); $this->assertInstanceOf( - 'Facebook\Tests\FooClientInterface', + 'Facebook\Tests\Fixtures\FooClientInterface', $fb->getClient()->getHttpClientHandler() ); $this->assertInstanceOf( - 'Facebook\Tests\FooPersistentDataInterface', + 'Facebook\Tests\Fixtures\FooPersistentDataInterface', $fb->getRedirectLoginHelper()->getPersistentDataHandler() ); $this->assertInstanceOf( - 'Facebook\Tests\FooUrlDetectionInterface', + 'Facebook\Tests\Fixtures\FooUrlDetectionInterface', $fb->getRedirectLoginHelper()->getUrlDetectionHandler() ); $this->assertInstanceOf( - 'Facebook\Tests\FooBarPseudoRandomStringGenerator', + 'Facebook\Tests\Fixtures\FooBarPseudoRandomStringGenerator', $fb->getRedirectLoginHelper()->getPseudoRandomStringGenerator() ); } @@ -363,6 +371,8 @@ class FacebookTest extends \PHPUnit_Framework_TestCase 'after' => 'bar_after_cursor', 'before' => 'bar_before_cursor', ], + 'previous' => 'previous_url', + 'next' => 'next_url', ] ], '/1337/photos', @@ -378,4 +388,32 @@ class FacebookTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Facebook\FacebookResponse', $lastResponse); $this->assertEquals(1337, $lastResponse->getHttpStatusCode()); } + + public function testCanGetSuccessfulTransferWithMaxTries() + { + $config = array_merge($this->config, [ + 'http_client_handler' => new FakeGraphApiForResumableUpload(), + ]); + $fb = new Facebook($config); + $response = $fb->uploadVideo('me', __DIR__.'/foo.txt', [], 'foo-token', 3); + $this->assertEquals([ + 'video_id' => '1337', + 'success' => true, + ], $response); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookResponseException + */ + public function testMaxingOutRetriesWillThrow() + { + $client = new FakeGraphApiForResumableUpload(); + $client->failOnTransfer(); + + $config = array_merge($this->config, [ + 'http_client_handler' => $client, + ]); + $fb = new Facebook($config); + $fb->uploadVideo('4', __DIR__.'/foo.txt', [], 'foo-token', 3); + } } diff --git a/lib/facebook-graph-sdk/tests/FacebookTestCredentials.php.dist b/lib/facebook-graph-sdk/tests/FacebookTestCredentials.php.dist index e5b66f7..4d2878a 100644 --- a/lib/facebook-graph-sdk/tests/FacebookTestCredentials.php.dist +++ b/lib/facebook-graph-sdk/tests/FacebookTestCredentials.php.dist @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/FileUpload/FacebookFileTest.php b/lib/facebook-graph-sdk/tests/FileUpload/FacebookFileTest.php index 1eb5c0b..8ef7417 100644 --- a/lib/facebook-graph-sdk/tests/FileUpload/FacebookFileTest.php +++ b/lib/facebook-graph-sdk/tests/FileUpload/FacebookFileTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -27,10 +27,9 @@ use Facebook\FileUpload\FacebookFile; class FacebookFileTest extends \PHPUnit_Framework_TestCase { - protected $testFile = ''; - public function setUp() + protected function setUp() { $this->testFile = __DIR__ . '/../foo.txt'; } @@ -43,6 +42,14 @@ class FacebookFileTest extends \PHPUnit_Framework_TestCase $this->assertEquals('This is a text file used for testing. Let\'s dance.', $fileContents); } + public function testPartialFilesCanBeCreated() + { + $file = new FacebookFile($this->testFile, 14, 5); + $fileContents = $file->getContents(); + + $this->assertEquals('is a text file', $fileContents); + } + /** * @expectedException \Facebook\Exceptions\FacebookSDKException */ diff --git a/lib/facebook-graph-sdk/tests/FileUpload/FacebookResumableUploaderTest.php b/lib/facebook-graph-sdk/tests/FileUpload/FacebookResumableUploaderTest.php new file mode 100644 index 0000000..c32b7fb --- /dev/null +++ b/lib/facebook-graph-sdk/tests/FileUpload/FacebookResumableUploaderTest.php @@ -0,0 +1,101 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +namespace Facebook\Tests\FileUpload; + +use Facebook\FileUpload\FacebookFile; +use Facebook\FacebookApp; +use Facebook\FacebookClient; +use Facebook\FileUpload\FacebookResumableUploader; +use Facebook\FileUpload\FacebookTransferChunk; +use Facebook\Tests\Fixtures\FakeGraphApiForResumableUpload; + +class FacebookResumableUploaderTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var FacebookApp + */ + private $fbApp; + + /** + * @var FacebookClient + */ + private $client; + + /** + * @var FakeGraphApiForResumableUpload + */ + private $graphApi; + + /** + * @var FacebookFile + */ + private $file; + + protected function setUp() + { + $this->fbApp = new FacebookApp('app_id', 'app_secret'); + $this->graphApi = new FakeGraphApiForResumableUpload(); + $this->client = new FacebookClient($this->graphApi); + $this->file = new FacebookFile(__DIR__.'/../foo.txt'); + } + + public function testResumableUploadCanStartTransferAndFinish() + { + $uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4'); + $endpoint = '/me/videos'; + $chunk = $uploader->start($endpoint, $this->file); + $this->assertInstanceOf('Facebook\FileUpload\FacebookTransferChunk', $chunk); + $this->assertEquals('42', $chunk->getUploadSessionId()); + $this->assertEquals('1337', $chunk->getVideoId()); + + $newChunk = $uploader->transfer($endpoint, $chunk); + $this->assertEquals(20, $newChunk->getStartOffset()); + $this->assertNotSame($newChunk, $chunk); + + $finalResponse = $uploader->finish($endpoint, $chunk->getUploadSessionId(), []); + $this->assertTrue($finalResponse); + } + + /** + * @expectedException \Facebook\Exceptions\FacebookResponseException + */ + public function testStartWillLetErrorResponsesThrow() + { + $this->graphApi->failOnStart(); + $uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4'); + + $uploader->start('/me/videos', $this->file); + } + + public function testFailedResumableTransferWillNotThrowAndReturnSameChunk() + { + $this->graphApi->failOnTransfer(); + $uploader = new FacebookResumableUploader($this->fbApp, $this->client, 'access_token', 'v2.4'); + + $chunk = new FacebookTransferChunk($this->file, '1', '2', '3', '4'); + $newChunk = $uploader->transfer('/me/videos', $chunk); + $this->assertSame($newChunk, $chunk); + } +} diff --git a/lib/facebook-graph-sdk/tests/FileUpload/MimetypesTest.php b/lib/facebook-graph-sdk/tests/FileUpload/MimetypesTest.php index c2092c1..14fc2b9 100644 --- a/lib/facebook-graph-sdk/tests/FileUpload/MimetypesTest.php +++ b/lib/facebook-graph-sdk/tests/FileUpload/MimetypesTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FakeGraphApiForResumableUpload.php b/lib/facebook-graph-sdk/tests/Fixtures/FakeGraphApiForResumableUpload.php new file mode 100644 index 0000000..1c2d0f8 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FakeGraphApiForResumableUpload.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ + +namespace Facebook\Tests\Fixtures; + +use Facebook\Http\GraphRawResponse; +use Facebook\HttpClients\FacebookHttpClientInterface; + +class FakeGraphApiForResumableUpload implements FacebookHttpClientInterface +{ + public $transferCount = 0; + private $respondWith = 'SUCCESS'; + + public function failOnStart() + { + $this->respondWith = 'FAIL_ON_START'; + } + + public function failOnTransfer() + { + $this->respondWith = 'FAIL_ON_TRANSFER'; + } + + public function send($url, $method, $body, array $headers, $timeOut) + { + // Could be start, transfer or finish + if (strpos($body, 'transfer') !== false) { + return $this->respondTransfer(); + } elseif (strpos($body, 'finish') !== false) { + return $this->respondFinish(); + } + + return $this->respondStart(); + } + + private function respondStart() + { + if ($this->respondWith == 'FAIL_ON_START') { + return new GraphRawResponse( + "HTTP/1.1 500 OK\r\nFoo: Bar", + '{"error":{"message":"Error validating access token: Session has expired on Monday, ' . + '10-Aug-15 01:00:00 PDT. The current time is Monday, 10-Aug-15 01:14:23 PDT.",' . + '"type":"OAuthException","code":190,"error_subcode":463}}' + ); + } + + return new GraphRawResponse( + "HTTP/1.1 200 OK\r\nFoo: Bar", + '{"video_id":"1337","start_offset":"0","end_offset":"20","upload_session_id":"42"}' + ); + } + + private function respondTransfer() + { + if ($this->respondWith == 'FAIL_ON_TRANSFER') { + return new GraphRawResponse( + "HTTP/1.1 500 OK\r\nFoo: Bar", + '{"error":{"message":"There was a problem uploading your video. Please try uploading it again.",' . + '"type":"FacebookApiException","code":6000,"error_subcode":1363019}}' + ); + } + + switch ($this->transferCount) { + case 0: + $data = ['start_offset' => 20, 'end_offset' => 40]; + break; + case 1: + $data = ['start_offset' => 40, 'end_offset' => 50]; + break; + default: + $data = ['start_offset' => 50, 'end_offset' => 50]; + break; + } + + $this->transferCount++; + + return new GraphRawResponse( + "HTTP/1.1 200 OK\r\nFoo: Bar", + json_encode($data) + ); + } + + private function respondFinish() + { + return new GraphRawResponse( + "HTTP/1.1 200 OK\r\nFoo: Bar", + '{"success":true}' + ); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooBarPseudoRandomStringGenerator.php b/lib/facebook-graph-sdk/tests/Fixtures/FooBarPseudoRandomStringGenerator.php new file mode 100644 index 0000000..17448b6 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooBarPseudoRandomStringGenerator.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface; + +class FooBarPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface +{ + public function getPseudoRandomString($length) + { + return 'csprs123'; + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooClientInterface.php b/lib/facebook-graph-sdk/tests/Fixtures/FooClientInterface.php new file mode 100644 index 0000000..f4548d8 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooClientInterface.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Http\GraphRawResponse; +use Facebook\HttpClients\FacebookHttpClientInterface; + +class FooClientInterface implements FacebookHttpClientInterface +{ + public function send($url, $method, $body, array $headers, $timeOut) + { + return new GraphRawResponse( + "HTTP/1.1 1337 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", + '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' + ); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooPersistentDataInterface.php b/lib/facebook-graph-sdk/tests/Fixtures/FooPersistentDataInterface.php new file mode 100644 index 0000000..5ff5793 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooPersistentDataInterface.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\PersistentData\PersistentDataInterface; + +class FooPersistentDataInterface implements PersistentDataInterface +{ + public function get($key) + { + return 'foo'; + } + + public function set($key, $value) + { + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooPseudoRandomStringGenerator.php b/lib/facebook-graph-sdk/tests/Fixtures/FooPseudoRandomStringGenerator.php new file mode 100644 index 0000000..d5a94d6 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooPseudoRandomStringGenerator.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface; + +class FooPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface +{ + public function getPseudoRandomString($length) + { + return 'csprs123'; + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooRedirectLoginOAuth2Client.php b/lib/facebook-graph-sdk/tests/Fixtures/FooRedirectLoginOAuth2Client.php new file mode 100644 index 0000000..2a2aeed --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooRedirectLoginOAuth2Client.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Authentication\AccessToken; +use Facebook\Authentication\OAuth2Client; + +class FooRedirectLoginOAuth2Client extends OAuth2Client +{ + public function getAccessTokenFromCode($code, $redirectUri = '', $machineId = null) + { + return new AccessToken('foo_token_from_code|' . $code . '|' . $redirectUri); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelper.php b/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelper.php new file mode 100644 index 0000000..9131631 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelper.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Helpers\FacebookSignedRequestFromInputHelper; + +class FooSignedRequestHelper extends FacebookSignedRequestFromInputHelper +{ + public function getRawSignedRequest() + { + return null; + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelperFacebookClient.php b/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelperFacebookClient.php new file mode 100644 index 0000000..0b08b8c --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooSignedRequestHelperFacebookClient.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\FacebookClient; +use Facebook\FacebookRequest; +use Facebook\FacebookResponse; + +class FooSignedRequestHelperFacebookClient extends FacebookClient +{ + public function sendRequest(FacebookRequest $request) + { + $params = $request->getParams(); + $rawResponse = json_encode([ + 'access_token' => 'foo_access_token_from:' . $params['code'], + ]); + + return new FacebookResponse($request, $rawResponse, 200); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/FooUrlDetectionInterface.php b/lib/facebook-graph-sdk/tests/Fixtures/FooUrlDetectionInterface.php new file mode 100644 index 0000000..8ee70c3 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/FooUrlDetectionInterface.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Url\UrlDetectionInterface; + +class FooUrlDetectionInterface implements UrlDetectionInterface +{ + public function getCurrentUrl() + { + return 'https://foo.bar'; + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/MyFooBarPseudoRandomStringGenerator.php b/lib/facebook-graph-sdk/tests/Fixtures/MyFooBarPseudoRandomStringGenerator.php new file mode 100644 index 0000000..8c39c8a --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/MyFooBarPseudoRandomStringGenerator.php @@ -0,0 +1,31 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\PseudoRandomString\PseudoRandomStringGeneratorTrait; + +class MyFooBarPseudoRandomStringGenerator +{ + use PseudoRandomStringGeneratorTrait; +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/MyFooBatchClientHandler.php b/lib/facebook-graph-sdk/tests/Fixtures/MyFooBatchClientHandler.php new file mode 100644 index 0000000..4a4c9cb --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/MyFooBatchClientHandler.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Http\GraphRawResponse; +use Facebook\HttpClients\FacebookHttpClientInterface; + +class MyFooBatchClientHandler implements FacebookHttpClientInterface +{ + public function send($url, $method, $body, array $headers, $timeOut) + { + return new GraphRawResponse( + "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", + '[{"code":"123","body":"Foo"},{"code":"1337","body":"Bar"}]' + ); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/MyFooClientHandler.php b/lib/facebook-graph-sdk/tests/Fixtures/MyFooClientHandler.php new file mode 100644 index 0000000..346da9e --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/MyFooClientHandler.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\Http\GraphRawResponse; +use Facebook\HttpClients\FacebookHttpClientInterface; + +class MyFooClientHandler implements FacebookHttpClientInterface +{ + public function send($url, $method, $body, array $headers, $timeOut) + { + return new GraphRawResponse( + "HTTP/1.1 200 OK\r\nDate: Mon, 19 May 2014 18:37:17 GMT", + '{"data":[{"id":"123","name":"Foo"},{"id":"1337","name":"Bar"}]}' + ); + } +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/MyFooGraphNode.php b/lib/facebook-graph-sdk/tests/Fixtures/MyFooGraphNode.php new file mode 100644 index 0000000..40d3a91 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/MyFooGraphNode.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\GraphNodes\GraphNode; + +class MyFooGraphNode extends GraphNode +{ + protected static $graphObjectMap = [ + 'foo_object' => '\Facebook\Tests\Fixtures\MyFooSubClassGraphNode', + ]; +} diff --git a/lib/facebook-graph-sdk/tests/Fixtures/MyFooSubClassGraphNode.php b/lib/facebook-graph-sdk/tests/Fixtures/MyFooSubClassGraphNode.php new file mode 100644 index 0000000..d03b308 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/Fixtures/MyFooSubClassGraphNode.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\Fixtures; + +use Facebook\GraphNodes\GraphNode; + +class MyFooSubClassGraphNode extends GraphNode +{ +} diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php b/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php index 1c4ce15..b4f0e90 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/AbstractGraphNode.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -33,7 +33,7 @@ abstract class AbstractGraphNode extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { parent::setUp(); $this->responseMock = m::mock('\Facebook\FacebookResponse'); diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php index af3eba8..14af476 100755 --- a/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/CollectionTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -60,6 +60,20 @@ class CollectionTest extends \PHPUnit_Framework_TestCase $this->assertEquals('faz', $property); } + public function testFalseDefaultsWillReturnSameType() + { + $graphNode = new Collection(['foo' => 'bar']); + + $field = $graphNode->getField('baz', ''); + $this->assertSame('', $field); + + $field = $graphNode->getField('baz', 0); + $this->assertSame(0, $field); + + $field = $graphNode->getField('baz', false); + $this->assertSame(false, $field); + } + public function testTheKeysFromTheCollectionCanBeReturned() { $graphNode = new Collection([ diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php index d5e276e..5be1140 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAchievementTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php index f7a5521..0c4eab5 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphAlbumTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -34,7 +34,7 @@ class GraphAlbumTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\\Facebook\\FacebookResponse'); } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php index 4e70f52..3afaf9c 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEdgeTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -26,6 +26,7 @@ namespace Facebook\Tests\GraphNodes; use Facebook\FacebookApp; use Facebook\FacebookRequest; use Facebook\GraphNodes\GraphEdge; +use Facebook\GraphNodes\GraphNode; class GraphEdgeTest extends \PHPUnit_Framework_TestCase { @@ -35,18 +36,12 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase */ protected $request; - protected $basePagination = [ + protected $pagination = [ 'next' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&after=foo_after_cursor', 'previous' => 'https://graph.facebook.com/v7.12/998899/photos?pretty=0&limit=25&before=foo_before_cursor', ]; - protected $cursorPagination = [ - 'cursors' => [ - 'after' => 'bar_after_cursor', - 'before' => 'bar_before_cursor', - ], - ]; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_app_secret'); $this->request = new FacebookRequest( @@ -75,7 +70,7 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase $graphEdge = new GraphEdge( $this->request, [], - ['paging' => $this->basePagination] + ['paging' => $this->pagination] ); $nextPage = $graphEdge->getPaginationUrl('next'); $prevPage = $graphEdge->getPaginationUrl('previous'); @@ -84,37 +79,52 @@ class GraphEdgeTest extends \PHPUnit_Framework_TestCase $this->assertEquals('/998899/photos?pretty=0&limit=25&before=foo_before_cursor', $prevPage); } - public function testCanGeneratePaginationEndpointsFromACursor() + public function testCanInstantiateNewPaginationRequest() { $graphEdge = new GraphEdge( $this->request, [], - ['paging' => $this->cursorPagination], + ['paging' => $this->pagination], '/1234567890/likes' ); - $nextPage = $graphEdge->getPaginationUrl('next'); - $prevPage = $graphEdge->getPaginationUrl('previous'); + $nextPage = $graphEdge->getNextPageRequest(); + $prevPage = $graphEdge->getPreviousPageRequest(); - $this->assertEquals('/1234567890/likes?access_token=foo_token&after=bar_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&keep=me', $nextPage); - $this->assertEquals('/1234567890/likes?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=bar_before_cursor&foo=bar&keep=me', $prevPage); + $this->assertInstanceOf('Facebook\FacebookRequest', $nextPage); + $this->assertInstanceOf('Facebook\FacebookRequest', $prevPage); + $this->assertNotSame($this->request, $nextPage); + $this->assertNotSame($this->request, $prevPage); + $this->assertEquals('/v1337/998899/photos?access_token=foo_token&after=foo_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&limit=25&pretty=0', $nextPage->getUrl()); + $this->assertEquals('/v1337/998899/photos?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=foo_before_cursor&foo=bar&limit=25&pretty=0', $prevPage->getUrl()); } - public function testCanInstantiateNewPaginationRequest() + public function testCanMapOverNodes() { $graphEdge = new GraphEdge( $this->request, - [], - ['paging' => $this->cursorPagination], + [ + new GraphNode(['name' => 'dummy']), + new GraphNode(['name' => 'dummy']), + ], + ['paging' => $this->pagination], '/1234567890/likes' ); - $nextPage = $graphEdge->getNextPageRequest(); - $prevPage = $graphEdge->getPreviousPageRequest(); - $this->assertInstanceOf('Facebook\FacebookRequest', $nextPage); - $this->assertInstanceOf('Facebook\FacebookRequest', $prevPage); - $this->assertNotSame($this->request, $nextPage); - $this->assertNotSame($this->request, $prevPage); - $this->assertEquals('/v1337/1234567890/likes?access_token=foo_token&after=bar_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&keep=me', $nextPage->getUrl()); - $this->assertEquals('/v1337/1234567890/likes?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=bar_before_cursor&foo=bar&keep=me', $prevPage->getUrl()); + $graphEdge = $graphEdge->map(function (GraphNode $node) { + $node['name'] = str_replace('dummy', 'foo', $node['name']); + return $node; + }); + + $graphEdgeToCompare = new GraphEdge( + $this->request, + [ + new GraphNode(['name' => 'foo']), + new GraphNode(['name' => 'foo']) + ], + ['paging' => $this->pagination], + '/1234567890/likes' + ); + + $this->assertEquals($graphEdgeToCompare, $graphEdge); } } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php index 98ccd85..7c6f127 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphEventTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -34,7 +34,7 @@ class GraphEventTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\Facebook\FacebookResponse'); } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php index 21893b5..c62d50f 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphGroupTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -34,7 +34,7 @@ class GraphGroupTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\Facebook\FacebookResponse'); } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php index 7d2f023..a4aa5e1 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeFactoryTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -27,18 +27,6 @@ use Facebook\FacebookApp; use Facebook\FacebookRequest; use Facebook\FacebookResponse; use Facebook\GraphNodes\GraphNodeFactory; -use Facebook\GraphNodes\GraphNode; - -class MyFooSubClassGraphNode extends GraphNode -{ -} - -class MyFooGraphNode extends GraphNode -{ - protected static $graphObjectMap = [ - 'foo_object' => '\Facebook\Tests\GraphNodes\MyFooSubClassGraphNode', - ]; -} class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase { @@ -47,7 +35,7 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase */ protected $request; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_app_secret'); $this->request = new FacebookRequest( @@ -126,7 +114,7 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase { GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphNode'); GraphNodeFactory::validateSubclass('\Facebook\GraphNodes\GraphAlbum'); - GraphNodeFactory::validateSubclass('\Facebook\Tests\GraphNodes\MyFooGraphNode'); + GraphNodeFactory::validateSubclass('\Facebook\Tests\Fixtures\MyFooGraphNode'); } public function testCastingAsASubClassObjectWillInstantiateTheSubClass() @@ -135,9 +123,9 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase $res = new FacebookResponse($this->request, $data); $factory = new GraphNodeFactory($res); - $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode'); + $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); - $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject); + $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); } public function testASubClassMappingWillAutomaticallyInstantiateSubClass() @@ -146,11 +134,11 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase $res = new FacebookResponse($this->request, $data); $factory = new GraphNodeFactory($res); - $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode'); + $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); $fooObject = $mySubClassObject->getField('foo_object'); - $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject); - $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooSubClassGraphNode', $fooObject); + $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); + $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooSubClassGraphNode', $fooObject); } public function testAnUnknownGraphNodeWillBeCastAsAGenericGraphNode() @@ -167,12 +155,12 @@ class GraphNodeFactoryTest extends \PHPUnit_Framework_TestCase $factory = new GraphNodeFactory($res); - $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\GraphNodes\MyFooGraphNode'); + $mySubClassObject = $factory->makeGraphNode('\Facebook\Tests\Fixtures\MyFooGraphNode'); $unknownObject = $mySubClassObject->getField('unknown_object'); - $this->assertInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $mySubClassObject); + $this->assertInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $mySubClassObject); $this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $unknownObject); - $this->assertNotInstanceOf('\Facebook\Tests\GraphNodes\MyFooGraphNode', $unknownObject); + $this->assertNotInstanceOf('\Facebook\Tests\Fixtures\MyFooGraphNode', $unknownObject); } public function testAListFromGraphWillBeCastAsAGraphEdge() diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php index 50f58ae..67444fa 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphNodeTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php index 764503a..3ef1d0b 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphObjectFactoryTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -38,7 +38,7 @@ class GraphObjectFactoryTest extends \PHPUnit_Framework_TestCase */ protected $request; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_app_secret'); $this->request = new FacebookRequest( diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php index a3a88e9..c7ce163 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphPageTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -33,7 +33,7 @@ class GraphPageTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\\Facebook\\FacebookResponse'); } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php index 2960c28..b2e56fa 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphSessionInfoTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -33,7 +33,7 @@ class GraphSessionInfoTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\\Facebook\\FacebookResponse'); } diff --git a/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php b/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php index ca75573..a3230fa 100644 --- a/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php +++ b/lib/facebook-graph-sdk/tests/GraphNodes/GraphUserTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -34,7 +34,7 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase */ protected $responseMock; - public function setUp() + protected function setUp() { $this->responseMock = m::mock('\\Facebook\\FacebookResponse'); } @@ -42,7 +42,25 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase public function testDatesGetCastToDateTime() { $dataFromGraph = [ - 'birthday' => '1984-01-01', + 'updated_time' => '2016-04-26 13:22:05', + ]; + + $this->responseMock + ->shouldReceive('getDecodedBody') + ->once() + ->andReturn($dataFromGraph); + $factory = new GraphNodeFactory($this->responseMock); + $graphNode = $factory->makeGraphUser(); + + $updatedTime = $graphNode->getField('updated_time'); + + $this->assertInstanceOf('DateTime', $updatedTime); + } + + public function testBirthdaysGetCastToBirthday() + { + $dataFromGraph = [ + 'birthday' => '1984/01/01', ]; $this->responseMock @@ -54,7 +72,53 @@ class GraphUserTest extends \PHPUnit_Framework_TestCase $birthday = $graphNode->getBirthday(); + // Test to ensure BC $this->assertInstanceOf('DateTime', $birthday); + + $this->assertInstanceOf('\\Facebook\\GraphNodes\\Birthday', $birthday); + $this->assertTrue($birthday->hasDate()); + $this->assertTrue($birthday->hasYear()); + $this->assertEquals('1984/01/01', $birthday->format('Y/m/d')); + } + + public function testBirthdayCastHandlesDateWithoutYear() + { + $dataFromGraph = [ + 'birthday' => '03/21', + ]; + + $this->responseMock + ->shouldReceive('getDecodedBody') + ->once() + ->andReturn($dataFromGraph); + $factory = new GraphNodeFactory($this->responseMock); + $graphNode = $factory->makeGraphUser(); + + $birthday = $graphNode->getBirthday(); + + $this->assertTrue($birthday->hasDate()); + $this->assertFalse($birthday->hasYear()); + $this->assertEquals('03/21', $birthday->format('m/d')); + } + + public function testBirthdayCastHandlesYearWithoutDate() + { + $dataFromGraph = [ + 'birthday' => '1984', + ]; + + $this->responseMock + ->shouldReceive('getDecodedBody') + ->once() + ->andReturn($dataFromGraph); + $factory = new GraphNodeFactory($this->responseMock); + $graphNode = $factory->makeGraphUser(); + + $birthday = $graphNode->getBirthday(); + + $this->assertTrue($birthday->hasYear()); + $this->assertFalse($birthday->hasDate()); + $this->assertEquals('1984', $birthday->format('Y')); } public function testPagePropertiesWillGetCastAsGraphPageObjects() diff --git a/lib/facebook-graph-sdk/tests/Helpers/FacebookCanvasHelperTest.php b/lib/facebook-graph-sdk/tests/Helpers/FacebookCanvasHelperTest.php index 294440e..f03d66f 100644 --- a/lib/facebook-graph-sdk/tests/Helpers/FacebookCanvasHelperTest.php +++ b/lib/facebook-graph-sdk/tests/Helpers/FacebookCanvasHelperTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -36,7 +36,7 @@ class FacebookCanvasHelperTest extends \PHPUnit_Framework_TestCase */ protected $helper; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_app_secret'); $this->helper = new FacebookCanvasHelper($app, new FacebookClient()); diff --git a/lib/facebook-graph-sdk/tests/Helpers/FacebookJavaScriptHelperTest.php b/lib/facebook-graph-sdk/tests/Helpers/FacebookJavaScriptHelperTest.php index 3f9cb88..5218758 100644 --- a/lib/facebook-graph-sdk/tests/Helpers/FacebookJavaScriptHelperTest.php +++ b/lib/facebook-graph-sdk/tests/Helpers/FacebookJavaScriptHelperTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Helpers/FacebookPageTabHelperTest.php b/lib/facebook-graph-sdk/tests/Helpers/FacebookPageTabHelperTest.php index a4b06c1..5c27f48 100644 --- a/lib/facebook-graph-sdk/tests/Helpers/FacebookPageTabHelperTest.php +++ b/lib/facebook-graph-sdk/tests/Helpers/FacebookPageTabHelperTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Helpers/FacebookRedirectLoginHelperTest.php b/lib/facebook-graph-sdk/tests/Helpers/FacebookRedirectLoginHelperTest.php index faa4647..5df9afa 100644 --- a/lib/facebook-graph-sdk/tests/Helpers/FacebookRedirectLoginHelperTest.php +++ b/lib/facebook-graph-sdk/tests/Helpers/FacebookRedirectLoginHelperTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -26,26 +26,10 @@ namespace Facebook\Tests\Helpers; use Facebook\Facebook; use Facebook\FacebookApp; use Facebook\FacebookClient; -use Facebook\Authentication\OAuth2Client; use Facebook\Helpers\FacebookRedirectLoginHelper; use Facebook\PersistentData\FacebookMemoryPersistentDataHandler; -use Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface; - -class FooPseudoRandomStringGenerator implements PseudoRandomStringGeneratorInterface -{ - public function getPseudoRandomString($length) - { - return 'csprs123'; - } -} - -class FooRedirectLoginOAuth2Client extends OAuth2Client -{ - public function getAccessTokenFromCode($code, $redirectUri = '', $machineId = null) - { - return 'foo_token_from_code|' . $code . '|' . $redirectUri; - } -} +use Facebook\Tests\Fixtures\FooPseudoRandomStringGenerator; +use Facebook\Tests\Fixtures\FooRedirectLoginOAuth2Client; class FacebookRedirectLoginHelperTest extends \PHPUnit_Framework_TestCase { @@ -60,8 +44,11 @@ class FacebookRedirectLoginHelperTest extends \PHPUnit_Framework_TestCase protected $redirectLoginHelper; const REDIRECT_URL = 'http://invalid.zzz'; + const FOO_CODE = "foo_code"; + const FOO_STATE = "foo_state"; + const FOO_PARAM = "some_param=blah"; - public function setUp() + protected function setUp() { $this->persistentDataHandler = new FacebookMemoryPersistentDataHandler(); @@ -110,12 +97,18 @@ class FacebookRedirectLoginHelperTest extends \PHPUnit_Framework_TestCase public function testAnAccessTokenCanBeObtainedFromRedirect() { $this->persistentDataHandler->set('state', 'foo_state'); - $_GET['state'] = 'foo_state'; - $_GET['code'] = 'foo_code'; + $_GET['state'] = static::FOO_STATE; + $_GET['code'] = static::FOO_CODE; + + $fullUrl = self::REDIRECT_URL . '?state=' . static::FOO_STATE . '&code=' . static::FOO_CODE . '&' . static::FOO_PARAM; + + $accessToken = $this->redirectLoginHelper->getAccessToken($fullUrl); - $accessToken = $this->redirectLoginHelper->getAccessToken(self::REDIRECT_URL); + // code and state should be stripped from the URL + $expectedUrl = self::REDIRECT_URL . '?' . static::FOO_PARAM; + $expectedString = 'foo_token_from_code|' . static::FOO_CODE . '|' . $expectedUrl; - $this->assertEquals('foo_token_from_code|foo_code|' . self::REDIRECT_URL, (string)$accessToken); + $this->assertEquals($expectedString, $accessToken->getValue()); } public function testACustomCsprsgCanBeInjected() diff --git a/lib/facebook-graph-sdk/tests/Helpers/FacebookSignedRequestFromInputHelperTest.php b/lib/facebook-graph-sdk/tests/Helpers/FacebookSignedRequestFromInputHelperTest.php index d9bd803..ffaa5e3 100644 --- a/lib/facebook-graph-sdk/tests/Helpers/FacebookSignedRequestFromInputHelperTest.php +++ b/lib/facebook-graph-sdk/tests/Helpers/FacebookSignedRequestFromInputHelperTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -24,31 +24,8 @@ namespace Facebook\Tests\Helpers; use Facebook\FacebookApp; -use Facebook\FacebookClient; -use Facebook\FacebookRequest; -use Facebook\FacebookResponse; -use Facebook\Helpers\FacebookSignedRequestFromInputHelper; - -class FooSignedRequestHelper extends FacebookSignedRequestFromInputHelper -{ - public function getRawSignedRequest() - { - return null; - } -} - -class FooSignedRequestHelperFacebookClient extends FacebookClient -{ - public function sendRequest(FacebookRequest $request) - { - $params = $request->getParams(); - $rawResponse = json_encode([ - 'access_token' => 'foo_access_token_from:' . $params['code'], - ]); - - return new FacebookResponse($request, $rawResponse, 200); - } -} +use Facebook\Tests\Fixtures\FooSignedRequestHelper; +use Facebook\Tests\Fixtures\FooSignedRequestHelperFacebookClient; class FacebookSignedRequestFromInputHelperTest extends \PHPUnit_Framework_TestCase { @@ -61,7 +38,7 @@ class FacebookSignedRequestFromInputHelperTest extends \PHPUnit_Framework_TestCa public $rawSignedRequestAuthorizedWithCode = 'oBtmZlsFguNQvGRETDYQQu1-PhwcArgbBBEK4urbpRA=.eyJjb2RlIjoiZm9vX2NvZGUiLCJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTQwNjMxMDc1MiwidXNlcl9pZCI6IjEyMyJ9'; public $rawSignedRequestUnauthorized = 'KPlyhz-whtYAhHWr15N5TkbS_avz-2rUJFpFkfXKC88=.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTQwMjU1MTA4Nn0='; - public function setUp() + protected function setUp() { $app = new FacebookApp('123', 'foo_app_secret'); $this->helper = new FooSignedRequestHelper($app, new FooSignedRequestHelperFacebookClient()); diff --git a/lib/facebook-graph-sdk/tests/Http/GraphRawResponseTest.php b/lib/facebook-graph-sdk/tests/Http/GraphRawResponseTest.php index ecad26f..3b18b56 100644 --- a/lib/facebook-graph-sdk/tests/Http/GraphRawResponseTest.php +++ b/lib/facebook-graph-sdk/tests/Http/GraphRawResponseTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -48,6 +48,9 @@ HEADER; 'Access-Control-Allow-Origin' => '*', ]; + protected $jsonFakeHeader = 'x-fb-ads-insights-throttle: {"app_id_util_pct": 0.00,"acc_id_util_pct": 0.00}'; + protected $jsonFakeHeaderAsArray = ['x-fb-ads-insights-throttle' => '{"app_id_util_pct": 0.00,"acc_id_util_pct": 0.00}']; + public function testCanSetTheHeadersFromAnArray() { $myHeaders = [ @@ -79,4 +82,12 @@ HEADER; $this->assertEquals($this->fakeHeadersAsArray, $headers); $this->assertEquals(200, $httpResponseCode); } + + public function testCanTransformJsonHeaderValues() + { + $response = new GraphRawResponse($this->jsonFakeHeader, ''); + $headers = $response->getHeaders(); + + $this->assertEquals($this->jsonFakeHeaderAsArray['x-fb-ads-insights-throttle'], $headers['x-fb-ads-insights-throttle']); + } } diff --git a/lib/facebook-graph-sdk/tests/Http/RequestBodyMultipartTest.php b/lib/facebook-graph-sdk/tests/Http/RequestBodyMultipartTest.php index 267cc49..1a23c46 100644 --- a/lib/facebook-graph-sdk/tests/Http/RequestBodyMultipartTest.php +++ b/lib/facebook-graph-sdk/tests/Http/RequestBodyMultipartTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Http/RequestUrlEncodedTest.php b/lib/facebook-graph-sdk/tests/Http/RequestUrlEncodedTest.php index 3e22912..2b4f67f 100644 --- a/lib/facebook-graph-sdk/tests/Http/RequestUrlEncodedTest.php +++ b/lib/facebook-graph-sdk/tests/Http/RequestUrlEncodedTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php b/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php index 269b235..a870052 100644 --- a/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php +++ b/lib/facebook-graph-sdk/tests/HttpClients/AbstractTestHttpClient.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php index 4cf31d3..47cc027 100644 --- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php +++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookCurlHttpClientTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -41,8 +41,11 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient const CURL_VERSION_STABLE = 0x072400; const CURL_VERSION_BUGGY = 0x071400; - public function setUp() + protected function setUp() { + if (!extension_loaded('curl')) { + $this->markTestSkipped('cURL must be installed to test cURL client handler.'); + } $this->curlMock = m::mock('Facebook\HttpClients\FacebookCurl'); $this->curlClient = new FacebookCurlHttpClient($this->curlMock); } @@ -147,15 +150,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient public function testIsolatesTheHeaderAndBody() { $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(strlen($this->fakeRawHeader)); - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_STABLE]); - $this->curlMock ->shouldReceive('exec') ->once() ->andReturn($this->fakeRawHeader . $this->fakeRawBody); @@ -171,15 +165,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient { $rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader; $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(mb_strlen($rawHeader)); - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_STABLE]); - $this->curlMock ->shouldReceive('exec') ->once() ->andReturn($rawHeader . $this->fakeRawBody); @@ -195,15 +180,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient { $rawHeader = $this->fakeRawProxyHeader . $this->fakeRawHeader; $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_BUGGY]); - $this->curlMock ->shouldReceive('exec') ->once() ->andReturn($rawHeader . $this->fakeRawBody); @@ -219,15 +195,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient { $rawHeader = $this->fakeRawProxyHeader2 . $this->fakeRawHeader; $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(mb_strlen($this->fakeRawHeader)); // Mimic bug that doesn't count proxy header - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_BUGGY]); - $this->curlMock ->shouldReceive('exec') ->once() ->andReturn($rawHeader . $this->fakeRawBody); @@ -243,15 +210,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient { $rawHeader = $this->fakeRawRedirectHeader . $this->fakeRawHeader; $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(mb_strlen($rawHeader)); - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_STABLE]); - $this->curlMock ->shouldReceive('exec') ->once() ->andReturn($rawHeader . $this->fakeRawBody); @@ -282,15 +240,6 @@ class FacebookCurlHttpClientTest extends AbstractTestHttpClient ->once() ->andReturn(null); $this->curlMock - ->shouldReceive('getinfo') - ->with(CURLINFO_HEADER_SIZE) - ->once() - ->andReturn(mb_strlen($this->fakeRawHeader)); - $this->curlMock - ->shouldReceive('version') - ->once() - ->andReturn(['version_number' => self::CURL_VERSION_STABLE]); - $this->curlMock ->shouldReceive('close') ->once() ->andReturn(null); diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php index 12eb36a..f14ad96 100644 --- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php +++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookGuzzleHttpClientTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -42,7 +42,7 @@ class FacebookGuzzleHttpClientTest extends AbstractTestHttpClient */ protected $guzzleClient; - public function setUp() + protected function setUp() { $this->guzzleMock = m::mock('GuzzleHttp\Client'); $this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock); diff --git a/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php b/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php index 9102b08..3749960 100644 --- a/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php +++ b/lib/facebook-graph-sdk/tests/HttpClients/FacebookStreamHttpClientTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -38,7 +38,7 @@ class FacebookStreamHttpClientTest extends AbstractTestHttpClient */ protected $streamClient; - public function setUp() + protected function setUp() { $this->streamMock = m::mock('Facebook\HttpClients\FacebookStream'); $this->streamClient = new FacebookStreamHttpClient($this->streamMock); diff --git a/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php b/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php new file mode 100644 index 0000000..4d49489 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/HttpClients/HttpClientsFactoryTest.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\HttpClients; + +use Facebook\HttpClients\FacebookCurlHttpClient; +use Facebook\HttpClients\FacebookGuzzleHttpClient; +use Facebook\HttpClients\FacebookStreamHttpClient; +use Facebook\HttpClients\HttpClientsFactory; +use GuzzleHttp\Client; +use PHPUnit_Framework_TestCase; + +class HttpClientsFactoryTest extends PHPUnit_Framework_TestCase +{ + const COMMON_NAMESPACE = 'Facebook\HttpClients\\'; + const COMMON_INTERFACE = 'Facebook\HttpClients\FacebookHttpClientInterface'; + + /** + * @param mixed $handler + * @param string $expected + * + * @dataProvider httpClientsProvider + */ + public function testCreateHttpClient($handler, $expected) + { + $httpClient = HttpClientsFactory::createHttpClient($handler); + + $this->assertInstanceOf(self::COMMON_INTERFACE, $httpClient); + $this->assertInstanceOf($expected, $httpClient); + } + + /** + * @return array + */ + public function httpClientsProvider() + { + $clients = [ + ['guzzle', self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], + ['stream', self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'], + [new Client(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], + [new FacebookGuzzleHttpClient(), self::COMMON_NAMESPACE . 'FacebookGuzzleHttpClient'], + [new FacebookStreamHttpClient(), self::COMMON_NAMESPACE . 'FacebookStreamHttpClient'], + [null, self::COMMON_INTERFACE], + ]; + if (extension_loaded('curl')) { + $clients[] = ['curl', self::COMMON_NAMESPACE . 'FacebookCurlHttpClient']; + $clients[] = [new FacebookCurlHttpClient(), self::COMMON_NAMESPACE . 'FacebookCurlHttpClient']; + } + + return $clients; + } +} diff --git a/lib/facebook-graph-sdk/tests/PersistentData/FacebookMemoryPersistentDataHandlerTest.php b/lib/facebook-graph-sdk/tests/PersistentData/FacebookMemoryPersistentDataHandlerTest.php index 2b09d29..89717f8 100644 --- a/lib/facebook-graph-sdk/tests/PersistentData/FacebookMemoryPersistentDataHandlerTest.php +++ b/lib/facebook-graph-sdk/tests/PersistentData/FacebookMemoryPersistentDataHandlerTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/PersistentData/FacebookSessionPersistentDataHandlerTest.php b/lib/facebook-graph-sdk/tests/PersistentData/FacebookSessionPersistentDataHandlerTest.php index e21d366..752d275 100644 --- a/lib/facebook-graph-sdk/tests/PersistentData/FacebookSessionPersistentDataHandlerTest.php +++ b/lib/facebook-graph-sdk/tests/PersistentData/FacebookSessionPersistentDataHandlerTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -32,7 +32,7 @@ class FacebookSessionPersistentDataHandlerTest extends \PHPUnit_Framework_TestCa */ public function testInactiveSessionsWillThrow() { - $handler = new FacebookSessionPersistentDataHandler(); + new FacebookSessionPersistentDataHandler(); } public function testCanSetAValue() diff --git a/lib/facebook-graph-sdk/tests/PersistentData/PersistentDataFactoryTest.php b/lib/facebook-graph-sdk/tests/PersistentData/PersistentDataFactoryTest.php new file mode 100644 index 0000000..d6206fc --- /dev/null +++ b/lib/facebook-graph-sdk/tests/PersistentData/PersistentDataFactoryTest.php @@ -0,0 +1,68 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\PersistentData; + +use Facebook\PersistentData\FacebookMemoryPersistentDataHandler; +use Facebook\PersistentData\FacebookSessionPersistentDataHandler; +use Facebook\PersistentData\PersistentDataFactory; +use PHPUnit_Framework_TestCase; + +class PersistentDataFactoryTest extends PHPUnit_Framework_TestCase +{ + const COMMON_NAMESPACE = 'Facebook\PersistentData\\'; + const COMMON_INTERFACE = 'Facebook\PersistentData\PersistentDataInterface'; + + /** + * @param mixed $handler + * @param string $expected + * + * @dataProvider persistentDataHandlerProviders + */ + public function testCreatePersistentDataHandler($handler, $expected) + { + $persistentDataHandler = PersistentDataFactory::createPersistentDataHandler($handler); + + $this->assertInstanceOf(self::COMMON_INTERFACE, $persistentDataHandler); + $this->assertInstanceOf($expected, $persistentDataHandler); + } + + /** + * @return array + */ + public function persistentDataHandlerProviders() + { + $handlers = [ + ['memory', self::COMMON_NAMESPACE . 'FacebookMemoryPersistentDataHandler'], + [new FacebookMemoryPersistentDataHandler(), self::COMMON_NAMESPACE . 'FacebookMemoryPersistentDataHandler'], + [new FacebookSessionPersistentDataHandler(false), self::COMMON_NAMESPACE . 'FacebookSessionPersistentDataHandler'], + [null, self::COMMON_INTERFACE], + ]; + + if (session_status() === PHP_SESSION_ACTIVE) { + $handlers[] = ['session', self::COMMON_NAMESPACE . 'FacebookSessionPersistentDataHandler']; + } + + return $handlers; + } +} diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/McryptPseudoRandomStringGeneratorTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/McryptPseudoRandomStringGeneratorTest.php index a45a3cf..f5e0336 100644 --- a/lib/facebook-graph-sdk/tests/PseudoRandomString/McryptPseudoRandomStringGeneratorTest.php +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/McryptPseudoRandomStringGeneratorTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -29,6 +29,10 @@ class McryptPseudoRandomStringGeneratorTest extends \PHPUnit_Framework_TestCase { public function testCanGenerateRandomStringOfArbitraryLength() { + if (version_compare(PHP_VERSION, '7.1', '>=')) { + $this->markTestSkipped('Skipping test mcrypt is deprecated from 7.1'); + } + if (!function_exists('mcrypt_create_iv')) { $this->markTestSkipped( 'Mcrypt must be installed to test mcrypt_create_iv().' diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/OpenSslPseudoRandomStringGeneratorTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/OpenSslPseudoRandomStringGeneratorTest.php index c740d0b..3ab4edc 100644 --- a/lib/facebook-graph-sdk/tests/PseudoRandomString/OpenSslPseudoRandomStringGeneratorTest.php +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/OpenSslPseudoRandomStringGeneratorTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringFactoryTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringFactoryTest.php new file mode 100644 index 0000000..9dc679e --- /dev/null +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringFactoryTest.php @@ -0,0 +1,71 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\PseudoRandomString; + +use Facebook\PseudoRandomString\PseudoRandomStringGeneratorFactory; +use PHPUnit_Framework_TestCase; + +class PseudoRandomStringFactoryTest extends PHPUnit_Framework_TestCase +{ + const COMMON_NAMESPACE = 'Facebook\PseudoRandomString\\'; + const COMMON_INTERFACE = 'Facebook\PseudoRandomString\PseudoRandomStringGeneratorInterface'; + + /** + * @param mixed $handler + * @param string $expected + * + * @dataProvider csprngProvider + */ + public function testCsprng($handler, $expected) + { + $pseudoRandomStringGenerator = PseudoRandomStringGeneratorFactory::createPseudoRandomStringGenerator($handler); + + $this->assertInstanceOf(self::COMMON_INTERFACE, $pseudoRandomStringGenerator); + $this->assertInstanceOf($expected, $pseudoRandomStringGenerator); + } + + /** + * @return array + */ + public function csprngProvider() + { + $providers = [ + [null, self::COMMON_INTERFACE], + ]; + if (function_exists('random_bytes')) { + $providers[] = ['random_bytes', self::COMMON_NAMESPACE . 'RandomBytesPseudoRandomStringGenerator']; + } + if (function_exists('mcrypt_create_iv')) { + $providers[] = ['mcrypt', self::COMMON_NAMESPACE . 'McryptPseudoRandomStringGenerator']; + } + if (function_exists('openssl_random_pseudo_bytes')) { + $providers[] = ['openssl', self::COMMON_NAMESPACE . 'OpenSslPseudoRandomStringGenerator']; + } + if (!ini_get('open_basedir') && is_readable('/dev/urandom')) { + $providers[] = ['urandom', self::COMMON_NAMESPACE . 'UrandomPseudoRandomStringGenerator']; + } + + return $providers; + } +} diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringGeneratorTraitTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringGeneratorTraitTest.php index ea3a1f8..16165d9 100644 --- a/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringGeneratorTraitTest.php +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/PseudoRandomStringGeneratorTraitTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -23,12 +23,7 @@ */ namespace Facebook\Tests\PseudoRandomString; -use Facebook\PseudoRandomString\PseudoRandomStringGeneratorTrait; - -class MyFooBarPseudoRandomStringGenerator -{ - use PseudoRandomStringGeneratorTrait; -} +use Facebook\Tests\Fixtures\MyFooBarPseudoRandomStringGenerator; class PseudoRandomStringGeneratorTraitTest extends \PHPUnit_Framework_TestCase { diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/RandomBytesPseudoRandomStringGeneratorTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/RandomBytesPseudoRandomStringGeneratorTest.php new file mode 100644 index 0000000..61f2a46 --- /dev/null +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/RandomBytesPseudoRandomStringGeneratorTest.php @@ -0,0 +1,44 @@ +<?php +/** + * Copyright 2017 Facebook, Inc. + * + * You are hereby granted a non-exclusive, worldwide, royalty-free license to + * use, copy, modify, and distribute this software in source code or binary + * form for use in connection with the web services and APIs provided by + * Facebook. + * + * As with any software that integrates with the Facebook platform, your use + * of this software is subject to the Facebook Developer Principles and + * Policies [http://developers.facebook.com/policy/]. This copyright notice + * shall be included in all copies or substantial portions of the software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + */ +namespace Facebook\Tests\PseudoRandomString; + +use Facebook\PseudoRandomString\RandomBytesPseudoRandomStringGenerator; + +class RandomBytesPseudoRandomStringGeneratorTest extends \PHPUnit_Framework_TestCase +{ + public function testCanGenerateRandomStringOfArbitraryLength() + { + if (!function_exists('random_bytes')) { + $this->markTestSkipped( + 'Must have PHP 7 or paragonie/random_compat installed to test random_bytes().' + ); + } + + $csprng = new RandomBytesPseudoRandomStringGenerator; + $randomString = $csprng->getPseudoRandomString(10); + + $this->assertEquals(1, preg_match('/^([0-9a-f]+)$/', $randomString)); + $this->assertEquals(10, strlen($randomString)); + } +} diff --git a/lib/facebook-graph-sdk/tests/PseudoRandomString/UrandomPseudoRandomStringGeneratorTest.php b/lib/facebook-graph-sdk/tests/PseudoRandomString/UrandomPseudoRandomStringGeneratorTest.php index 9e12a58..e67136f 100644 --- a/lib/facebook-graph-sdk/tests/PseudoRandomString/UrandomPseudoRandomStringGeneratorTest.php +++ b/lib/facebook-graph-sdk/tests/PseudoRandomString/UrandomPseudoRandomStringGeneratorTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/SignedRequestTest.php b/lib/facebook-graph-sdk/tests/SignedRequestTest.php index 247600f..119f27c 100644 --- a/lib/facebook-graph-sdk/tests/SignedRequestTest.php +++ b/lib/facebook-graph-sdk/tests/SignedRequestTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -46,7 +46,7 @@ class SignedRequestTest extends \PHPUnit_Framework_TestCase 'foo' => 'bar', ]; - public function setUp() + protected function setUp() { $this->app = new FacebookApp('123', 'foo_app_secret'); } diff --git a/lib/facebook-graph-sdk/tests/Url/FacebookUrlDetectionHandlerTest.php b/lib/facebook-graph-sdk/tests/Url/FacebookUrlDetectionHandlerTest.php index c3127ef..b623c05 100644 --- a/lib/facebook-graph-sdk/tests/Url/FacebookUrlDetectionHandlerTest.php +++ b/lib/facebook-graph-sdk/tests/Url/FacebookUrlDetectionHandlerTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/Url/FacebookUrlManipulatorTest.php b/lib/facebook-graph-sdk/tests/Url/FacebookUrlManipulatorTest.php index c58e2b3..d92a285 100644 --- a/lib/facebook-graph-sdk/tests/Url/FacebookUrlManipulatorTest.php +++ b/lib/facebook-graph-sdk/tests/Url/FacebookUrlManipulatorTest.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary diff --git a/lib/facebook-graph-sdk/tests/bootstrap.php b/lib/facebook-graph-sdk/tests/bootstrap.php index 4b04836..49fba28 100644 --- a/lib/facebook-graph-sdk/tests/bootstrap.php +++ b/lib/facebook-graph-sdk/tests/bootstrap.php @@ -1,6 +1,6 @@ <?php /** - * Copyright 2014 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary @@ -25,8 +25,6 @@ date_default_timezone_set('Europe/Paris'); require_once __DIR__ . '/../vendor/autoload.php'; -use Facebook\FacebookClient; - // Delete the temp test user after all tests have fired register_shutdown_function(function () { //echo "\nTotal requests made to Graph: " . FacebookClient::$requestCount . "\n\n"; |