From 8729b2f1e54ed19f18cf31ba5c11a2953a7e4274 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Fri, 22 Jun 2018 16:51:11 +0800 Subject: Adding unit test. Signed-off-by: tianhe1986 --- tests/codeigniter/core/Input_test.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 80cb9a740..07a99e136 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -90,6 +90,23 @@ class Input_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_post_get_array_notation() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo']['bar'] = 'baz'; + $barArray = array('bar' => 'baz'); + + $this->assertEquals('baz', $this->input->get_post('foo[bar]')); + $this->assertEquals($barArray, $this->input->get_post('foo[]')); + $this->assertNull($this->input->get_post('foo[baz]')); + + $this->assertEquals('baz', $this->input->post_get('foo[bar]')); + $this->assertEquals($barArray, $this->input->post_get('foo[]')); + $this->assertNull($this->input->post_get('foo[baz]')); + } + + // -------------------------------------------------------------------- + public function test_get_post() { $_SERVER['REQUEST_METHOD'] = 'GET'; @@ -100,6 +117,23 @@ class Input_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_get_post_array_notation() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo']['bar'] = 'baz'; + $barArray = array('bar' => 'baz'); + + $this->assertEquals('baz', $this->input->get_post('foo[bar]')); + $this->assertEquals($barArray, $this->input->get_post('foo[]')); + $this->assertNull($this->input->get_post('foo[baz]')); + + $this->assertEquals('baz', $this->input->post_get('foo[bar]')); + $this->assertEquals($barArray, $this->input->post_get('foo[]')); + $this->assertNull($this->input->post_get('foo[baz]')); + } + + // -------------------------------------------------------------------- + public function test_cookie() { $_COOKIE['foo'] = 'bar'; -- cgit v1.2.3-24-g4f1b