예제 #1
0
 /**
  * Test fetch DELETE params
  */
 public function testDelete()
 {
     $env = Slim_Environment::mock(array('REQUEST_METHOD' => 'DELETE', 'slim.input' => 'foo=bar&abc=123', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 15));
     $req = new Slim_Http_Request($env);
     $this->assertEquals(2, count($req->delete()));
     $this->assertEquals('bar', $req->delete('foo'));
     $this->assertEquals('bar', $req->params('foo'));
     $this->assertNull($req->delete('xyz'));
 }
예제 #2
0
 /**
  * Test params from request body
  */
 public function testParamsFromRequestBody()
 {
     $env = Slim_Environment::mock(array('REQUEST_METHOD' => 'POST', 'QUERY_STRING' => 'one=1&two=2&three=3', 'slim.input' => 'foo=bar&abc=123', 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 15));
     $req = new Slim_Http_Request($env);
     $this->assertEquals(5, count($req->params()));
     //Union of GET and POST
     $this->assertEquals('bar', $req->params('foo'));
 }
예제 #3
0
 /**
  * Test params from request body
  */
 public function testParamsFromRequestBody()
 {
     Slim_Environment::mock(array('REQUEST_METHOD' => 'POST', 'REMOTE_ADDR' => '127.0.0.1', 'SCRIPT_NAME' => '/foo/index.php', 'PATH_INFO' => '/bar/xyz', 'QUERY_STRING' => 'one=1&two=2&three=3', 'SERVER_NAME' => 'slim', 'SERVER_PORT' => 80, 'slim.url_scheme' => 'http', 'slim.input' => 'foo=bar&abc=123', 'slim.errors' => fopen('php://stderr', 'w'), 'CONTENT_TYPE' => 'application/x-www-form-urlencoded', 'CONTENT_LENGTH' => 15));
     $env = Slim_Environment::getInstance();
     $req = new Slim_Http_Request($env);
     $this->assertEquals(5, count($req->params()));
     //Union of GET and POST
     $this->assertEquals('bar', $req->params('foo'));
 }
예제 #4
0
 public function testParams()
 {
     //Case A: PUT params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('_METHOD' => 'PUT', 'foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->put('foo1'));
     $this->assertEquals(array('foo1' => 'bar1'), $r->put());
     //Case B: POST params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_POST = array('foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->post('foo1'));
     $this->assertEquals($_POST, $r->post());
     //Case C: GET params
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_POST = array();
     $_GET = array('foo1' => 'bar1');
     $r = new Slim_Http_Request();
     $this->assertEquals('bar1', $r->params('foo1'));
     $this->assertEquals('bar1', $r->get('foo1'));
     $this->assertEquals($_GET, $r->get());
     //Case D: COOKIE params
     $_COOKIE['foo'] = 'bar';
     $r = new Slim_Http_Request();
     $this->assertEquals($_COOKIE, $r->cookies());
     $this->assertEquals('bar', $r->cookies('foo'));
     //Case E: NULL params
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_GET = array();
     $_POST = array();
     $r = new Slim_Http_Request();
     $this->assertNull($r->params('foo1'));
     $this->assertNull($r->put('foo1'));
     $this->assertNull($r->post('foo1'));
     $this->assertNull($r->get('foo1'));
     $this->assertNull($r->cookies('foo1'));
 }