From 4b8a9a5189a625bf99fedec7fd31f6e146410a14 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 26 Apr 2018 01:00:12 +0200 Subject: Update FB API library --- lib/facebook-graph-sdk/tests/FacebookTest.php | 154 ++++++++++++++++---------- 1 file changed, 96 insertions(+), 58 deletions(-) (limited to 'lib/facebook-graph-sdk/tests/FacebookTest.php') 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 @@ '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); + } } -- cgit v1.2.3