Ejemplo n.º 1
0
 /**
  * Makes a batched request to Graph and returns the result.
  *
  * @param FacebookBatchRequest $request
  *
  * @return FacebookBatchResponse
  *
  * @throws FacebookSDKException
  */
 public function sendBatchRequest(FacebookBatchRequest $request)
 {
     $request->prepareRequestsForBatch();
     $facebookResponse = $this->sendRequest($request);
     return new FacebookBatchResponse($request, $facebookResponse);
 }
 public function testAFacebookBatchRequestWillProperlyBatchFiles()
 {
     $fbRequests = [new FacebookRequest($this->fbApp, 'token', 'POST', '/photo', ['message' => 'foobar', 'source' => new FacebookFile(__DIR__ . '/foo.txt')]), new FacebookRequest($this->fbApp, 'token', 'POST', '/video', ['message' => 'foobar', 'source' => new FacebookVideo(__DIR__ . '/foo.txt')])];
     $fbBatchRequest = new FacebookBatchRequest($this->fbApp, $fbRequests);
     $fbBatchRequest->prepareRequestsForBatch();
     list($url, $method, $headers, $body) = $this->fbClient->prepareRequestMessage($fbBatchRequest);
     $this->assertEquals(FacebookClient::BASE_GRAPH_VIDEO_URL . '/' . Facebook::DEFAULT_GRAPH_VERSION, $url);
     $this->assertEquals('POST', $method);
     $this->assertContains('multipart/form-data; boundary=', $headers['Content-Type']);
     $this->assertContains('Content-Disposition: form-data; name="batch"', $body);
     $this->assertContains('Content-Disposition: form-data; name="include_headers"', $body);
     $this->assertContains('"name":0,"attached_files":', $body);
     $this->assertContains('"name":1,"attached_files":', $body);
     $this->assertContains('"; filename="foo.txt"', $body);
 }
 private function createAndAppendRequestsTo(FacebookBatchRequest $batchRequest, $number)
 {
     for ($i = 0; $i < $number; $i++) {
         $batchRequest->add(new FacebookRequest());
     }
 }