예제 #1
0
 public function testProcessEntityRequest()
 {
     $io = new Google_CurlIO();
     $req = new Google_HttpRequest("http://localhost.com");
     $req->setRequestMethod("POST");
     // Verify that the content-length is calculated.
     $req->setPostBody("{}");
     $io->processEntityRequest($req);
     $this->assertEquals(2, $req->getRequestHeader("content-length"));
     // Test an empty post body.
     $req->setPostBody("");
     $io->processEntityRequest($req);
     $this->assertEquals(0, $req->getRequestHeader("content-length"));
     // Test a null post body.
     $req->setPostBody(null);
     $io->processEntityRequest($req);
     $this->assertEquals(0, $req->getRequestHeader("content-length"));
     // Set an array in the postbody, and verify that it is url-encoded.
     $req->setPostBody(array("a" => "1", "b" => 2));
     $io->processEntityRequest($req);
     $this->assertEquals(7, $req->getRequestHeader("content-length"));
     $this->assertEquals(Google_CurlIO::FORM_URLENCODED, $req->getRequestHeader("content-type"));
     $this->assertEquals("a=1&b=2", $req->getPostBody());
     // Verify that the content-type isn't reset.
     $payload = array("a" => "1", "b" => 2);
     $req->setPostBody($payload);
     $req->setRequestHeaders(array("content-type" => "multipart/form-data"));
     $io->processEntityRequest($req);
     $this->assertEquals("multipart/form-data", $req->getRequestHeader("content-type"));
     $this->assertEquals($payload, $req->getPostBody());
 }