diff options
Diffstat (limited to 'tests/codeigniter')
-rw-r--r-- | tests/codeigniter/core/Input_test.php | 47 | ||||
-rw-r--r-- | tests/codeigniter/core/URI_test.php | 15 | ||||
-rw-r--r-- | tests/codeigniter/core/Utf8_test.php | 13 |
3 files changed, 59 insertions, 16 deletions
diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 0a98e556c..95833fc91 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -138,13 +138,24 @@ class Input_test extends CI_TestCase { public function test_valid_ip() { - $ip_v4 = '192.18.0.1'; - $this->assertTrue($this->input->valid_ip($ip_v4)); + $this->assertTrue($this->input->valid_ip('192.18.0.1')); + $this->assertTrue($this->input->valid_ip('192.18.0.1', 'ipv4')); + $this->assertFalse($this->input->valid_ip('555.0.0.0')); + $this->assertFalse($this->input->valid_ip('2001:db8:0:85a3::ac1f:8001', 'ipv4')); + + // v6 tests + $this->assertFalse($this->input->valid_ip('192.18.0.1', 'ipv6')); + + $ip_v6 = array( + '2001:0db8:0000:85a3:0000:0000:ac1f:8001', + '2001:db8:0:85a3:0:0:ac1f:8001', + '2001:db8:0:85a3::ac1f:8001' + ); - $ip_v6 = array('2001:0db8:0000:85a3:0000:0000:ac1f:8001', '2001:db8:0:85a3:0:0:ac1f:8001', '2001:db8:0:85a3::ac1f:8001'); foreach ($ip_v6 as $ip) { $this->assertTrue($this->input->valid_ip($ip)); + $this->assertTrue($this->input->valid_ip($ip, 'ipv6')); } } @@ -171,4 +182,34 @@ class Input_test extends CI_TestCase { $this->assertTrue($this->input->is_ajax_request()); } + // -------------------------------------------------------------------- + + public function test_input_stream() + { + $this->markTestSkipped('TODO: Find a way to test input://'); + } + + // -------------------------------------------------------------------- + + public function test_set_cookie() + { + $this->markTestSkipped('TODO: Find a way to test HTTP headers'); + } + + public function test_ip_address() + { + // 127.0.0.1 is set in our Bootstrap file + $this->assertEquals('127.0.0.1', $this->input->ip_address()); + + // Invalid + $_SERVER['REMOTE_ADDR'] = 'invalid_ip_address'; + $this->input->ip_address = FALSE; // reset cached value + $this->assertEquals('0.0.0.0', $this->input->ip_address()); + + // TODO: Add proxy_ips tests + + // Back to reality + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality + } + }
\ No newline at end of file diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 7fa0e6265..99d79bbd2 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -112,11 +112,10 @@ class URI_test extends CI_TestCase { public function test_filter_uri() { - $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-'); $str_in = 'abc01239~%.:_-'; - $str = $this->uri->_filter_uri($str_in); + $str = $this->uri->filter_uri($str_in); $this->assertEquals($str, $str_in); } @@ -126,11 +125,9 @@ class URI_test extends CI_TestCase { public function test_filter_uri_escaping() { // ensure escaping even if dodgey characters are permitted + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-()$'); - $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-()$'); - - $str = $this->uri->_filter_uri('$destroy_app(foo)'); + $str = $this->uri->filter_uri('$destroy_app(foo)'); $this->assertEquals($str, '$destroy_app(foo)'); } @@ -142,8 +139,8 @@ class URI_test extends CI_TestCase { $this->setExpectedException('RuntimeException'); $this->uri->config->set_item('enable_query_strings', FALSE); - $this->uri->config->set_item('permitted_uri_chars', 'a-z 0-9~%.:_\-'); - $this->uri->_filter_uri('$this()'); + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-'); + $this->uri->filter_uri('$this()'); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index caa7b6986..71299134e 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -11,10 +11,15 @@ class Utf8_test extends CI_TestCase { public function test_convert_to_utf8() { - $this->assertEquals( - $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251'), - 'ัะตัั' - ); + $this->assertEquals('ัะตัั', $this->utf8->convert_to_utf8('๒ๅ๑๒', 'WINDOWS-1251')); + } + + // -------------------------------------------------------------------- + + public function test_is_ascii() + { + $this->assertTrue($this->utf8->is_ascii_test('foo bar')); + $this->assertFalse($this->utf8->is_ascii_test('ัะตัั')); } }
\ No newline at end of file |