Example #1
0
 public function processEntityRequest($io, $client)
 {
     $req = new Postman_Google_Http_Request("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(Postman_Google_IO_Abstract::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());
 }