/** * Test fetch PUT params */ public function testPut() { Slim_Environment::mock(array('REQUEST_METHOD' => 'PUT', '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(2, count($req->put())); $this->assertEquals('bar', $req->put('foo')); $this->assertNull($req->put('xyz')); }
/** * Test fetch PUT params */ public function testPut() { $env = Slim_Environment::mock(array('REQUEST_METHOD' => 'PUT', '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->put())); $this->assertEquals('bar', $req->put('foo')); $this->assertEquals('bar', $req->params('foo')); $this->assertNull($req->put('xyz')); }
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')); }