From ca16c4ff1aa0cf5ebfbe877e9be755c0b7d2061c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 15:15:30 +0700 Subject: Adding autoloader and mocks directory --- tests/codeigniter/core/Common_test.php | 2 -- tests/codeigniter/core/Loader_test.php | 38 +--------------------------------- tests/codeigniter/core/URI_test.php | 33 +---------------------------- 3 files changed, 2 insertions(+), 71 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index cec12982d..29b512d8a 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,7 +1,5 @@ models_dir = vfsStream::newDirectory('models')->at(vfsStreamWrapper::getRoot()); - $this->libs_dir = vfsStream::newDirectory('libraries')->at(vfsStreamWrapper::getRoot()); - $this->helpers_dir = vfsStream::newDirectory('helpers')->at(vfsStreamWrapper::getRoot()); - $this->views_dir = vfsStream::newDirectory('views')->at(vfsStreamWrapper::getRoot()); - - $this->_ci_ob_level = ob_get_level(); - $this->_ci_library_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_helper_paths = array(vfsStream::url('application').'/', BASEPATH); - $this->_ci_model_paths = array(vfsStream::url('application').'/'); - $this->_ci_view_paths = array(vfsStream::url('application').'/views/' => TRUE); - } -} - - class Loader_test extends CI_TestCase { private $ci_obj; @@ -40,7 +7,7 @@ class Loader_test extends CI_TestCase { public function set_up() { // Instantiate a new loader - $this->load = new Extended_Loader(); + $this->load = new Mock_Core_Loader(); // mock up a ci instance $this->ci_obj = new StdClass; @@ -265,7 +232,4 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- - - - } diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 40252aa14..e340ddf73 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -1,41 +1,10 @@ ci_core_class('cfg'); - - // set predictable config values - $test->ci_set_config(array( - 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', - 'subclass_prefix' => 'MY_' - )); - - $this->config = new $cls; - - } - - protected function _is_cli_request() - { - return FALSE; - } -} - class URI_test extends CI_TestCase { public function set_up() { - $this->uri = new URI_extended(); + $this->uri = new Mock_Core_URI(); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From ac5373a8979537f5454af6b911108541140a35d7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:03:38 +0700 Subject: Adding core and libraries mock classes --- tests/codeigniter/core/Common_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 29b512d8a..dded2e824 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -1,7 +1,6 @@ Date: Tue, 15 May 2012 18:47:24 +0700 Subject: Benchmark code-coverage --- tests/codeigniter/core/Benchmark_test.php | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/codeigniter/core/Benchmark_test.php (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php new file mode 100644 index 000000000..2790b582e --- /dev/null +++ b/tests/codeigniter/core/Benchmark_test.php @@ -0,0 +1,42 @@ +benchmark = new Mock_Core_Benchmark(); + } + + // -------------------------------------------------------------------- + + public function test_mark() + { + $this->assertEmpty($this->benchmark->marker); + + $this->benchmark->mark('code_start'); + + $this->assertEquals(1, count($this->benchmark->marker)); + $this->assertArrayHasKey('code_start', $this->benchmark->marker); + } + + // -------------------------------------------------------------------- + + public function test_elapsed_time() + { + $this->assertEquals('{elapsed_time}', $this->benchmark->elapsed_time()); + $this->assertEmpty($this->benchmark->elapsed_time('undefined_point')); + + $this->benchmark->mark('code_start'); + sleep(1); + $this->benchmark->mark('code_end'); + + $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + } + + // -------------------------------------------------------------------- + + public function test_memory_usage() + { + $this->assertEquals('{memory_usage}', $this->benchmark->memory_usage()); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8af88f3f729b7bcfd2a106f858b5445deafe5ed0 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 21:52:53 +0700 Subject: Security Code coverage --- tests/codeigniter/core/Security_test.php | 79 ++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/codeigniter/core/Security_test.php (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php new file mode 100644 index 000000000..c3b526965 --- /dev/null +++ b/tests/codeigniter/core/Security_test.php @@ -0,0 +1,79 @@ +ci_set_config('csrf_protection', TRUE); + $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); + // @see : ./Bootstrap.php Line 16 + $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); + $this->ci_set_config('csrf_expire', 7200); + $this->ci_set_config('csrf_regenerate', TRUE); + $this->ci_set_config('csrf_exclude_uris', array()); + + $this->ci_set_config('cookie_prefix', ""); + $this->ci_set_config('cookie_domain', ""); + $this->ci_set_config('cookie_path', "/"); + $this->ci_set_config('cookie_secure', FALSE); + $this->ci_set_config('cookie_httponly', FALSE); + + $this->security = new Mock_Core_Security(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_invalid() + { + // Without issuing $_POST[csrf_token_name], this request will triggering CSRF error + $_SERVER['REQUEST_METHOD'] = 'POST'; + + $this->setExpectedException('RuntimeException', 'CI Error: The action you have requested is not allowed'); + + $this->security->csrf_verify(); + } + + // -------------------------------------------------------------------- + + public function test_csrf_verify_valid() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST[$this->security->csrf_token_name] = $this->security->csrf_hash; + + $this->assertInstanceOf('CI_Security', $this->security->csrf_verify()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_hash() + { + $this->assertEquals($this->security->csrf_hash, $this->security->get_csrf_hash()); + } + + // -------------------------------------------------------------------- + + public function test_get_csrf_token_name() + { + $this->assertEquals('ci_csrf_token', $this->security->get_csrf_token_name()); + } + + // -------------------------------------------------------------------- + + public function test_xss_clean() + { + $harm_string = "Hello, i try to your site"; + + $harmless_string = $this->security->xss_clean($harm_string); + + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 7756af5df0a53930019e9fd7b828504f0c2c5427 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Tue, 15 May 2012 23:57:05 +0700 Subject: Input class code-coverage --- tests/codeigniter/core/Input_test.php | 144 +++++++++++++++++++++++++++++++ tests/codeigniter/core/Security_test.php | 14 +-- 2 files changed, 148 insertions(+), 10 deletions(-) create mode 100644 tests/codeigniter/core/Input_test.php (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php new file mode 100644 index 000000000..fd0576e38 --- /dev/null +++ b/tests/codeigniter/core/Input_test.php @@ -0,0 +1,144 @@ +ci_set_config('allow_get_array', TRUE); + $this->ci_set_config('global_xss_filtering', FALSE); + $this->ci_set_config('csrf_protection', FALSE); + + $security = new Mock_Core_Security(); + $utf8 = new Mock_Core_Utf8(); + + $this->input = new Mock_Core_Input($security, $utf8); + } + + // -------------------------------------------------------------------- + + public function test_get_not_exists() + { + $this->assertEmpty($this->input->get()); + $this->assertEmpty($this->input->get('foo')); + + $this->assertTrue( ! $this->input->get()); + $this->assertTrue( ! $this->input->get('foo')); + + $this->assertTrue($this->input->get() == FALSE); + $this->assertTrue($this->input->get('foo') == FALSE); + + $this->assertTrue($this->input->get() === FALSE); + $this->assertTrue($this->input->get('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_get_exist() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->get()); + $this->assertEquals('bar', $this->input->get('foo')); + } + + // -------------------------------------------------------------------- + + public function test_get_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'GET'; + $_GET['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->get()); + $this->assertEquals("Hello, i try to your site", $this->input->get('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->get('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_post_not_exists() + { + $this->assertEmpty($this->input->post()); + $this->assertEmpty($this->input->post('foo')); + + $this->assertTrue( ! $this->input->post()); + $this->assertTrue( ! $this->input->post('foo')); + + $this->assertTrue($this->input->post() == FALSE); + $this->assertTrue($this->input->post('foo') == FALSE); + + $this->assertTrue($this->input->post() === FALSE); + $this->assertTrue($this->input->post('foo') === FALSE); + } + + // -------------------------------------------------------------------- + + public function test_post_exist() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertArrayHasKey('foo', $this->input->post()); + $this->assertEquals('bar', $this->input->post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_post_exist_with_xss_clean() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['harm'] = "Hello, i try to your site"; + + $this->assertArrayHasKey('harm', $this->input->post()); + $this->assertEquals("Hello, i try to your site", $this->input->post('harm')); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $this->input->post('harm', TRUE)); + } + + // -------------------------------------------------------------------- + + public function test_get_post() + { + $_SERVER['REQUEST_METHOD'] = 'POST'; + $_POST['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->get_post('foo')); + } + + // -------------------------------------------------------------------- + + public function test_cookie() + { + $_COOKIE['foo'] = 'bar'; + + $this->assertEquals('bar', $this->input->cookie('foo')); + } + + // -------------------------------------------------------------------- + + public function test_server() + { + $this->assertEquals('GET', $this->input->server('REQUEST_METHOD')); + } + + // -------------------------------------------------------------------- + + public function test_fetch_from_array() + { + $data = array( + 'foo' => 'bar', + 'harm' => 'Hello, i try to your site', + ); + + $foo = $this->input->fetch_from_array($data, 'foo'); + $harm = $this->input->fetch_from_array($data, 'harm'); + $harmless = $this->input->fetch_from_array($data, 'harm', TRUE); + + $this->assertEquals('bar', $foo); + $this->assertEquals("Hello, i try to your site", $harm); + $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); + } +} \ No newline at end of file diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index c3b526965..1796ba74d 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -4,19 +4,13 @@ class Security_test extends CI_TestCase { public function set_up() { + // Set cookie for security test + $_COOKIE['ci_csrf_cookie'] = md5(uniqid(rand(), TRUE)); + + // Set config for Security class $this->ci_set_config('csrf_protection', TRUE); $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); - // @see : ./Bootstrap.php Line 16 $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - $this->ci_set_config('csrf_expire', 7200); - $this->ci_set_config('csrf_regenerate', TRUE); - $this->ci_set_config('csrf_exclude_uris', array()); - - $this->ci_set_config('cookie_prefix', ""); - $this->ci_set_config('cookie_domain', ""); - $this->ci_set_config('cookie_path', "/"); - $this->ci_set_config('cookie_secure', FALSE); - $this->ci_set_config('cookie_httponly', FALSE); $this->security = new Mock_Core_Security(); } -- cgit v1.2.3-24-g4f1b From 09a1b5e7fb3c930aa9a50e246236227a499b5d28 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 16 May 2012 22:18:00 +0700 Subject: Reduce decimal points, since there is a micro differencess on runtime and update travis status --- tests/codeigniter/core/Benchmark_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Benchmark_test.php b/tests/codeigniter/core/Benchmark_test.php index 2790b582e..109b38821 100644 --- a/tests/codeigniter/core/Benchmark_test.php +++ b/tests/codeigniter/core/Benchmark_test.php @@ -29,8 +29,8 @@ class Benchmark_test extends CI_TestCase { $this->benchmark->mark('code_start'); sleep(1); $this->benchmark->mark('code_end'); - - $this->assertEquals('1.00', $this->benchmark->elapsed_time('code_start', 'code_end', 3)); + + $this->assertEquals('1.0', $this->benchmark->elapsed_time('code_start', 'code_end', 1)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 55a6ddb0c7bab1149bb1ddfa3a1aff46612c91d4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 23 May 2012 18:37:24 +0100 Subject: Input, Session and Cookie get's will return NULL. Read more about this change here: http://codeigniter.com/forums/viewthread/215833 --- tests/codeigniter/core/Input_test.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index fd0576e38..a066d9960 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -28,11 +28,13 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get()); $this->assertTrue( ! $this->input->get('foo')); - $this->assertTrue($this->input->get() == FALSE); - $this->assertTrue($this->input->get('foo') == FALSE); + // Test we're getting empty results + $this->assertTrue($this->input->get() == NULL); + $this->assertTrue($this->input->get('foo') == NULL); - $this->assertTrue($this->input->get() === FALSE); - $this->assertTrue($this->input->get('foo') === FALSE); + // Test new 3.0 behaviour for non existant results (used to be FALSE) + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); } // -------------------------------------------------------------------- @@ -68,11 +70,11 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == FALSE); - $this->assertTrue($this->input->post('foo') == FALSE); + $this->assertTrue($this->input->post() == NULL); + $this->assertTrue($this->input->post('foo') == NULL); - $this->assertTrue($this->input->post() === FALSE); - $this->assertTrue($this->input->post('foo') === FALSE); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6c7526c95b3fbd502dc8105a67fd38da793caa4e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sun, 27 May 2012 13:51:27 +0700 Subject: Continuation for Security and Table code-coverage, add coverage report to travis --- tests/codeigniter/core/Security_test.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 1796ba74d..b2f8c69d2 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -70,4 +70,36 @@ class Security_test extends CI_TestCase { $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless_string); } + + // -------------------------------------------------------------------- + + public function test_xss_hash() + { + $this->assertEmpty($this->security->xss_hash); + + // Perform hash + $this->security->xss_hash(); + + $this->assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash) === 1); + } + + // -------------------------------------------------------------------- + + public function test_entity_decode() + { + $encoded = '<div>Hello <b>Booya</b></div>'; + $decoded = $this->security->entity_decode($encoded); + + $this->assertEquals('
Hello Booya
', $decoded); + } + + // -------------------------------------------------------------------- + + public function test_sanitize_filename() + { + $filename = './'; + $safe_filename = $this->security->sanitize_filename($filename); + + $this->assertEquals('foo', $safe_filename); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From d6d1150959c95e43d310d0bc45f8bd674ff6460c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sat, 2 Jun 2012 11:12:55 +0100 Subject: Replaced `==` with `===` and `!=` with `!==` in /tests --- tests/codeigniter/core/Input_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index a066d9960..cfc80c950 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -29,8 +29,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->get('foo')); // Test we're getting empty results - $this->assertTrue($this->input->get() == NULL); - $this->assertTrue($this->input->get('foo') == NULL); + $this->assertTrue($this->input->get() === NULL); + $this->assertTrue($this->input->get('foo') === NULL); // Test new 3.0 behaviour for non existant results (used to be FALSE) $this->assertTrue($this->input->get() === NULL); @@ -70,8 +70,8 @@ class Input_test extends CI_TestCase { $this->assertTrue( ! $this->input->post()); $this->assertTrue( ! $this->input->post('foo')); - $this->assertTrue($this->input->post() == NULL); - $this->assertTrue($this->input->post('foo') == NULL); + $this->assertTrue($this->input->post() === NULL); + $this->assertTrue($this->input->post('foo') === NULL); $this->assertTrue($this->input->post() === NULL); $this->assertTrue($this->input->post('foo') === NULL); -- cgit v1.2.3-24-g4f1b From 06c22871943bee956522b893e8acbf206524a229 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 13:36:13 +0200 Subject: Add test when loading language file and not using the second parameter (language) --- tests/codeigniter/core/Lang_test.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index a414f0ace..92c71322e 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,13 +18,21 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); + $this->_test_line(); + } + + // -------------------------------------------------------------------- + + public function test_load_with_unspecified_language() + { + $this->assertTrue($this->lang->load('profiler')); + $this->_test_line(); } // -------------------------------------------------------------------- - public function test_line() + private function _test_line() { - $this->assertTrue($this->lang->load('profiler', 'english')); $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From d348cb0fd6f255074bc410f169072e2f613074fe Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Tue, 5 Jun 2012 15:32:55 +0200 Subject: remove _test_line() --- tests/codeigniter/core/Lang_test.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index 92c71322e..874230feb 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -18,7 +18,7 @@ class Lang_test extends CI_TestCase { public function test_load() { $this->assertTrue($this->lang->load('profiler', 'english')); - $this->_test_line(); + $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } // -------------------------------------------------------------------- @@ -26,13 +26,6 @@ class Lang_test extends CI_TestCase { public function test_load_with_unspecified_language() { $this->assertTrue($this->lang->load('profiler')); - $this->_test_line(); - } - - // -------------------------------------------------------------------- - - private function _test_line() - { $this->assertEquals('URI STRING', $this->lang->line('profiler_uri_string')); } -- cgit v1.2.3-24-g4f1b From 83c62ccf881847c5f4eef83822de0f7b09f98491 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:26:31 +0200 Subject: add tests for ipv6 and new method ip_version() --- tests/codeigniter/core/Input_test.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index cfc80c950..27e152d6a 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -143,4 +143,31 @@ class Input_test extends CI_TestCase { $this->assertEquals("Hello, i try to your site", $harm); $this->assertEquals("Hello, i try to [removed]alert('Hack');[removed] your site", $harmless); } + + // -------------------------------------------------------------------- + + public function test_valid_ip() + { + $ip_v4 = '175.123.74.43'; + $this->assertTrue($this->input->valid_ip($ip_v4)); + + $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)); + } + } + + // -------------------------------------------------------------------- + + public function test_ip_version() + { + $ip_v4 = '175.123.74.43'; + $this->assertEquals('4', $this->input->ip_version($ip_v4)); + + $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->assertEquals('6', $this->input->ip_version($ip)); + } + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0723617703dda3660597d9cdef59e7cdded1c497 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 14:39:02 +0200 Subject: follow styling guide --- tests/codeigniter/core/Input_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 27e152d6a..2aa3a6246 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -152,7 +152,8 @@ class Input_test extends CI_TestCase { $this->assertTrue($this->input->valid_ip($ip_v4)); $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) { + foreach($ip_v6 as $ip) + { $this->assertTrue($this->input->valid_ip($ip)); } } @@ -165,7 +166,8 @@ class Input_test extends CI_TestCase { $this->assertEquals('4', $this->input->ip_version($ip_v4)); $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) { + foreach($ip_v6 as $ip) + { $this->assertEquals('6', $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 908f36a583384b0314d04c4cfe71992746e35daa Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 15:47:22 +0200 Subject: ip_version() now returns int instead of string --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 2aa3a6246..98d6299f8 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -163,12 +163,12 @@ class Input_test extends CI_TestCase { public function test_ip_version() { $ip_v4 = '175.123.74.43'; - $this->assertEquals('4', $this->input->ip_version($ip_v4)); + $this->assertEquals(4, $this->input->ip_version($ip_v4)); $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->assertEquals('6', $this->input->ip_version($ip)); + $this->assertEquals(6, $this->input->ip_version($ip)); } } -- cgit v1.2.3-24-g4f1b From 70b5d3b4eb74ad27da7eac29ef5d349be944ba15 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 18:22:36 +0200 Subject: use an ip of the range 192.18.0.0/15 --- tests/codeigniter/core/Input_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 98d6299f8..3682d308d 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -148,7 +148,7 @@ class Input_test extends CI_TestCase { public function test_valid_ip() { - $ip_v4 = '175.123.74.43'; + $ip_v4 = '192.18.0.1'; $this->assertTrue($this->input->valid_ip($ip_v4)); $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'); @@ -162,7 +162,7 @@ class Input_test extends CI_TestCase { public function test_ip_version() { - $ip_v4 = '175.123.74.43'; + $ip_v4 = '192.18.0.1'; $this->assertEquals(4, $this->input->ip_version($ip_v4)); $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'); -- cgit v1.2.3-24-g4f1b From 1ab6f6520ebfc016c49cfbe3a4d9d009be5da268 Mon Sep 17 00:00:00 2001 From: Joffrey Jaffeux Date: Wed, 6 Jun 2012 20:14:13 +0200 Subject: removed ip_version() --- tests/codeigniter/core/Input_test.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tests/codeigniter/core') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 3682d308d..c9322c027 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -158,18 +158,4 @@ class Input_test extends CI_TestCase { } } - // -------------------------------------------------------------------- - - public function test_ip_version() - { - $ip_v4 = '192.18.0.1'; - $this->assertEquals(4, $this->input->ip_version($ip_v4)); - - $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->assertEquals(6, $this->input->ip_version($ip)); - } - } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b