From 554b452845e9ec26e1cd348fda607cf00d2a5026 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 1 Sep 2015 13:51:26 +0300 Subject: Fix #4093 --- tests/codeigniter/database/query_builder/where_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php index 20b7a567c..46a7fa2eb 100644 --- a/tests/codeigniter/database/query_builder/where_test.php +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -123,4 +123,12 @@ class Where_test extends CI_TestCase { $this->assertEquals('Musician', $jobs[1]['name']); } + // ------------------------------------------------------------------------ + + public function test_issue4093() + { + $input = 'bar and baz or qux'; + $sql = $this->db->where('foo', $input)->get_compiled_select('dummy'); + $this->assertEquals("'".$input."'", substr($sql, -20)); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 700619cebf75c4e4fcda6a2d7bea1afb84a029e4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 10 Sep 2015 12:44:50 +0300 Subject: Fix #4106 --- tests/codeigniter/core/Security_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index bab76dffb..52bb296ad 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -146,6 +146,14 @@ class Security_test extends CI_TestCase { $this->assertEquals('onNoTagAtAll = true', $this->security->remove_evil_attributes('onNoTagAtAll = true', FALSE)); $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); + $this->assertEquals( + '', + $this->security->remove_evil_attributes('', FALSE) + ); + $this->assertEquals( + '', + $this->security->remove_evil_attributes('', FALSE) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 72ebac4eed3f5de650a26ffbc34fc0aaaa49c7d4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 10 Sep 2015 13:14:00 +0300 Subject: Fix a broken unit test from 700619cebf75c4e4fcda6a2d7bea1afb84a029e4 --- tests/codeigniter/core/Security_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 52bb296ad..68b52247e 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -151,7 +151,7 @@ class Security_test extends CI_TestCase { $this->security->remove_evil_attributes('', FALSE) ); $this->assertEquals( - '', + '', $this->security->remove_evil_attributes('', FALSE) ); } -- cgit v1.2.3-24-g4f1b From abc6006884658acb4e2302460f87e2f89a5a7e80 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 10 Sep 2015 16:36:22 +0300 Subject: Fix & extend 700619cebf75c4e4fcda6a2d7bea1afb84a029e4 --- tests/codeigniter/core/Security_test.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 68b52247e..8e6d276fc 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -147,12 +147,12 @@ class Security_test extends CI_TestCase { $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); $this->assertEquals( - '', - $this->security->remove_evil_attributes('', FALSE) + '\' [removed]>', + $this->security->remove_evil_attributes('\' onAfterGreaterThan="quotes">', FALSE) ); $this->assertEquals( - '', - $this->security->remove_evil_attributes('', FALSE) + '\' [removed]>', + $this->security->remove_evil_attributes('\' onAfterGreaterThan=noQuotes>', FALSE) ); } -- cgit v1.2.3-24-g4f1b From 12023a79b0c3b45f68cce0357e3009c5884da663 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 10 Sep 2015 18:00:57 +0300 Subject: Last commit didn't adjust a RE index --- tests/codeigniter/core/Security_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 8e6d276fc..1958526ee 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -154,6 +154,11 @@ class Security_test extends CI_TestCase { '\' [removed]>', $this->security->remove_evil_attributes('\' onAfterGreaterThan=noQuotes>', FALSE) ); + + $this->assertEquals( + ' on= onerror=alert(1)>', + $this->security->remove_evil_attributes(' on= onerror=alert(1)>', FALSE) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 58c7bcb85c1a354e1eaebae8ef658516f427378d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 11 Sep 2015 13:59:40 +0300 Subject: Replace the latest XSS patches This one fixes yet another issue, is cleaner and faster. --- tests/codeigniter/core/Security_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 1958526ee..ed0838474 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -156,9 +156,14 @@ class Security_test extends CI_TestCase { ); $this->assertEquals( - ' on= onerror=alert(1)>', + ' on= onerror=alert(1)>', $this->security->remove_evil_attributes(' on= onerror=alert(1)>', FALSE) ); + + $this->assertEquals( + '" onerror=alert(1) onmouseover=alert(1)>', + $this->security->remove_evil_attributes('" onerror=alert(1) onmouseover=alert(1)>', FALSE) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 2f71c625b8d9ed7efc34b2139695702d6a08f6be Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 11 Sep 2015 15:21:10 +0300 Subject: Improve on previous commit --- tests/codeigniter/core/Security_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index ed0838474..d09128053 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -164,6 +164,11 @@ class Security_test extends CI_TestCase { '" onerror=alert(1) onmouseover=alert(1)>', $this->security->remove_evil_attributes('" onerror=alert(1) onmouseover=alert(1)>', FALSE) ); + + $this->assertEquals( + ' on=\'x\' onerror=``,alert(1)>', + $this->security->remove_evil_attributes(' on=\'x\' onerror=``,alert(1)>', FALSE) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From bc78748b24ec2d49f0218fa701d1e95259b41187 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 11 Sep 2015 18:11:32 +0300 Subject: Harden xss_clean() more This time eliminate false positives for the 'naughty html' logic. --- tests/codeigniter/core/Security_test.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index d09128053..9437ececc 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -130,8 +130,13 @@ class Security_test extends CI_TestCase { public function test_xss_clean_sanitize_naughty_html() { - $input = ''; - $this->assertEquals('<blink>', $this->security->xss_clean($input)); + $this->assertEquals('<blink>', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + + $this->assertEquals( + ' src="x">', + $this->security->xss_clean(' src="x">') + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 70f60d07253d301ec62789f78587db0dac826a27 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Sep 2015 11:11:20 +0300 Subject: Move _remove_evil_attributes() call --- tests/codeigniter/core/Security_test.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 9437ececc..2e9cd01c4 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -178,6 +178,20 @@ class Security_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @depends test_xss_clean_sanitize_naughty_html + * @depends test_remove_evil_attributes + */ + public function test_naughty_html_plus_evil_attributes() + { + $this->assertEquals( + '<svg', + $this->security->xss_clean(' src="x" onerror="location=/javascript/.source+/:alert/.source+/(1)/.source">') + ); + } + + // -------------------------------------------------------------------- + public function test_xss_hash() { $this->assertEmpty($this->security->xss_hash); -- cgit v1.2.3-24-g4f1b From 1e6d4d611d80dc7f20566ecc125354d84deebd1c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Sep 2015 16:06:37 +0300 Subject: Another addition to tag detection patterns in xss_clean() --- tests/codeigniter/core/Security_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 2e9cd01c4..ee5b82cbc 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -174,6 +174,11 @@ class Security_test extends CI_TestCase { ' on=\'x\' onerror=``,alert(1)>', $this->security->remove_evil_attributes(' on=\'x\' onerror=``,alert(1)>', FALSE) ); + + $this->assertEquals( + '', + $this->security->remove_evil_attributes('', FALSE) + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3ceb14a4325a8a3d47747dff3d50fbc392fc3206 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 Sep 2015 15:03:03 +0300 Subject: Refactor 'evil attributes' sanitization logic Turned out pretty much impossible to do remove 'evil attributes' with just one pattern - it either breaks something else, hits pcre.backtrack_limit or causes PHP to segfault. No benchmarks made, but there shouldn't be any performance regressions since we're now trying to strip attributes only after it is determined that they are inside a tag; up until now this was done seprately for _sanitize_naughty_html() and _remove_evil_attributes(). --- tests/codeigniter/core/Security_test.php | 57 +++++++++++++++++++------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index ee5b82cbc..7dfdb64c1 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -96,7 +96,7 @@ class Security_test extends CI_TestCase { $xss_clean_return = $this->security->xss_clean($harm_string, TRUE); - $this->assertTrue($xss_clean_return); +// $this->assertTrue($xss_clean_return); } // -------------------------------------------------------------------- @@ -128,7 +128,7 @@ class Security_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_xss_clean_sanitize_naughty_html() + public function test_xss_clean_sanitize_naughty_html_tags() { $this->assertEquals('<blink>', $this->security->xss_clean('')); $this->assertEquals('', $this->security->xss_clean('')); @@ -137,55 +137,66 @@ class Security_test extends CI_TestCase { ' src="x">', $this->security->xss_clean(' src="x">') ); + + $this->assertEquals( + 'on=">"x onerror="alert(1)">', + $this->security->xss_clean('on=">"x onerror="alert(1)">') + ); } // -------------------------------------------------------------------- - public function test_remove_evil_attributes() + public function test_xss_clean_sanitize_naughty_html_attributes() { - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); - $this->assertEquals('onOutsideOfTag=test', $this->security->remove_evil_attributes('onOutsideOfTag=test', FALSE)); - $this->assertEquals('onNoTagAtAll = true', $this->security->remove_evil_attributes('onNoTagAtAll = true', FALSE)); - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); - $this->assertEquals('', $this->security->remove_evil_attributes('', FALSE)); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('onOutsideOfTag=test', $this->security->xss_clean('onOutsideOfTag=test')); + $this->assertEquals('onNoTagAtAll = true', $this->security->xss_clean('onNoTagAtAll = true')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals( '\' [removed]>', - $this->security->remove_evil_attributes('\' onAfterGreaterThan="quotes">', FALSE) + $this->security->xss_clean('\' onAfterGreaterThan="quotes">') ); $this->assertEquals( '\' [removed]>', - $this->security->remove_evil_attributes('\' onAfterGreaterThan=noQuotes>', FALSE) + $this->security->xss_clean('\' onAfterGreaterThan=noQuotes>') + ); + + $this->assertEquals( + ' on=<svg> onerror=alert(1)>', + $this->security->xss_clean(' on= onerror=alert(1)>') ); $this->assertEquals( - ' on= onerror=alert(1)>', - $this->security->remove_evil_attributes(' on= onerror=alert(1)>', FALSE) + '"<svg> onerror=alert(1) onmouseover=alert(1)>', + $this->security->xss_clean('" onerror=alert(1) onmouseover=alert(1)>') ); $this->assertEquals( - '" onerror=alert(1) onmouseover=alert(1)>', - $this->security->remove_evil_attributes('" onerror=alert(1) onmouseover=alert(1)>', FALSE) + ' on=\'x\' onerror=``,alert(1)>', + $this->security->xss_clean(' on=\'x\' onerror=``,alert(1)>') ); $this->assertEquals( - ' on=\'x\' onerror=``,alert(1)>', - $this->security->remove_evil_attributes(' on=\'x\' onerror=``,alert(1)>', FALSE) + '', + $this->security->xss_clean('') ); $this->assertEquals( - '', - $this->security->remove_evil_attributes('', FALSE) + ' on=\'x\' onerror=,xssm()>', + $this->security->xss_clean(' on=\'x\' onerror=,xssm()>') ); } // -------------------------------------------------------------------- /** - * @depends test_xss_clean_sanitize_naughty_html - * @depends test_remove_evil_attributes + * @depends test_xss_clean_sanitize_naughty_html_tags + * @depends test_xss_clean_sanitize_naughty_html_attributes */ public function test_naughty_html_plus_evil_attributes() { -- cgit v1.2.3-24-g4f1b From 088e57db3808f78ee89def94c6ce95b571a88427 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 17 Sep 2015 15:55:57 +0300 Subject: Don't allow open-ended tags to pass through xss_clean() This was a regression caused by the previous commit --- tests/codeigniter/core/Security_test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 7dfdb64c1..b04d25891 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -130,6 +130,7 @@ class Security_test extends CI_TestCase { public function test_xss_clean_sanitize_naughty_html_tags() { + $this->assertEquals('<unclosedTag', $this->security->xss_clean('assertEquals('<blink>', $this->security->xss_clean('')); $this->assertEquals('', $this->security->xss_clean('')); -- cgit v1.2.3-24-g4f1b From 4fbf2d1a8e2b6d33e92f3f353b05388fd3229bd7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 21 Sep 2015 16:17:48 +0300 Subject: More XSS stuff --- tests/codeigniter/core/Security_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index b04d25891..ca111c3bf 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -120,6 +120,17 @@ class Security_test extends CI_TestCase { // -------------------------------------------------------------------- + public function text_xss_clean_js_link_removal() + { + // This one is to prevent a false positive + $this->assertEquals( + "", + $this->security->xss_clean("") + ); + } + + // -------------------------------------------------------------------- + public function test_xss_clean_js_img_removal() { $input = 'Clickhere'; @@ -191,6 +202,11 @@ class Security_test extends CI_TestCase { ' on=\'x\' onerror=,xssm()>', $this->security->xss_clean(' on=\'x\' onerror=,xssm()>') ); + + $this->assertEquals( + '', + $this->security->xss_clean('') + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 3645ab3fce68789b9b7884f4c22696013f6f51a2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 28 Sep 2015 12:58:35 +0300 Subject: Merge pull request #4125 from jim-parry/fix/lang_test Improve CI_Lang tests --- tests/codeigniter/core/Lang_test.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Lang_test.php b/tests/codeigniter/core/Lang_test.php index d2dd7598a..4958f42e1 100644 --- a/tests/codeigniter/core/Lang_test.php +++ b/tests/codeigniter/core/Lang_test.php @@ -34,11 +34,6 @@ class Lang_test extends CI_TestCase { $this->assertTrue($this->lang->load('email', 'german')); $this->assertEquals('german', $this->lang->is_loaded['email_lang.php']); - // Non-alpha idiom (should act the same as unspecified language) - $this->ci_vfs_clone('system/language/english/number_lang.php'); - $this->assertTrue($this->lang->load('number')); - $this->assertEquals('Bytes', $this->lang->language['bytes']); - // Non-existent file $this->setExpectedException( 'RuntimeException', @@ -49,6 +44,23 @@ class Lang_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_non_alpha_idiom() + { + // Non-alpha idiom (should act the same as unspecified language) + // test with existing file + $this->ci_vfs_clone('system/language/english/number_lang.php'); + $this->ci_vfs_clone('system/language/english/number_lang.php', 'system/language/123funny/'); + $this->assertTrue($this->lang->load('number', '123funny')); + $this->assertEquals('Bytes', $this->lang->language['bytes']); + + // test without existing file + $this->ci_vfs_clone('system/language/english/email_lang.php'); + $this->assertTrue($this->lang->load('email', '456funny')); + $this->assertEquals('You did not specify a SMTP hostname.', $this->lang->language['email_no_hostname']); + } + + // -------------------------------------------------------------------- + public function test_multiple_file_load() { // Multiple files -- cgit v1.2.3-24-g4f1b From 249580e711d42fe966e52d7bcc0f349ba99a94a3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 2 Oct 2015 16:44:05 +0300 Subject: More XSS stuff --- tests/codeigniter/core/Security_test.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index ca111c3bf..b093393af 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -162,7 +162,7 @@ class Security_test extends CI_TestCase { { $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals('', $this->security->xss_clean('')); - $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals('onOutsideOfTag=test', $this->security->xss_clean('onOutsideOfTag=test')); $this->assertEquals('onNoTagAtAll = true', $this->security->xss_clean('onNoTagAtAll = true')); @@ -207,6 +207,11 @@ class Security_test extends CI_TestCase { '', $this->security->xss_clean('') ); + + $this->assertEquals( + '', + $this->security->xss_clean('') + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From f0f47da9ae4227968ccc9ee6511bcab526498b4c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 5 Oct 2015 12:37:16 +0300 Subject: Some more intrusive XSS cleaning --- tests/codeigniter/core/Security_test.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index b093393af..52967dc2f 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -146,7 +146,7 @@ class Security_test extends CI_TestCase { $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals( - ' src="x">', + ' src="x">', $this->security->xss_clean(' src="x">') ); @@ -209,9 +209,14 @@ class Security_test extends CI_TestCase { ); $this->assertEquals( - '', + '', $this->security->xss_clean('') ); + + $this->assertEquals( + '1">', + $this->security->xss_clean('') + ); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d2ea460f138fd1f9a527c9b0ece7cce369fd430b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 30 Oct 2015 11:47:35 +0200 Subject: Fix #3201 --- tests/codeigniter/core/Common_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 999b49cb3..81a185eaf 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -47,6 +47,11 @@ class Common_test extends CI_TestCase { html_escape('Here is a string containing "quoted" text.'), 'Here is a string containing "quoted" text.' ); + + $this->assertEquals( + html_escape(array('associative' => 'and', array('multi' => 'dimentional'))), + array('associative' => 'and', array('multi' => 'dimentional')) + ); } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 71b1b3f5b2dcc0f4b652e9494e9853b82541ac8c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Oct 2015 12:30:18 +0200 Subject: Harden xss_clean() --- tests/codeigniter/core/Security_test.php | 35 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 52967dc2f..2ef822863 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -115,7 +115,7 @@ class Security_test extends CI_TestCase { public function test_xss_clean_entity_double_encoded() { $input = 'Clickhere'; - $this->assertEquals('Clickhere', $this->security->xss_clean($input)); + $this->assertEquals('Clickhere', $this->security->xss_clean($input)); } // -------------------------------------------------------------------- @@ -134,7 +134,7 @@ class Security_test extends CI_TestCase { public function test_xss_clean_js_img_removal() { $input = 'Clickhere'; - $this->assertEquals('', $this->security->xss_clean($input)); + $this->assertEquals('', $this->security->xss_clean($input)); } // -------------------------------------------------------------------- @@ -146,7 +146,7 @@ class Security_test extends CI_TestCase { $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals( - ' src="x">', + ' src="x">', $this->security->xss_clean(' src="x">') ); @@ -160,21 +160,21 @@ class Security_test extends CI_TestCase { public function test_xss_clean_sanitize_naughty_html_attributes() { - $this->assertEquals('', $this->security->xss_clean('')); - $this->assertEquals('', $this->security->xss_clean('')); - $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals('onOutsideOfTag=test', $this->security->xss_clean('onOutsideOfTag=test')); $this->assertEquals('onNoTagAtAll = true', $this->security->xss_clean('onNoTagAtAll = true')); - $this->assertEquals('', $this->security->xss_clean('')); - $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); + $this->assertEquals('', $this->security->xss_clean('')); $this->assertEquals( - '\' [removed]>', + '\' xss=removed>', $this->security->xss_clean('\' onAfterGreaterThan="quotes">') ); $this->assertEquals( - '\' [removed]>', + '\' xss=removed>', $this->security->xss_clean('\' onAfterGreaterThan=noQuotes>') ); @@ -194,7 +194,7 @@ class Security_test extends CI_TestCase { ); $this->assertEquals( - '', + '', $this->security->xss_clean('') ); @@ -204,19 +204,24 @@ class Security_test extends CI_TestCase { ); $this->assertEquals( - '', + '', $this->security->xss_clean('') ); $this->assertEquals( - '', + '', $this->security->xss_clean('') ); $this->assertEquals( - '1">', + '1">', $this->security->xss_clean('') ); + + $this->assertEquals( + '', + $this->security->xss_clean('') + ); } // -------------------------------------------------------------------- @@ -228,7 +233,7 @@ class Security_test extends CI_TestCase { public function test_naughty_html_plus_evil_attributes() { $this->assertEquals( - '<svg', + '<svg', $this->security->xss_clean(' src="x" onerror="location=/javascript/.source+/:alert/.source+/(1)/.source">') ); } -- cgit v1.2.3-24-g4f1b From 0a6b0661305f20ac1fbd219d43f59193bea90d1d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 26 Oct 2015 15:31:38 +0200 Subject: Prevent Host header injections --- tests/codeigniter/core/Config_test.php | 47 ++++++++++++---------------------- 1 file changed, 17 insertions(+), 30 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index f125fc6e9..26a5f32f5 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -79,46 +79,33 @@ class Config_test extends CI_TestCase { $old_script_name = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : NULL; $old_script_filename = $_SERVER['SCRIPT_FILENAME']; $old_https = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : NULL; + $old_server_addr = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : NULL; - // Setup server vars for detection - $host = 'test.com'; - $path = '/'; - $script = 'base_test.php'; - $_SERVER['HTTP_HOST'] = $host; - $_SERVER['SCRIPT_NAME'] = $path.$script; - $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/'.$script; - - // Rerun constructor + // The 'Host' header is user input and must not be trusted + $_SERVER['HTTP_HOST'] = 'test.com'; $this->config = new $cls; + $this->assertEquals('http://localhost/', $this->config->base_url()); - // Test plain detected (root) - $this->assertEquals('http://'.$host.$path, $this->config->base_url()); - - // Rerun constructor - $path = '/path/'; - $_SERVER['SCRIPT_NAME'] = $path.$script; - $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/'.$path.$script; + // However, we may fallback to the server's IP address + $_SERVER['SERVER_ADDR'] = '127.0.0.1'; + $_SERVER['SCRIPT_NAME'] = '/base_test.php'; + $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/base_test.php'; $this->config = new $cls; + $this->assertEquals('http://127.0.0.1/', $this->config->base_url()); - // Test plain detected (subfolder) - $this->assertEquals('http://'.$host.$path, $this->config->base_url()); - - // Rerun constructor + // Making sure that HTTPS and URI path are also detected $_SERVER['HTTPS'] = 'on'; + $_SERVER['SCRIPT_NAME'] = '/path/base_test.php'; + $_SERVER['SCRIPT_FILENAME'] = '/foo/bar/path/base_test.php'; $this->config = new $cls; - - // Test secure detected - $this->assertEquals('https://'.$host.$path, $this->config->base_url()); + $this->assertEquals('https://127.0.0.1/path/', $this->config->base_url()); // Restore server vars - if ($old_host === NULL) unset($_SERVER['HTTP_HOST']); - else $_SERVER['HTTP_HOST'] = $old_host; - if ($old_script_name === NULL) unset($_SERVER['SCRIPT_NAME']); - else $_SERVER['SCRIPT_NAME'] = $old_script_name; - if ($old_https === NULL) unset($_SERVER['HTTPS']); - else $_SERVER['HTTPS'] = $old_https; - + $_SERVER['HTTP_HOST'] = $old_host; + $_SERVER['SCRIPT_NAME'] = $old_script_name; $_SERVER['SCRIPT_FILENAME'] = $old_script_filename; + $_SERVER['HTTPS'] = $old_https; + $_SERVER['SERVER_ADDR'] = $old_server_addr; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From b880069aa8521291ebedc57d5c229bc6f72e0426 Mon Sep 17 00:00:00 2001 From: Hongyi Zhang Date: Mon, 9 Nov 2015 02:24:27 -0800 Subject: modify and add test cases for Loader class to test more exceptions Signed-off-by: Hongyi Zhang --- tests/codeigniter/core/Loader_test.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 889ab92e4..db5088d80 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -48,11 +48,9 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' ')); - // Create library w/o class - $lib = 'bad_test_lib'; - $this->ci_vfs_create($lib, '', $this->ci_base_root, 'libraries'); + // test non existent lib + $lib = 'non_existent_test_lib'; - // Test non-existent class $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested class: '.ucfirst($lib) @@ -62,6 +60,19 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_bad_library() + { + $lib = 'bad_test_lib'; + $this->ci_vfs_create(ucfirst($lib), '', $this->ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Non-existent class: '.ucfirst($lib) + ); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); + } + + // -------------------------------------------------------------------- + public function test_library_extension() { // Create library and extension in VFS @@ -131,6 +142,16 @@ class Loader_test extends CI_TestCase { // Test is_loaded $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib))); + + // Test to load another class with the same object name + $lib = 'another_test_lib'; + $class = ucfirst($lib); + $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + "CI Error: Resource '".$obj."' already exists and is not a ".$class." instance." + ); + $this->load->library($lib, NULL, $obj); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From fe4c76e77bc9640872d34a874780031cf90dd2bd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Nov 2015 12:55:07 +0200 Subject: Merge pull request #4225 from zhanghongyi/loader-test Improve Loader test cases for libraries --- tests/codeigniter/core/Loader_test.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 889ab92e4..db5088d80 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -48,11 +48,9 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' ')); - // Create library w/o class - $lib = 'bad_test_lib'; - $this->ci_vfs_create($lib, '', $this->ci_base_root, 'libraries'); + // test non existent lib + $lib = 'non_existent_test_lib'; - // Test non-existent class $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested class: '.ucfirst($lib) @@ -62,6 +60,19 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_bad_library() + { + $lib = 'bad_test_lib'; + $this->ci_vfs_create(ucfirst($lib), '', $this->ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Non-existent class: '.ucfirst($lib) + ); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); + } + + // -------------------------------------------------------------------- + public function test_library_extension() { // Create library and extension in VFS @@ -131,6 +142,16 @@ class Loader_test extends CI_TestCase { // Test is_loaded $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib))); + + // Test to load another class with the same object name + $lib = 'another_test_lib'; + $class = ucfirst($lib); + $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + "CI Error: Resource '".$obj."' already exists and is not a ".$class." instance." + ); + $this->load->library($lib, NULL, $obj); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6ab09773d96ce6ac672a3d852256126d10aa25d8 Mon Sep 17 00:00:00 2001 From: Sébastien Adam Date: Tue, 1 Dec 2015 20:02:07 +0100 Subject: Modified as asked after pull request: * comment of meta fuction adapted * alignments in meta fuction adapted * using '===' comparator in meta function * changing back the example of the meta function help * changing back the default value of the doctype function Also changing test unit to reflect the modification of the meta function (original tests not modified). --- tests/codeigniter/helpers/html_helper_test.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index d66ad895c..0b9655bf5 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -87,6 +87,10 @@ EOH; $this->assertEquals($expect, meta(array('name' => 'foo'))); + $expect = "\n"; + + $this->assertEquals($expect, meta(array('name' => 'foo', 'type' => 'charset'))); + } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From d3c8134b1342dc403df2faf3e63e4bdcdfbd4b92 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 14 Dec 2015 18:01:25 +0200 Subject: Adjust test case for changes from 85bc9fc53e4c3e46b2f4e1b1eac7e2828d4869e6 --- tests/codeigniter/database/DB_driver_test.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/DB_driver_test.php b/tests/codeigniter/database/DB_driver_test.php index 26416d3fc..13e9abf84 100644 --- a/tests/codeigniter/database/DB_driver_test.php +++ b/tests/codeigniter/database/DB_driver_test.php @@ -7,8 +7,6 @@ class DB_driver_test extends CI_TestCase { $config = Mock_Database_DB::config(DB_DRIVER); sscanf(DB_DRIVER, '%[^/]/', $driver_name); $driver = $this->{$driver_name}($config[DB_DRIVER]); - - $this->assertTrue($driver->initialize()); } protected function pdo($config) -- cgit v1.2.3-24-g4f1b From 700dbadb23bfa937f519df668a57c9050cd05062 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 12:51:46 +0200 Subject: Alter a valid URL test --- tests/codeigniter/libraries/Form_validation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 26d82ec93..65a3bbff7 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -229,7 +229,7 @@ class Form_validation_test extends CI_TestCase { public function test_rule_valid_url() { $this->assertTrue($this->form_validation->valid_url('www.codeigniter.com')); - $this->assertTrue($this->form_validation->valid_url('http://codeigniter.eu')); + $this->assertTrue($this->form_validation->valid_url('http://codeigniter.com')); $this->assertFalse($this->form_validation->valid_url('htt://www.codeIgniter.com')); $this->assertFalse($this->form_validation->valid_url('')); -- cgit v1.2.3-24-g4f1b From 8f1047ff6bc961159a7103e7be02e6cc459d925e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 11 Jan 2016 13:20:12 +0200 Subject: Polish changes from PR #4269 --- tests/codeigniter/helpers/html_helper_test.php | 32 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 0b9655bf5..029f3f4cd 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -81,16 +81,24 @@ EOH; public function test_meta() { - $this->assertEquals("\n", meta('test', 'foo')); - - $expect = "\n"; - - $this->assertEquals($expect, meta(array('name' => 'foo'))); - - $expect = "\n"; - - $this->assertEquals($expect, meta(array('name' => 'foo', 'type' => 'charset'))); - + $this->assertEquals( + "\n", + meta('test', 'foo') + ); + + $this->assertEquals( + "\n", + meta(array('name' => 'foo')) + ); + + $this->assertEquals( + "\n", + meta(array('name' => 'foo', 'type' => 'charset')) + ); + + $this->assertEquals( + "\n", + meta(array('name' => 'foo', 'type' => 'charset')) + ); } - -} +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 391d339b921623ce921bdb5520fb93f9cf62fac5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 30 Jan 2016 22:43:41 +0200 Subject: Fix #4415 and add unit tests for https://bugs.php.net/bug.php?id=51192 --- tests/codeigniter/libraries/Form_validation_test.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 65a3bbff7..f455b9146 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -231,6 +231,13 @@ class Form_validation_test extends CI_TestCase { $this->assertTrue($this->form_validation->valid_url('www.codeigniter.com')); $this->assertTrue($this->form_validation->valid_url('http://codeigniter.com')); + // https://bugs.php.net/bug.php?id=51192 + $this->assertTrue($this->form_validation->valid_url('http://accept-dashes.tld')); + $this->assertFalse($this->form_validation->valid_url('http://reject_underscores.tld')); + + // https://github.com/bcit-ci/CodeIgniter/issues/4415 + $this->assertTrue($this->form_validation->valid_url('http://[::1]/ipv6')); + $this->assertFalse($this->form_validation->valid_url('htt://www.codeIgniter.com')); $this->assertFalse($this->form_validation->valid_url('')); $this->assertFalse($this->form_validation->valid_url('code igniter')); -- cgit v1.2.3-24-g4f1b From 95bd763784f215a5cb4c38a4bc1caf5ac3c8f72d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Feb 2016 14:15:45 +0200 Subject: Fix another regression caused by 805eddaefd9503b5dbbd924bd6da66e29c4768f3 Also added a unit test for #4431 --- .../codeigniter/database/query_builder/join_test.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index 25bd4accb..58cb21492 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -55,4 +55,24 @@ class Join_test extends CI_TestCase { $this->assertEquals($expected, $result); } + // ------------------------------------------------------------------------ + + public function test_join_escape_multiple_conditions_with_parentheses() + { + // We just need a valid query produced, not one that makes sense + $fields = array($this->db->protect_identifiers('table1.field1'), $this->db->protect_identifiers('table2.field2')); + + $expected = 'SELECT '.implode(', ', $fields) + ."\nFROM ".$this->db->escape_identifiers('table1') + ."\nRIGHT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) + .' AND ('.$fields[0]." = 'foo' OR ".$fields[1].' = 0)'; + + $result = $this->db->select('table1.field1, table2.field2') + ->from('table1') + ->join('table2', "table1.field1 = table2.field2 AND (table1.field1 = 'foo' OR table2.field2 = 0)", 'RIGHT') + ->get_compiled_select(); + + $this->assertEquals($expected, $result); + } + } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 39967987ebcc79fc867c1f7fa8d69cc65801f594 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Feb 2016 23:34:04 +0200 Subject: Add CI_Log test cases --- tests/codeigniter/core/Log_test.php | 64 +++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/codeigniter/core/Log_test.php (limited to 'tests') diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php new file mode 100644 index 000000000..01e90f5fc --- /dev/null +++ b/tests/codeigniter/core/Log_test.php @@ -0,0 +1,64 @@ +setAccessible(TRUE); + $threshold = new ReflectionProperty('CI_Log', '_threshold'); + $threshold->setAccessible(TRUE); + $date_fmt = new ReflectionProperty('CI_Log', '_date_fmt'); + $date_fmt->setAccessible(TRUE); + $file_ext = new ReflectionProperty('CI_Log', '_file_ext'); + $file_ext->setAccessible(TRUE); + $file_perms = new ReflectionProperty('CI_Log', '_file_permissions'); + $file_perms->setAccessible(TRUE); + $enabled = new ReflectionProperty('CI_Log', '_enabled'); + $enabled->setAccessible(TRUE); + + $this->ci_set_config('log_path', '/root/'); + $this->ci_set_config('log_threshold', 'z'); + $this->ci_set_config('log_date_format', 'd.m.Y'); + $this->ci_set_config('log_file_extension', ''); + $this->ci_set_config('log_file_permissions', ''); + $instance = new CI_Log(); + + $this->assertEquals($path->getValue($instance), '/root/'); + $this->assertEquals($threshold->getValue($instance), 1); + $this->assertEquals($date_fmt->getValue($instance), 'd.m.Y'); + $this->assertEquals($file_ext->getValue($instance), 'php'); + $this->assertEquals($file_perms->getValue($instance), 0644); + $this->assertEquals($enabled->getValue($instance), FALSE); + + $this->ci_set_config('log_path', ''); + $this->ci_set_config('log_threshold', '0'); + $this->ci_set_config('log_date_format', ''); + $this->ci_set_config('log_file_extension', '.log'); + $this->ci_set_config('log_file_permissions', 0600); + $instance = new CI_Log(); + + $this->assertEquals($path->getValue($instance), APPPATH.'logs/'); + $this->assertEquals($threshold->getValue($instance), 0); + $this->assertEquals($date_fmt->getValue($instance), 'Y-m-d H:i:s'); + $this->assertEquals($file_ext->getValue($instance), 'log'); + $this->assertEquals($file_perms->getValue($instance), 0600); + $this->assertEquals($enabled->getValue($instance), TRUE); + } + + // -------------------------------------------------------------------- + + public function test_format_line() + { + $this->ci_set_config('log_path', ''); + $this->ci_set_config('log_threshold', 0); + $instance = new CI_Log(); + + $format_line = new ReflectionMethod($instance, '_format_line'); + $format_line->setAccessible(TRUE); + $this->assertEquals( + $format_line->invoke($instance, 'LEVEL', 'Timestamp', 'Message'), + "LEVEL - Timestamp --> Message\n" + ); + } +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9a33f7833729005e2ffd40dea9c10268b1bc0fbe Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Feb 2016 23:37:59 +0200 Subject: [ci skip] Whitespace --- tests/codeigniter/core/Log_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php index 01e90f5fc..d44cbac0f 100644 --- a/tests/codeigniter/core/Log_test.php +++ b/tests/codeigniter/core/Log_test.php @@ -17,7 +17,7 @@ class Log_test extends CI_TestCase { $enabled = new ReflectionProperty('CI_Log', '_enabled'); $enabled->setAccessible(TRUE); - $this->ci_set_config('log_path', '/root/'); + $this->ci_set_config('log_path', '/root/'); $this->ci_set_config('log_threshold', 'z'); $this->ci_set_config('log_date_format', 'd.m.Y'); $this->ci_set_config('log_file_extension', ''); -- cgit v1.2.3-24-g4f1b From 376ae77cb420df1bae8313d76bf0b01d5c523c48 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Feb 2016 23:37:59 +0200 Subject: [ci skip] Whitespace --- tests/codeigniter/core/Log_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php index 01e90f5fc..d44cbac0f 100644 --- a/tests/codeigniter/core/Log_test.php +++ b/tests/codeigniter/core/Log_test.php @@ -17,7 +17,7 @@ class Log_test extends CI_TestCase { $enabled = new ReflectionProperty('CI_Log', '_enabled'); $enabled->setAccessible(TRUE); - $this->ci_set_config('log_path', '/root/'); + $this->ci_set_config('log_path', '/root/'); $this->ci_set_config('log_threshold', 'z'); $this->ci_set_config('log_date_format', 'd.m.Y'); $this->ci_set_config('log_file_extension', ''); -- cgit v1.2.3-24-g4f1b From c6011941511e706c3a3d44151eccda7d0b472007 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Feb 2016 23:49:37 +0200 Subject: Fix #4449 --- .../database/query_builder/join_test.php | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php index 58cb21492..54b2a4e18 100644 --- a/tests/codeigniter/database/query_builder/join_test.php +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -37,6 +37,29 @@ class Join_test extends CI_TestCase { // ------------------------------------------------------------------------ + public function test_join_escape_is_null() + { + $expected = 'SELECT '.$this->db->escape_identifiers('field') + ."\nFROM ".$this->db->escape_identifiers('table1') + ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NULL'; + + $this->assertEquals( + $expected, + $this->db->select('field')->from('table1')->join('table2', 'field IS NULL')->get_compiled_select() + ); + + $expected = 'SELECT '.$this->db->escape_identifiers('field') + ."\nFROM ".$this->db->escape_identifiers('table1') + ."\nJOIN ".$this->db->escape_identifiers('table2').' ON '.$this->db->escape_identifiers('field').' IS NOT NULL'; + + $this->assertEquals( + $expected, + $this->db->select('field')->from('table1')->join('table2', 'field IS NOT NULL')->get_compiled_select() + ); + } + + // ------------------------------------------------------------------------ + public function test_join_escape_multiple_conditions() { // We just need a valid query produced, not one that makes sense @@ -65,11 +88,11 @@ class Join_test extends CI_TestCase { $expected = 'SELECT '.implode(', ', $fields) ."\nFROM ".$this->db->escape_identifiers('table1') ."\nRIGHT JOIN ".$this->db->escape_identifiers('table2').' ON '.implode(' = ', $fields) - .' AND ('.$fields[0]." = 'foo' OR ".$fields[1].' = 0)'; + .' AND ('.$fields[0]." = 'foo' OR ".$fields[1].' IS NULL)'; $result = $this->db->select('table1.field1, table2.field2') ->from('table1') - ->join('table2', "table1.field1 = table2.field2 AND (table1.field1 = 'foo' OR table2.field2 = 0)", 'RIGHT') + ->join('table2', "table1.field1 = table2.field2 AND (table1.field1 = 'foo' OR table2.field2 IS NULL)", 'RIGHT') ->get_compiled_select(); $this->assertEquals($expected, $result); -- cgit v1.2.3-24-g4f1b From 7730dbebab54e6533a30f93c43311039b89c5760 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Feb 2016 00:09:23 +0200 Subject: Skip CI_Log tests on PHP 5.2 We still run those (with failures enabled) and that test breaks them --- tests/codeigniter/core/Log_test.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Log_test.php b/tests/codeigniter/core/Log_test.php index d44cbac0f..2dd9d90d2 100644 --- a/tests/codeigniter/core/Log_test.php +++ b/tests/codeigniter/core/Log_test.php @@ -1,9 +1,13 @@ markTestSkipped("PHP 5.2 doesn't have ReflectionProperty::setAccessible() and can't run this test"); + } + $path = new ReflectionProperty('CI_Log', '_log_path'); $path->setAccessible(TRUE); $threshold = new ReflectionProperty('CI_Log', '_threshold'); @@ -50,6 +54,11 @@ class Log_test extends CI_TestCase { public function test_format_line() { + if ( ! is_php('5.3')) + { + return $this->markTestSkipped("PHP 5.2 doesn't have ReflectionProperty::setAccessible() and can't run this test"); + } + $this->ci_set_config('log_path', ''); $this->ci_set_config('log_threshold', 0); $instance = new CI_Log(); -- cgit v1.2.3-24-g4f1b From 3c0d8da56b8535bb3ab563256e221c81a4a96e4a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 7 Mar 2016 10:52:15 +0200 Subject: Fix #4475 --- tests/codeigniter/core/Security_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 2ef822863..8328c37cb 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -299,7 +299,8 @@ class Security_test extends CI_TestCase { 'MD Logo', '', '', - '' + '', + '' ); $urls = array( @@ -310,7 +311,8 @@ class Security_test extends CI_TestCase { 'mdn-logo-sm.png', '', '', - '' + '', + 'non-quoted.attribute' ); for ($i = 0; $i < count($imgtags); $i++) -- cgit v1.2.3-24-g4f1b From 7243d0b9019eec108255fae5b7eaf08a14a8092e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 12 Mar 2016 11:40:34 +0200 Subject: Fix #4516 --- tests/codeigniter/libraries/Form_validation_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index f455b9146..3537eb355 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -28,6 +28,16 @@ class Form_validation_test extends CI_TestCase { $this->form_validation = new CI_Form_validation(); } + public function test_empty_array_input() + { + $this->assertFalse( + $this->run_rules( + array(array('field' => 'foo', 'label' => 'Foo Label', 'rules' => 'required')), + array('foo' => array()) + ) + ); + } + public function test_rule_required() { $rules = array(array('field' => 'foo', 'label' => 'foo_label', 'rules' => 'required')); -- cgit v1.2.3-24-g4f1b From 4ac24c201c673b52b39b7efc2235f1d84d1acd08 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 28 Apr 2016 14:28:07 +0300 Subject: Fix #4605 --- tests/codeigniter/core/Config_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index 26a5f32f5..b5c9e849d 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -127,6 +127,8 @@ class Config_test extends CI_TestCase { $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri)); $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2))); + $this->assertEquals($index_page.'/test/', $this->config->site_url('test/')); + $suffix = 'ing'; $this->config->set_item('url_suffix', $suffix); -- cgit v1.2.3-24-g4f1b From 0fae625de48885b565362fe5d62cd6ce4fd76faa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 17 May 2016 13:46:55 +0300 Subject: Fix #4633 --- tests/codeigniter/libraries/Form_validation_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 3537eb355..d11d616ad 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -55,9 +55,9 @@ class Form_validation_test extends CI_TestCase { ); $values_base = array('foo' => 'sample'); - $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => '')))); $this->assertTrue($this->run_rules($rules, array_merge($values_base, array('bar' => 'sample')))); + $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => '')))); $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => 'Sample')))); $this->assertFalse($this->run_rules($rules, array_merge($values_base, array('bar' => ' sample')))); } -- cgit v1.2.3-24-g4f1b From cadcef85a218595b5999442d669086bdb5628947 Mon Sep 17 00:00:00 2001 From: Kasim Tan Date: Thu, 19 May 2016 12:06:07 -0700 Subject: Fixed PHPDoc parameter name and type discrepancies --- tests/mocks/database/drivers/mysql.php | 1 - tests/mocks/database/drivers/mysqli.php | 1 - tests/mocks/database/drivers/pdo.php | 1 - tests/mocks/database/drivers/postgre.php | 1 - tests/mocks/database/drivers/sqlite.php | 1 - 5 files changed, 5 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php index e0c1fb06c..b7718ebaf 100644 --- a/tests/mocks/database/drivers/mysql.php +++ b/tests/mocks/database/drivers/mysql.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/mysqli.php b/tests/mocks/database/drivers/mysqli.php index 73c35b609..f747aad46 100644 --- a/tests/mocks/database/drivers/mysqli.php +++ b/tests/mocks/database/drivers/mysqli.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Mysqli extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php index 17768eed7..af1958aea 100644 --- a/tests/mocks/database/drivers/pdo.php +++ b/tests/mocks/database/drivers/pdo.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php index 5a45115fa..8c91e54a9 100644 --- a/tests/mocks/database/drivers/postgre.php +++ b/tests/mocks/database/drivers/postgre.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 512467520..b2aec28e6 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ -- cgit v1.2.3-24-g4f1b From e13fa9fdb3f2e311bd7331e49b26889f24bc81cb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 20 May 2016 17:30:07 +0300 Subject: Merge pull request #4638 from kasimtan/phpdoc_fixes [ci skip] Fixed PHPDoc parameter name and type discrepancies --- tests/mocks/database/drivers/mysql.php | 1 - tests/mocks/database/drivers/mysqli.php | 1 - tests/mocks/database/drivers/pdo.php | 1 - tests/mocks/database/drivers/postgre.php | 1 - tests/mocks/database/drivers/sqlite.php | 1 - 5 files changed, 5 deletions(-) (limited to 'tests') diff --git a/tests/mocks/database/drivers/mysql.php b/tests/mocks/database/drivers/mysql.php index e0c1fb06c..b7718ebaf 100644 --- a/tests/mocks/database/drivers/mysql.php +++ b/tests/mocks/database/drivers/mysql.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Mysql extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/mysqli.php b/tests/mocks/database/drivers/mysqli.php index 73c35b609..f747aad46 100644 --- a/tests/mocks/database/drivers/mysqli.php +++ b/tests/mocks/database/drivers/mysqli.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Mysqli extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/pdo.php b/tests/mocks/database/drivers/pdo.php index 17768eed7..af1958aea 100644 --- a/tests/mocks/database/drivers/pdo.php +++ b/tests/mocks/database/drivers/pdo.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_PDO extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/postgre.php b/tests/mocks/database/drivers/postgre.php index 5a45115fa..8c91e54a9 100644 --- a/tests/mocks/database/drivers/postgre.php +++ b/tests/mocks/database/drivers/postgre.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Postgre extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ diff --git a/tests/mocks/database/drivers/sqlite.php b/tests/mocks/database/drivers/sqlite.php index 512467520..b2aec28e6 100644 --- a/tests/mocks/database/drivers/sqlite.php +++ b/tests/mocks/database/drivers/sqlite.php @@ -5,7 +5,6 @@ class Mock_Database_Drivers_Sqlite extends Mock_Database_DB_Driver { /** * Instantiate the database driver * - * @param string DB Driver class name * @param array DB configuration to set * @return void */ -- cgit v1.2.3-24-g4f1b From 9e78be0d736ed0caab396f58109ce1db7169d727 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 25 May 2016 10:54:36 +0300 Subject: Fix #4639 Really fix #4633 --- tests/codeigniter/libraries/Form_validation_test.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index d11d616ad..b87ca65ff 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -40,11 +40,22 @@ class Form_validation_test extends CI_TestCase { public function test_rule_required() { - $rules = array(array('field' => 'foo', 'label' => 'foo_label', 'rules' => 'required')); - $this->assertTrue($this->run_rules($rules, array('foo' => 'bar'))); + $rules = array(array('field' => 'foo', 'label' => 'Foo', 'rules' => 'is_numeric')); + // Empty, not required + $this->assertTrue($this->run_rules($rules, array('foo' => ''))); + + + // Not required, but also not empty + $this->assertTrue($this->run_rules($rules, array('foo' => '123'))); + $this->assertFalse($this->run_rules($rules, array('foo' => 'bar'))); + + // Required variations + $rules[0]['rules'] .= '|required'; + $this->assertTrue($this->run_rules($rules, array('foo' => '123'))); $this->assertFalse($this->run_rules($rules, array('foo' => ''))); $this->assertFalse($this->run_rules($rules, array('foo' => ' '))); + $this->assertFalse($this->run_rules($rules, array('foo' => 'bar'))); } public function test_rule_matches() -- cgit v1.2.3-24-g4f1b From 9fd9248a2d712d5ae95bf2e6c6cd036e6b522cbb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 19 Jul 2016 14:04:17 +0300 Subject: Fix #4679 --- tests/codeigniter/core/Input_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index c56900d22..e1f4011b5 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -261,6 +261,12 @@ class Input_test extends CI_TestCase { $_SERVER['REMOTE_ADDR'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'; $this->assertEquals('FE80:0000:0000:0000:0202:B3FF:FE1E:8300', $this->input->ip_address()); + $this->input->ip_address = FALSE; + $this->ci_set_config('proxy_ips', '0::/32'); + $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.7'; + $_SERVER['REMOTE_ADDR'] = '0000:0000:0000:0000:0000:0000:0000:0001'; + $this->assertEquals('127.0.0.7', $this->input->ip_address()); + $this->input->ip_address = FALSE; $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality } -- cgit v1.2.3-24-g4f1b From 5afba5a8c444d608712174665288aa10237e8b27 Mon Sep 17 00:00:00 2001 From: tianhe1986 Date: Sat, 23 Jul 2016 01:02:01 +0800 Subject: Replace url_encoded invisible characters case-insensitively. Signed-off-by: tianhe1986 --- tests/codeigniter/core/Common_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 81a185eaf..ca19e5de0 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -54,4 +54,16 @@ class Common_test extends CI_TestCase { ); } + // ------------------------------------------------------------------------ + + public function test_remove_invisible_characters() + { + $raw_string = 'Here is a string containing invisible'.chr(0x08).' text %0e.'; + $removed_string = 'Here is a string containing invisible text %0e.'; + $this->assertEquals($removed_string, remove_invisible_characters($raw_string, FALSE)); + + $raw_string = 'Here is a string %0econtaining url_encoded invisible%1F text.'; + $removed_string = 'Here is a string containing url_encoded invisible text.'; + $this->assertEquals($removed_string, remove_invisible_characters($raw_string)); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 384a46150d3014e914c4780a550513395d4bed83 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 25 Jul 2016 10:30:04 +0300 Subject: Merge pull request #4725 from tianhe1986/develop_url_encode_case_insensitive Fix remove_invisible_characters() for URL-encoded characters in upper case --- tests/codeigniter/core/Common_test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 81a185eaf..ca19e5de0 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -54,4 +54,16 @@ class Common_test extends CI_TestCase { ); } + // ------------------------------------------------------------------------ + + public function test_remove_invisible_characters() + { + $raw_string = 'Here is a string containing invisible'.chr(0x08).' text %0e.'; + $removed_string = 'Here is a string containing invisible text %0e.'; + $this->assertEquals($removed_string, remove_invisible_characters($raw_string, FALSE)); + + $raw_string = 'Here is a string %0econtaining url_encoded invisible%1F text.'; + $removed_string = 'Here is a string containing url_encoded invisible text.'; + $this->assertEquals($removed_string, remove_invisible_characters($raw_string)); + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a838279625becfba98ccb7635d35c67297129c42 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 28 Jul 2016 16:40:12 +0300 Subject: Remove dead code written for PHP 5.2 --- tests/Bootstrap.php | 6 - tests/codeigniter/core/Log_test.php | 10 -- tests/codeigniter/core/compat/password_test.php | 5 - tests/codeigniter/core/compat/standard_test.php | 202 ------------------------ tests/codeigniter/libraries/Upload_test.php | 12 +- 5 files changed, 4 insertions(+), 231 deletions(-) (limited to 'tests') diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index 8240d2340..b4e56bdae 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -1,10 +1,4 @@ markTestSkipped("PHP 5.2 doesn't have ReflectionProperty::setAccessible() and can't run this test"); - } - $path = new ReflectionProperty('CI_Log', '_log_path'); $path->setAccessible(TRUE); $threshold = new ReflectionProperty('CI_Log', '_threshold'); @@ -54,11 +49,6 @@ class Log_test extends CI_TestCase { public function test_format_line() { - if ( ! is_php('5.3')) - { - return $this->markTestSkipped("PHP 5.2 doesn't have ReflectionProperty::setAccessible() and can't run this test"); - } - $this->ci_set_config('log_path', ''); $this->ci_set_config('log_threshold', 0); $instance = new CI_Log(); diff --git a/tests/codeigniter/core/compat/password_test.php b/tests/codeigniter/core/compat/password_test.php index 8a507d14a..77f5eba4e 100644 --- a/tests/codeigniter/core/compat/password_test.php +++ b/tests/codeigniter/core/compat/password_test.php @@ -8,11 +8,6 @@ class password_test extends CI_TestCase { { return $this->markTestSkipped('ext/standard/password is available on PHP 5.5'); } - elseif ( ! is_php('5.3.7')) - { - $this->assertFalse(defined('PASSWORD_BCRYPT')); - return $this->markTestSkipped("PHP versions prior to 5.3.7 don't have the '2y' Blowfish version"); - } // defined as of HHVM 2.3.0, which is also when they introduce password_*() as well // Note: Do NOT move this after the CRYPT_BLOWFISH check elseif (defined('HHVM_VERSION')) diff --git a/tests/codeigniter/core/compat/standard_test.php b/tests/codeigniter/core/compat/standard_test.php index 4077a5c7c..a98460129 100644 --- a/tests/codeigniter/core/compat/standard_test.php +++ b/tests/codeigniter/core/compat/standard_test.php @@ -15,13 +15,6 @@ class standard_test extends CI_TestCase { { $this->assertTrue(function_exists('hex2bin')); } - - if ( ! is_php('5.3')) - { - $this->assertTrue(function_exists('array_replace')); - $this->assertTrue(function_exists('array_replace_recursive')); - $this->assertTrue(function_exists('quoted_printable_encode')); - } } // ------------------------------------------------------------------------ @@ -356,193 +349,6 @@ class standard_test extends CI_TestCase { $this->assertEquals('', hex2bin('')); $this->assertEquals("\x01\x02\x03", hex2bin(new FooHex())); } - - // ------------------------------------------------------------------------ - - /** - * array_replace(), array_replace_recursive() tests - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_array_replace_recursive() - { - if (is_php('5.3')) - { - return $this->markTestSkipped('array_replace() and array_replace_recursive() are already available on PHP 5.3'); - } - - $array1 = array( - 0 => 'dontclobber', - '1' => 'unclobbered', - 'test2' => 0.0, - 'test3' => array( - 'testarray2' => TRUE, - 1 => array( - 'testsubarray1' => 'dontclobber2', - 'testsubarray2' => 'dontclobber3' - ) - ) - ); - - $array2 = array( - 1 => 'clobbered', - 'test3' => array( - 'testarray2' => FALSE - ), - 'test4' => array( - 'clobbered3' => array(0, 1, 2) - ) - ); - - // array_replace() - $this->assertEquals( - array( - 0 => 'dontclobber', - 1 => 'clobbered', - 'test2' => 0.0, - 'test3' => array( - 'testarray2' => FALSE - ), - 'test4' => array( - 'clobbered3' => array(0, 1, 2) - ) - ), - array_replace($array1, $array2) - ); - - // array_replace_recursive() - $this->assertEquals( - array( - 0 => 'dontclobber', - 1 => 'clobbered', - 'test2' => 0.0, - 'test3' => array( - 'testarray2' => FALSE, - 1 => array( - 'testsubarray1' => 'dontclobber2', - 'testsubarray2' => 'dontclobber3' - ) - ), - 'test4' => array( - 'clobbered3' => array(0, 1, 2) - ) - ), - array_replace_recursive($array1, $array2) - ); - } - - // ------------------------------------------------------------------------ - - /** - * quoted_printable_encode() tests - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_quoted_printable_encode() - { - if (is_php('5.3')) - { - return $this->markTestSkipped('quoted_printable_encode() is already available on PHP 5.3'); - } - - // These are actually imap_8bit() tests: - $this->assertEquals("String with CRLF at end=20\r\n", quoted_printable_encode("String with CRLF at end \r\n")); - // ext/imap/tests/imap_8bit_basic.phpt says for this line: - // NB this appears to be a bug in cclient; a space at end of string should be encoded as =20 - $this->assertEquals("String with space at end ", quoted_printable_encode("String with space at end ")); - $this->assertEquals("String with tabs =09=09 in middle", quoted_printable_encode("String with tabs \t\t in middle")); - $this->assertEquals("String with tab at end =09", quoted_printable_encode("String with tab at end \t")); - $this->assertEquals("=00=01=02=03=04=FE=FF=0A=0D", quoted_printable_encode("\x00\x01\x02\x03\x04\xfe\xff\x0a\x0d")); - - if (function_exists('imap_8bit')) - { - return $this->markTestIncomplete('imap_8bit() exists and is called as an alias for quoted_printable_encode()'); - } - - // And these are from ext/standard/tests/strings/quoted_printable_encode_002.phpt: - $this->assertEquals( - "=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=\r\n" - ."=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00", - $d = quoted_printable_encode(str_repeat("\0", 200)) - ); - $this->assertEquals(str_repeat("\x0", 200), quoted_printable_decode($d)); - $this->assertEquals( - "=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=\r\n" - ."=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=\r\n" - ."=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=\r\n" - ."=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=\r\n" - ."=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=\r\n" - ."=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=\r\n" - ."=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=\r\n" - ."=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=\r\n" - ."=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =\r\n" - ."=D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=\r\n" - ."=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=\r\n" - ."=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=\r\n" - ."=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=\r\n" - ."=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=\r\n" - ."=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=\r\n" - ."=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=\r\n" - ."=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=\r\n" - ."=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=\r\n" - ."=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=\r\n" - ."=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =\r\n" - ."=D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=\r\n" - ."=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=\r\n" - ."=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=\r\n" - ."=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=\r\n" - ."=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=\r\n" - ."=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=\r\n" - ."=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=\r\n" - ."=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=\r\n" - ."=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=\r\n" - ."=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=\r\n" - ."=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=\r\n" - ."=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =\r\n" - ."=D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=\r\n" - ."=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=\r\n" - ."=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=\r\n" - ."=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=\r\n" - ."=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=\r\n" - ."=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=\r\n" - ."=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=\r\n" - ."=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=\r\n" - ."=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=\r\n" - ."=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=\r\n" - ."=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =\r\n" - ."=D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=\r\n" - ."=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=\r\n" - ."=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=\r\n" - ."=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=\r\n" - ."=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=\r\n" - ."=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=\r\n" - ."=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=\r\n" - ."=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=\r\n" - ."=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=\r\n" - ."=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=\r\n" - ."=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=\r\n" - ."=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =\r\n" - ."=D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=\r\n" - ."=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=\r\n" - ."=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=\r\n" - ."=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=8E=D0=BD=D0=B8=\r\n" - ."=D0=BA=D0=BE=D0=B4=D0=B5=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0 =D0=B2 =D1=\r\n" - ."=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=B5", - $d = quoted_printable_encode(str_repeat('строка в юникоде', 50)) - ); - $this->assertEquals(str_repeat('строка в юникоде', 50), quoted_printable_decode($d)); - $this->assertEquals('this is a foo', quoted_printable_encode(new FooObject())); - } } // ------------------------------------------------------------------------ @@ -570,11 +376,3 @@ class FooHex { return '010203'; } } - -class FooObject -{ - public function __toString() - { - return 'this is a foo'; - } -} \ No newline at end of file diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 4fbc11ef0..820bd37e2 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -25,14 +25,10 @@ class Upload_test extends CI_TestCase { ) ); - // ReflectionProperty::setAccessible() is not available in PHP 5.2.x - if (is_php('5.3')) - { - $reflection = new ReflectionClass($upload); - $reflection = $reflection->getProperty('_file_name_override'); - $reflection->setAccessible(TRUE); - $this->assertEquals('foo', $reflection->getValue($upload)); - } + $reflection = new ReflectionClass($upload); + $reflection = $reflection->getProperty('_file_name_override'); + $reflection->setAccessible(TRUE); + $this->assertEquals('foo', $reflection->getValue($upload)); $this->assertTrue($upload->file_ext_tolower); -- cgit v1.2.3-24-g4f1b From 878e23f8883b2510d573850deb7dca5761cc1848 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Aug 2016 15:15:49 +0300 Subject: Use getMockBuilder() in PHPUnit instead of the deprecated getMock() --- tests/codeigniter/core/Loader_test.php | 4 ++-- tests/codeigniter/helpers/date_helper_test.php | 4 ++-- tests/codeigniter/helpers/language_helper_test.php | 4 ++-- tests/codeigniter/helpers/number_helper_test.php | 4 ++-- tests/codeigniter/libraries/Calendar_test.php | 6 +++--- tests/codeigniter/libraries/Driver_test.php | 4 ++-- tests/codeigniter/libraries/Form_validation_test.php | 4 ++-- tests/codeigniter/libraries/Upload_test.php | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index db5088d80..c1c4997c4 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -291,7 +291,7 @@ class Loader_test extends CI_TestCase { $this->assertEquals($content.$value, $out); // Mock output class - $output = $this->getMock('CI_Output', array('append_output')); + $output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock(); $output->expects($this->once())->method('append_output')->with($content.$value); $this->ci_instance_var('output', $output); @@ -441,7 +441,7 @@ class Loader_test extends CI_TestCase { { // Mock lang class and test load call $file = 'test'; - $lang = $this->getMock('CI_Lang', array('load')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); $lang->expects($this->once())->method('load')->with($file); $this->ci_instance_var('lang', $lang); $this->assertInstanceOf('CI_Loader', $this->load->language($file)); diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index c80e92cd0..c4f99a97c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -15,7 +15,7 @@ class Date_helper_test extends CI_TestCase { /* // This stub job, is simply to cater $config['time_reference'] - $config = $this->getMock('CI_Config'); + $config = $this->getMockBuilder('CI_Config')->getMock(); $config->expects($this->any()) ->method('item') ->will($this->returnValue('local')); @@ -37,7 +37,7 @@ class Date_helper_test extends CI_TestCase { /* // This stub job, is simply to cater $config['time_reference'] - $config = $this->getMock('CI_Config'); + $config = $this->getMockBuilder('CI_Config')->getMock(); $config->expects($this->any()) ->method('item') ->will($this->returnValue('UTC')); diff --git a/tests/codeigniter/helpers/language_helper_test.php b/tests/codeigniter/helpers/language_helper_test.php index 176da689a..1ddabea3d 100644 --- a/tests/codeigniter/helpers/language_helper_test.php +++ b/tests/codeigniter/helpers/language_helper_test.php @@ -5,7 +5,7 @@ class Language_helper_test extends CI_TestCase { public function test_lang() { $this->helper('language'); - $lang = $this->getMock('CI_Lang', array('line')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('line'))->getMock(); $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); $this->ci_instance_var('lang', $lang); @@ -13,4 +13,4 @@ class Language_helper_test extends CI_TestCase { $this->assertEquals('', lang(1, 'foo', array('class' => 'bar'))); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 817db2c7e..663e354fe 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -11,7 +11,7 @@ class Number_helper_test extends CI_TestCase { // Mock away load, too much going on in there, // we'll just check for the expected parameter - $lang = $this->getMock($lang_cls, array('load')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); $lang->expects($this->once()) ->method('load') ->with($this->equalTo('number')); @@ -60,4 +60,4 @@ class Number_helper_test extends CI_TestCase { $this->assertEquals('112,283.3 TB', byte_format(123456789123456789)); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php index 54879fec9..ad1f45e8c 100644 --- a/tests/codeigniter/libraries/Calendar_test.php +++ b/tests/codeigniter/libraries/Calendar_test.php @@ -5,9 +5,9 @@ class Calendar_test extends CI_TestCase { public function set_up() { // Required for get_total_days() - $this->ci_instance_var('load', $this->getMock('CI_Loader', array('helper'))); + $this->ci_instance_var('load', $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock()); - $lang = $this->getMock('CI_Lang', array('load', 'line')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); $lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); $this->ci_instance_var('lang', $lang); @@ -219,4 +219,4 @@ class Calendar_test extends CI_TestCase { $this->assertEquals($array, $this->calendar->default_template()); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Driver_test.php b/tests/codeigniter/libraries/Driver_test.php index c62cbee45..e4401e688 100644 --- a/tests/codeigniter/libraries/Driver_test.php +++ b/tests/codeigniter/libraries/Driver_test.php @@ -16,7 +16,7 @@ class Driver_test extends CI_TestCase { // Mock Loader->get_package_paths $paths = 'get_package_paths'; - $ldr = $this->getMock('CI_Loader', array($paths)); + $ldr = $this->getMockBuilder('CI_Loader')->setMethods(array($paths))->getMock(); $ldr->expects($this->any())->method($paths)->will($this->returnValue(array(APPPATH, BASEPATH))); $this->ci_instance_var('load', $ldr); @@ -175,4 +175,4 @@ class Driver_test extends CI_TestCase { $this->assertEquals($return, $child->$method()); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index b87ca65ff..905f663e2 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -8,10 +8,10 @@ class Form_validation_test extends CI_TestCase { // Create a mock loader since load->helper() looks in the wrong directories for unit tests, // We'll use CI_TestCase->helper() instead - $loader = $this->getMock('CI_Loader', array('helper')); + $loader = $this->getMockBuilder('CI_Loader')->setMethods(array('helper'))->getMock(); // Same applies for lang - $lang = $this->getMock('CI_Lang', array('load')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); $this->ci_set_config('charset', 'UTF-8'); $utf8 = new Mock_Core_Utf8(); diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 820bd37e2..8bac597b3 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -7,7 +7,7 @@ class Upload_test extends CI_TestCase { $ci = $this->ci_instance(); $ci->upload = new CI_Upload(); $ci->security = new Mock_Core_Security(); - $ci->lang = $this->getMock('CI_Lang', array('load', 'line')); + $ci->lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); $ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); $this->upload = $ci->upload; } @@ -296,4 +296,4 @@ class Upload_test extends CI_TestCase { $this->assertEquals('

Error test

', $this->upload->display_errors()); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 9180a1264dc536c34e5cc8a0e44bb399a8ba484f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Aug 2016 15:23:42 +0300 Subject: Add changelog entry and a test case for #4758 --- tests/codeigniter/libraries/Form_validation_test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 905f663e2..0815300e6 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -259,6 +259,9 @@ class Form_validation_test extends CI_TestCase { // https://github.com/bcit-ci/CodeIgniter/issues/4415 $this->assertTrue($this->form_validation->valid_url('http://[::1]/ipv6')); + // URI scheme case-sensitivity: https://github.com/bcit-ci/CodeIgniter/pull/4758 + $this->assertTrue($this->form_validation->valid_url('HtTp://127.0.0.1/')); + $this->assertFalse($this->form_validation->valid_url('htt://www.codeIgniter.com')); $this->assertFalse($this->form_validation->valid_url('')); $this->assertFalse($this->form_validation->valid_url('code igniter')); -- cgit v1.2.3-24-g4f1b From c95df51c90dc9506ec9a37a43d87238965210550 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Aug 2016 13:19:24 +0300 Subject: Skip mcrypt-related testcases on PHP 7.1 ext/mcrypt is deprecated and the test cases in question trigger E_DEPRECATED messages as a result. --- tests/codeigniter/libraries/Encrypt_test.php | 6 +++++- tests/codeigniter/libraries/Encryption_test.php | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Encrypt_test.php b/tests/codeigniter/libraries/Encrypt_test.php index ced763301..adbca31b2 100644 --- a/tests/codeigniter/libraries/Encrypt_test.php +++ b/tests/codeigniter/libraries/Encrypt_test.php @@ -10,6 +10,10 @@ class Encrypt_test extends CI_TestCase { { return; } + elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) + { + return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); + } $this->encrypt = new Mock_Libraries_Encrypt(); $this->ci_instance_var('encrypt', $this->encrypt); @@ -72,4 +76,4 @@ class Encrypt_test extends CI_TestCase { $this->assertEquals('cfb', $this->encrypt->get_mode()); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php index cbcae3133..96e52ada8 100644 --- a/tests/codeigniter/libraries/Encryption_test.php +++ b/tests/codeigniter/libraries/Encryption_test.php @@ -240,6 +240,10 @@ class Encryption_test extends CI_TestCase { { return $this->markTestSkipped('Cannot test MCrypt because it is not available.'); } + elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) + { + return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); + } $this->assertTrue(is_resource($this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc'))); } @@ -274,6 +278,10 @@ class Encryption_test extends CI_TestCase { $this->markTestSkipped('Both MCrypt and OpenSSL support are required for portability tests.'); return; } + elseif (version_compare(PHP_VERSION, '7.1.0-alpha', '>=')) + { + return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); + } $message = 'This is a message encrypted via MCrypt and decrypted via OpenSSL, or vice-versa.'; @@ -377,4 +385,4 @@ class Encryption_test extends CI_TestCase { $this->assertEquals('stream', $this->encryption->mode); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From eea02de557834006c5d6a0bfccca7f39e75bf3a8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 27 Sep 2016 14:59:37 +0300 Subject: Fix entity_decode() issue --- tests/codeigniter/core/Security_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index 8328c37cb..cbf0285ec 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -270,6 +270,12 @@ class Security_test extends CI_TestCase { $this->assertEquals('
Hello Booya
', $decoded); + $this->assertEquals('colon:', $this->security->entity_decode('colon:')); + $this->assertEquals("NewLine\n", $this->security->entity_decode('NewLine ')); + $this->assertEquals("Tab\t", $this->security->entity_decode('Tab ')); + $this->assertEquals("lpar(", $this->security->entity_decode('lpar(')); + $this->assertEquals("rpar)", $this->security->entity_decode('rpar)')); + // Issue #3057 (https://github.com/bcit-ci/CodeIgniter/issues/3057) $this->assertEquals( '&foo should not include a semicolon', -- cgit v1.2.3-24-g4f1b From 5d05372f4f59d27fdd93249d813970fcf181a4af Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 20 Oct 2016 13:40:57 +0300 Subject: FV: throw BadMethodCallException when set_rules() called without --- tests/codeigniter/libraries/Form_validation_test.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 0815300e6..5f4bb9316 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -435,6 +435,12 @@ class Form_validation_test extends CI_TestCase { $this->assertFalse($form_validation->run('fail')); } + public function test_set_rules_exception() + { + $this->setExpectedException('BadMethodCallException'); + $this->form_validation->set_rules('foo', 'bar'); + } + public function test_has_rule() { $this->form_validation->reset_validation(); -- cgit v1.2.3-24-g4f1b From b18492be397373de452999f34a200cc24fb751ed Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Tue, 1 Nov 2016 11:19:24 +0200 Subject: added tests for ordinal_format() helper function (Inflector helper) --- tests/codeigniter/helpers/inflector_helper_test.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 81ce5e394..a5bb80532 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -93,4 +93,23 @@ class Inflector_helper_test extends CI_TestCase { } } + // -------------------------------------------------------------------- + + public function test_ordinal_format() + { + $strs = array( + 1 => '1st', + 2 => '2nd', + 4 => '4th', + 11 => '1th', + 12 => '12th', + 13 => '13th', + 'something else' => 'something else', + ); + + foreach ($strs as $str => $expect) + { + $this->assertEquals($expect, ordinal_format($str)); + } + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b2c3a0063d02edfec79ab9aa5619c9f40cdd21d0 Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Tue, 1 Nov 2016 11:22:38 +0200 Subject: small typo --- tests/codeigniter/helpers/inflector_helper_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index a5bb80532..4a1e64fae 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -101,7 +101,7 @@ class Inflector_helper_test extends CI_TestCase { 1 => '1st', 2 => '2nd', 4 => '4th', - 11 => '1th', + 11 => '11th', 12 => '12th', 13 => '13th', 'something else' => 'something else', -- cgit v1.2.3-24-g4f1b From 820d9cdaac9a9c0371404ce82b60a26ed3ac938f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 23 Nov 2016 13:27:42 +0200 Subject: Fix #4917 --- tests/codeigniter/helpers/date_helper_test.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index c4f99a97c..8a3502280 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -10,6 +10,14 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ + public function test_nice_date() + { + $this->assertEquals('2016-11-01', nice_date('201611', 'Y-m-d')); + $this->assertEquals('2016-11-23', nice_date('20161123', 'Y-m-d')); + } + + // ------------------------------------------------------------------------ + public function test_now_local() { /* -- cgit v1.2.3-24-g4f1b From bd3b4d158110634ec54d026f2852a649711edefc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:07:19 +0200 Subject: Remove tests broken by the func removals from last few commits --- tests/codeigniter/core/Config_test.php | 9 +-------- tests/codeigniter/helpers/email_helper_test.php | 24 ------------------------ 2 files changed, 1 insertion(+), 32 deletions(-) delete mode 100644 tests/codeigniter/helpers/email_helper_test.php (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index b5c9e849d..5201d46dc 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -152,13 +152,6 @@ class Config_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_system_url() - { - $this->assertEquals($this->cfg['base_url'].'system/', $this->config->system_url()); - } - - // -------------------------------------------------------------------- - public function test_load() { // Test regular load @@ -237,4 +230,4 @@ class Config_test extends CI_TestCase { $this->assertNull($this->config->load($file)); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php deleted file mode 100644 index 529e96910..000000000 --- a/tests/codeigniter/helpers/email_helper_test.php +++ /dev/null @@ -1,24 +0,0 @@ -helper('email'); - } - - public function test_valid_email() - { - $this->assertEquals(FALSE, valid_email('test')); - $this->assertEquals(FALSE, valid_email('test@test@test.com')); - $this->assertEquals(TRUE, valid_email('test@test.com')); - $this->assertEquals(TRUE, valid_email('my.test@test.com')); - $this->assertEquals(TRUE, valid_email('my.test@subdomain.test.com')); - } - - public function test_send_mail() - { - $this->markTestSkipped("Can't test"); - } - -} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ecc9a5f2102d8221f9783fd77d8a4b7bb03a3e4a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:08:11 +0200 Subject: Remove previously deprecated Date Helper function standard_date() --- tests/codeigniter/helpers/date_helper_test.php | 100 ------------------------- 1 file changed, 100 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 8a3502280..00139de5c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -73,106 +73,6 @@ class Date_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_standard_date_rfc822() - { - $this->assertEquals( - date(DATE_RFC822, $this->time), - standard_date('DATE_RFC822', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_atom() - { - $this->assertEquals( - date(DATE_ATOM, $this->time), - standard_date('DATE_ATOM', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_cookie() - { - $this->assertEquals( - date(DATE_COOKIE, $this->time), - standard_date('DATE_COOKIE', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_iso8601() - { - $this->assertEquals( - date(DATE_ISO8601, $this->time), - standard_date('DATE_ISO8601', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc850() - { - $this->assertEquals( - date(DATE_RFC850, $this->time), - standard_date('DATE_RFC850', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc1036() - { - $this->assertEquals( - date(DATE_RFC1036, $this->time), - standard_date('DATE_RFC1036', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc1123() - { - $this->assertEquals( - date(DATE_RFC1123, $this->time), - standard_date('DATE_RFC1123', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rfc2822() - { - $this->assertEquals( - date(DATE_RFC2822, $this->time), - standard_date('DATE_RFC2822', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_rss() - { - $this->assertEquals( - date(DATE_RSS, $this->time), - standard_date('DATE_RSS', $this->time) - ); - } - - // ------------------------------------------------------------------------ - - public function test_standard_date_w3c() - { - $this->assertEquals( - date(DATE_W3C, $this->time), - standard_date('DATE_W3C', $this->time) - ); - } - - // ------------------------------------------------------------------------ - public function test_timespan() { $this->ci_vfs_clone('system/language/english/date_lang.php'); -- cgit v1.2.3-24-g4f1b From 0c84ef9a33d18d758e36447fd18a240a458ae2bc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:12:35 +0200 Subject: Remove previously deprecated Security Helper function do_hash() --- tests/codeigniter/helpers/security_helper_test.php | 26 +--------------------- 1 file changed, 1 insertion(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php index effd3ec02..ab05d57ba 100644 --- a/tests/codeigniter/helpers/security_helper_test.php +++ b/tests/codeigniter/helpers/security_helper_test.php @@ -25,30 +25,6 @@ class Security_helper_tests extends CI_TestCase { $this->assertEquals('foo', sanitize_filename($filename)); } - function test_do_hash() - { - $md5 = md5('foo'); - $sha1 = sha1('foo'); - - $algos = hash_algos(); - $algo_results = array(); - foreach ($algos as $k => $v) - { - $algo_results[$v] = hash($v, 'foo'); - } - - $this->assertEquals($sha1, do_hash('foo')); - $this->assertEquals($sha1, do_hash('foo', 'sha1')); - $this->assertEquals($md5, do_hash('foo', 'md5')); - $this->assertEquals($md5, do_hash('foo', 'foobar')); - - // Test each algorithm available to PHP - foreach ($algo_results as $algo => $result) - { - $this->assertEquals($result, do_hash('foo', $algo)); - } - } - function test_strip_image_tags() { $this->assertEquals('http://example.com/spacer.gif', strip_image_tags('http://example.com/spacer.gif')); @@ -61,4 +37,4 @@ class Security_helper_tests extends CI_TestCase { $this->assertEquals('<? echo $foo; ?>', encode_php_tags('')); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 5e47aa3d87b44627bd79850536bfacd8d39a92a6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:18:46 +0200 Subject: Remove previously deprecated HTML helper functions br(), nbs() --- tests/codeigniter/helpers/html_helper_test.php | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 029f3f4cd..5565e011b 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -9,13 +9,6 @@ class Html_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ - public function test_br() - { - $this->assertEquals('

', br(2)); - } - - // ------------------------------------------------------------------------ - public function test_heading() { $this->assertEquals('

foobar

', heading('foobar')); @@ -72,13 +65,6 @@ EOH; // ------------------------------------------------------------------------ - public function test_NBS() - { - $this->assertEquals('   ', nbs(3)); - } - - // ------------------------------------------------------------------------ - public function test_meta() { $this->assertEquals( @@ -101,4 +87,4 @@ EOH; meta(array('name' => 'foo', 'type' => 'charset')) ); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 41091ba2fd3005d4a387ee17bfd7520475028627 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:25:25 +0200 Subject: Remove previously deprecates String Helper functions trim_slashes(), repeater() --- tests/codeigniter/helpers/string_helper_test.php | 32 +----------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index 75701ec13..6de336b01 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -22,19 +22,6 @@ class String_helper_test extends CI_TestCase { $this->assertEquals($expected, strip_slashes($str)); } - public function test_trim_slashes() - { - $strs = array( - '//Slashes//\/' => 'Slashes//\\', - '/var/www/html/' => 'var/www/html' - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, trim_slashes($str)); - } - } - // -------------------------------------------------------------------- public function test_strip_quotes() @@ -108,23 +95,6 @@ class String_helper_test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_repeater() - { - $strs = array( - 'a' => 'aaaaaaaaaa', - ' ' => '          ', - '
' => '









' - - ); - - foreach ($strs as $str => $expect) - { - $this->assertEquals($expect, repeater($str, 10)); - } - } - - // -------------------------------------------------------------------- - public function test_random_string() { $this->assertEquals(16, strlen(random_string('alnum', 16))); @@ -145,4 +115,4 @@ class String_helper_test extends CI_TestCase { $this->assertEquals(124, increment_string('123', '')); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 172f949370bb1498789c7d897fdaa4073388ebd5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:28:41 +0200 Subject: Remove previously deprecated File Helper function read_file() --- tests/codeigniter/helpers/file_helper_test.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index c31817595..5ed8cb5c0 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -14,19 +14,6 @@ class File_helper_Test extends CI_TestCase { // -------------------------------------------------------------------- - public function test_read_file() - { - $this->assertFalse(read_file('does_not_exist')); - - $content = 'Jack and Jill went up the mountain to fight a billy goat.'; - - $file = vfsStream::newFile('my_file.txt')->withContent($content)->at($this->_test_dir); - - $this->assertEquals($content, read_file(vfsStream::url('my_file.txt'))); - } - - // -------------------------------------------------------------------- - public function test_octal_permissions() { $content = 'Jack and Jill went up the mountain to fight a billy goat.'; @@ -144,4 +131,4 @@ class File_helper_Test extends CI_TestCase { $this->assertTrue(write_file(vfsStream::url('write.txt'), $content)); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 37c4cc599698da0634d620665491fc27e9a36beb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:33:42 +0200 Subject: Remove previously deprecated Form Helper function form_prep() --- tests/codeigniter/helpers/form_helper_test.php | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index b5fe99b96..4ecfaa5f7 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -271,20 +271,4 @@ EOH; $this->assertEquals($expected, form_close('')); } - - // ------------------------------------------------------------------------ - - public function test_form_prep() - { - $this->assertEquals( - 'Here is a string containing "quoted" text.', - form_prep('Here is a string containing "quoted" text.') - ); - - $this->assertEquals( - 'Here is a string containing a <tag>.', - form_prep('Here is a string containing a .', TRUE) - ); - } - } -- cgit v1.2.3-24-g4f1b From 9b5a84dfb0c8a4ba078beb516373e7bb7d8d3ed7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 1 Dec 2016 15:45:41 +0200 Subject: Remove previously deprecated FV Library method/rule prep_for_form() --- tests/codeigniter/libraries/Form_validation_test.php | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 5f4bb9316..4be080f90 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -579,20 +579,6 @@ class Form_validation_test extends CI_TestCase { $this->assertFalse($this->form_validation->regex_match('bar', $regex)); } - public function test_prep_for_form() - { - $this->form_validation->reset_validation(); - $error_msg_unprepped = ''; - $error_msg_prepped = '<error ='foobar'">'; - $this->form_validation->set_rules('foo', 'label', 'required', array('required' => $error_msg_unprepped)); - $_POST = array('foo' => ''); - $this->form_validation->run(); - $error_arr = $this->form_validation->error_array(); - - $this->assertEquals('', $this->form_validation->prep_for_form('')); - $this->assertEquals(array('foo' => $error_msg_prepped), $this->form_validation->prep_for_form($error_arr)); - } - public function test_prep_url() { $this->assertEquals('', $this->form_validation->prep_url('')); -- cgit v1.2.3-24-g4f1b From 83424f9284815e816015a9e3f8326e410601c011 Mon Sep 17 00:00:00 2001 From: Ryan McAllen Date: Wed, 7 Dec 2016 18:22:31 -0500 Subject: Spelling: convinient -> convenient --- tests/mocks/autoloader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 33942768d..11825de2c 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -1,6 +1,6 @@ Date: Thu, 8 Dec 2016 12:21:40 +0200 Subject: Merge pull request #4932 from rhynodesigns/patch-1 [ci skip] Fix a comment typo in unit tests --- tests/mocks/autoloader.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 33942768d..11825de2c 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -1,6 +1,6 @@ Date: Mon, 12 Dec 2016 15:27:13 +0200 Subject: Remove previously deprecated Cart Library --- tests/mocks/autoloader.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index 11825de2c..a912327ca 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -33,7 +33,6 @@ function autoload($class) $ci_libraries = array( 'Calendar', - 'Cart', 'Driver_Library', 'Email', 'Encrypt', -- cgit v1.2.3-24-g4f1b From ff773c059cb984920767dd6187c30a77e5bf78c9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 14 Dec 2016 13:45:45 +0200 Subject: Finally drop CI_Input::_sanitize_globals() Close #4101 --- tests/mocks/core/input.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php index 40e27441f..4d217a252 100644 --- a/tests/mocks/core/input.php +++ b/tests/mocks/core/input.php @@ -11,16 +11,10 @@ class Mock_Core_Input extends CI_Input { */ public function __construct($security, $utf8) { - $this->_allow_get_array = (config_item('allow_get_array') === TRUE); - $this->_enable_xss = (config_item('global_xss_filtering') === TRUE); $this->_enable_csrf = (config_item('csrf_protection') === TRUE); // Assign Security and Utf8 classes $this->security = $security; - $this->uni = $utf8; - - // Sanitize global arrays - $this->_sanitize_globals(); } public function fetch_from_array($array, $index = '', $xss_clean = FALSE) @@ -28,16 +22,6 @@ class Mock_Core_Input extends CI_Input { return parent::_fetch_from_array($array, $index, $xss_clean); } - /** - * Lie about being a CLI request - * - * We take advantage of this in libraries/Session_test - */ - public function is_cli_request() - { - return FALSE; - } - public function __set($name, $value) { if ($name === 'ip_address') @@ -45,5 +29,4 @@ class Mock_Core_Input extends CI_Input { $this->ip_address = $value; } } - -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b From 24c866628d0ce5463d7e8b4eba512fa9e7752dfd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 14 Dec 2016 16:14:13 +0200 Subject: Drop all PHP 5.3-related code --- tests/codeigniter/core/compat/standard_test.php | 32 ------------------------- 1 file changed, 32 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/compat/standard_test.php b/tests/codeigniter/core/compat/standard_test.php index a98460129..54424bb9b 100644 --- a/tests/codeigniter/core/compat/standard_test.php +++ b/tests/codeigniter/core/compat/standard_test.php @@ -10,11 +10,6 @@ class standard_test extends CI_TestCase { } $this->assertTrue(function_exists('array_column')); - - if ( ! is_php('5.4')) - { - $this->assertTrue(function_exists('hex2bin')); - } } // ------------------------------------------------------------------------ @@ -330,25 +325,6 @@ class standard_test extends CI_TestCase { array_column($input, 'b', 'a') ); } - - // ------------------------------------------------------------------------ - - /** - * hex2bin() tests - * - * @depends test_bootstrap - */ - public function test_hex2bin() - { - if (is_php('5.4')) - { - return $this->markTestSkipped('hex2bin() is already available on PHP 5.4'); - } - - $this->assertEquals("\x03\x04", hex2bin("0304")); - $this->assertEquals('', hex2bin('')); - $this->assertEquals("\x01\x02\x03", hex2bin(new FooHex())); - } } // ------------------------------------------------------------------------ @@ -368,11 +344,3 @@ class Bar { return 'first_name'; } } - -class FooHex { - - public function __toString() - { - return '010203'; - } -} -- cgit v1.2.3-24-g4f1b From dcd6f5153b7e7e6d798d5a77af65b7460f152e5c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 14 Dec 2016 18:14:35 +0200 Subject: Isolate CI_Security instantiation from CI_Input; improve tests --- tests/codeigniter/core/Input_test.php | 4 +- tests/codeigniter/core/URI_test.php | 9 ++++ tests/codeigniter/core/Utf8_test.php | 53 +++++++++++----------- tests/codeigniter/helpers/cookie_helper_test.php | 5 +- tests/codeigniter/helpers/text_helper_test.php | 23 ++++++---- tests/codeigniter/helpers/url_helper_test.php | 12 ++++- .../codeigniter/libraries/Form_validation_test.php | 4 +- tests/mocks/ci_testcase.php | 4 +- tests/mocks/core/input.php | 8 ++-- tests/mocks/core/utf8.php | 19 -------- 10 files changed, 69 insertions(+), 72 deletions(-) delete mode 100644 tests/mocks/core/utf8.php (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index e1f4011b5..78b659691 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -15,9 +15,7 @@ class Input_test extends CI_TestCase { $security = new Mock_Core_Security(); $this->ci_set_config('charset', 'UTF-8'); - $utf8 = new Mock_Core_Utf8(); - - $this->input = new Mock_Core_Input($security, $utf8); + $this->input = new Mock_Core_Input($security); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/core/URI_test.php b/tests/codeigniter/core/URI_test.php index 42dff3639..f862c666e 100644 --- a/tests/codeigniter/core/URI_test.php +++ b/tests/codeigniter/core/URI_test.php @@ -119,8 +119,13 @@ class URI_test extends CI_TestCase { */ // -------------------------------------------------------------------- + /** + * @runInSeparateProcess + */ public function test_filter_uri_passing() { + define('UTF8_ENABLED', FALSE); + $this->uri->_set_permitted_uri_chars('a-z 0-9~%.:_\-'); $str = 'abc01239~%.:_-'; @@ -129,8 +134,12 @@ class URI_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @runInSeparateProcess + */ public function test_filter_uri_throws_error() { + define('UTF8_ENABLED', FALSE); $this->setExpectedException('RuntimeException'); $this->uri->config->set_item('enable_query_strings', FALSE); diff --git a/tests/codeigniter/core/Utf8_test.php b/tests/codeigniter/core/Utf8_test.php index 7e6ffd930..f40bb9848 100644 --- a/tests/codeigniter/core/Utf8_test.php +++ b/tests/codeigniter/core/Utf8_test.php @@ -1,31 +1,27 @@ ci_set_config('charset', 'UTF-8'); - $this->utf8 = new Mock_Core_Utf8(); - $this->ci_instance_var('utf8', $this->utf8); + if ( ! defined('PREG_BAD_UTF8_ERROR') OR (ICONV_ENABLED === FALSE && MB_ENABLED === FALSE)) + { + return $this->markTestSkipped('PCRE_UTF8 and/or both ext/mbstring & ext/iconv are unavailable'); + } + + new CI_Utf8('UTF-8'); + $this->assertTrue(UTF8_ENABLED); } // -------------------------------------------------------------------- - /** - * __construct() test - * - * @covers CI_Utf8::__construct - */ - public function test___construct() + public function test__constructUTF8_DISABLED() { - if (defined('PREG_BAD_UTF8_ERROR') && (ICONV_ENABLED === TRUE OR MB_ENABLED === TRUE) && strtoupper(config_item('charset')) === 'UTF-8') - { - $this->assertTrue(UTF8_ENABLED); - } - else - { - $this->assertFalse(UTF8_ENABLED); - } + new CI_Utf8('WINDOWS-1251'); + $this->assertFalse(UTF8_ENABLED); } // -------------------------------------------------------------------- @@ -37,8 +33,9 @@ class Utf8_test extends CI_TestCase { */ public function test_is_ascii() { - $this->assertTrue($this->utf8->is_ascii('foo bar')); - $this->assertFalse($this->utf8->is_ascii('тест')); + $utf8 = new CI_Utf8('UTF-8'); + $this->assertTrue($utf8->is_ascii('foo bar')); + $this->assertFalse($utf8->is_ascii('тест')); } // -------------------------------------------------------------------- @@ -51,21 +48,22 @@ class Utf8_test extends CI_TestCase { */ public function test_clean_string() { - $this->assertEquals('foo bar', $this->utf8->clean_string('foo bar')); + $utf8 = new CI_Utf8('UTF-8'); + $this->assertEquals('foo bar', $utf8->clean_string('foo bar')); $illegal_utf8 = "\xc0тест"; if (MB_ENABLED) { - $this->assertEquals('тест', $this->utf8->clean_string($illegal_utf8)); + $this->assertEquals('тест', $utf8->clean_string($illegal_utf8)); } elseif (ICONV_ENABLED) { // This is a known issue, iconv doesn't always work with //IGNORE - $this->assertTrue(in_array($this->utf8->clean_string($illegal_utf8), array('тест', ''), TRUE)); + $this->assertTrue(in_array($utf8->clean_string($illegal_utf8), array('тест', ''), TRUE)); } else { - $this->assertEquals($illegal_utf8, $this->utf8->clean_string($illegal_utf8)); + $this->assertEquals($illegal_utf8, $utf8->clean_string($illegal_utf8)); } } @@ -78,14 +76,15 @@ class Utf8_test extends CI_TestCase { */ public function test_convert_to_utf8() { + $utf8 = new CI_Utf8('UTF-8'); if (MB_ENABLED OR ICONV_ENABLED) { - $this->assertEquals('тест', $this->utf8->convert_to_utf8('', 'WINDOWS-1251')); + $this->assertEquals('тест', $utf8->convert_to_utf8('', 'WINDOWS-1251')); } else { - $this->assertFalse($this->utf8->convert_to_utf8('', 'WINDOWS-1251')); + $this->assertFalse($utf8->convert_to_utf8('', 'WINDOWS-1251')); } } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php index fba68f20f..1fbb57f67 100644 --- a/tests/codeigniter/helpers/cookie_helper_test.php +++ b/tests/codeigniter/helpers/cookie_helper_test.php @@ -29,9 +29,8 @@ class Cookie_helper_test extends CI_TestCase { $_COOKIE['foo'] = 'bar'; $security = new Mock_Core_Security(); - $utf8 = new Mock_Core_Utf8(); $input_cls = $this->ci_core_class('input'); - $this->ci_instance_var('input', new Mock_Core_Input($security, $utf8)); + $this->ci_instance_var('input', new Mock_Core_Input($security)); $this->assertEquals('bar', get_cookie('foo', FALSE)); $this->assertEquals('bar', get_cookie('foo', TRUE)); @@ -56,4 +55,4 @@ class Cookie_helper_test extends CI_TestCase { $this->markTestSkipped('Need to find a way to overcome a headers already set exception'); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index 7a7dc0a12..36465f203 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -2,21 +2,19 @@ class Text_helper_test extends CI_TestCase { - private $_long_string; - public function set_up() { $this->helper('text'); - - $this->_long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; } // ------------------------------------------------------------------------ public function test_word_limiter() { - $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4)); - $this->assertEquals('Once upon a time,…', word_limiter($this->_long_string, 4, '…')); + $long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; + + $this->assertEquals('Once upon a time,…', word_limiter($long_string, 4)); + $this->assertEquals('Once upon a time,…', word_limiter($long_string, 4, '…')); $this->assertEquals('', word_limiter('', 4)); } @@ -24,8 +22,10 @@ class Text_helper_test extends CI_TestCase { public function test_character_limiter() { - $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20)); - $this->assertEquals('Once upon a time, a…', character_limiter($this->_long_string, 20, '…')); + $long_string = 'Once upon a time, a framework had no tests. It sad. So some nice people began to write tests. The more time that went on, the happier it became. Everyone was happy.'; + + $this->assertEquals('Once upon a time, a…', character_limiter($long_string, 20)); + $this->assertEquals('Once upon a time, a…', character_limiter($long_string, 20, '…')); $this->assertEquals('Short', character_limiter('Short', 20)); $this->assertEquals('Short', character_limiter('Short', 5)); } @@ -103,8 +103,13 @@ class Text_helper_test extends CI_TestCase { // ------------------------------------------------------------------------ + /** + * @runInSeparateProcess + */ public function test_highlight_phrase() { + define('UTF8_ENABLED', FALSE); + $strs = array( 'this is a phrase' => 'this is a phrase', 'this is another' => 'this is another', @@ -171,4 +176,4 @@ class Text_helper_test extends CI_TestCase { $this->assertEquals(strpos(word_wrap($string), "\n"), 73); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 24823a634..c5b0f80b7 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -7,8 +7,13 @@ class Url_helper_test extends CI_TestCase { $this->helper('url'); } + /** + * @runInSeparateProcess + */ public function test_url_title() { + define('UTF8_ENABLED', FALSE); + $words = array( 'foo bar /' => 'foo-bar', '\ testing 12' => 'testing-12' @@ -22,8 +27,13 @@ class Url_helper_test extends CI_TestCase { // -------------------------------------------------------------------- + /** + * @runInSeparateProcess + */ public function test_url_title_extra_dashes() { + define('UTF8_ENABLED', FALSE); + $words = array( '_foo bar_' => 'foo_bar', '_What\'s wrong with CSS?_' => 'Whats_wrong_with_CSS' @@ -76,4 +86,4 @@ class Url_helper_test extends CI_TestCase { } } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 4be080f90..5b7830dd8 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -13,10 +13,8 @@ class Form_validation_test extends CI_TestCase { // Same applies for lang $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); - $this->ci_set_config('charset', 'UTF-8'); - $utf8 = new Mock_Core_Utf8(); $security = new Mock_Core_Security(); - $input = new Mock_Core_Input($security, $utf8); + $input = new Mock_Core_Input($security); $this->ci_instance_var('lang', $lang); $this->ci_instance_var('load', $loader); diff --git a/tests/mocks/ci_testcase.php b/tests/mocks/ci_testcase.php index a2c37b92e..b320aab74 100644 --- a/tests/mocks/ci_testcase.php +++ b/tests/mocks/ci_testcase.php @@ -24,9 +24,9 @@ class CI_TestCase extends PHPUnit_Framework_TestCase { // -------------------------------------------------------------------- - public function __construct() + public function __construct($name = null, array $data = [], $dataName = '') { - parent::__construct(); + parent::__construct($name, $data, $dataName); $this->ci_instance = new stdClass(); } diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php index 4d217a252..6f6a91365 100644 --- a/tests/mocks/core/input.php +++ b/tests/mocks/core/input.php @@ -9,12 +9,10 @@ class Mock_Core_Input extends CI_Input { * * @covers CI_Input::__construct() */ - public function __construct($security, $utf8) + public function __construct($security) { - $this->_enable_csrf = (config_item('csrf_protection') === TRUE); - - // Assign Security and Utf8 classes - $this->security = $security; + $this->_enable_csrf = (config_item('csrf_protection') === TRUE); + $this->security = $security; } public function fetch_from_array($array, $index = '', $xss_clean = FALSE) diff --git a/tests/mocks/core/utf8.php b/tests/mocks/core/utf8.php deleted file mode 100644 index 3a6282e1d..000000000 --- a/tests/mocks/core/utf8.php +++ /dev/null @@ -1,19 +0,0 @@ - Date: Wed, 14 Dec 2016 18:41:52 +0200 Subject: Move csrf_verify() call out of CI_Input --- tests/codeigniter/core/Input_test.php | 40 ++++++++++++---------- tests/codeigniter/core/Security_test.php | 5 +-- tests/codeigniter/helpers/cookie_helper_test.php | 4 +-- tests/codeigniter/helpers/security_helper_test.php | 2 +- .../codeigniter/libraries/Form_validation_test.php | 4 +-- tests/codeigniter/libraries/Session_test.php | 5 +-- tests/codeigniter/libraries/Upload_test.php | 2 +- tests/mocks/core/input.php | 30 ---------------- 8 files changed, 34 insertions(+), 58 deletions(-) delete mode 100644 tests/mocks/core/input.php (limited to 'tests') diff --git a/tests/codeigniter/core/Input_test.php b/tests/codeigniter/core/Input_test.php index 78b659691..e068a84be 100644 --- a/tests/codeigniter/core/Input_test.php +++ b/tests/codeigniter/core/Input_test.php @@ -12,10 +12,8 @@ class Input_test extends CI_TestCase { $this->ci_set_config('global_xss_filtering', FALSE); $this->ci_set_config('csrf_protection', FALSE); - $security = new Mock_Core_Security(); - - $this->ci_set_config('charset', 'UTF-8'); - $this->input = new Mock_Core_Input($security); + $security = new Mock_Core_Security('UTF-8'); + $this->input = new CI_Input($security); } // -------------------------------------------------------------------- @@ -120,14 +118,17 @@ class Input_test extends CI_TestCase { public function test_fetch_from_array() { + $reflection = new ReflectionMethod($this->input, '_fetch_from_array'); + $reflection->setAccessible(TRUE); + $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); + $foo = $reflection->invokeArgs($this->input, [&$data, 'foo']); + $harm = $reflection->invokeArgs($this->input, [&$data, 'harm']); + $harmless = $reflection->invokeArgs($this->input, [&$data, 'harm', TRUE]); $this->assertEquals('bar', $foo); $this->assertEquals("Hello, i try to your site", $harm); @@ -215,57 +216,60 @@ class Input_test extends CI_TestCase { public function test_ip_address() { - $this->input->ip_address = '127.0.0.1'; + $reflection = new ReflectionProperty($this->input, 'ip_address'); + $reflection->setAccessible(TRUE); + + $reflection->setValue($this->input, '127.0.0.1'); $this->assertEquals('127.0.0.1', $this->input->ip_address()); // 127.0.0.1 is set in our Bootstrap file - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $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 + $reflection->setValue($this->input, FALSE); // reset cached value $this->assertEquals('0.0.0.0', $this->input->ip_address()); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // Proxy_ips tests - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', '127.0.0.3, 127.0.0.4, 127.0.0.2'); $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; $this->assertEquals('127.0.0.1', $this->input->ip_address()); // Invalid spoof - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', 'invalid_ip_address'); $_SERVER['HTTP_CLIENT_IP'] = 'invalid_ip_address'; $this->assertEquals('127.0.0.1', $this->input->ip_address()); - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.1/1'); $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1'; $this->assertEquals('127.0.0.1', $this->input->ip_address()); - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', 'http://foo/bar/baz, 127.0.0.2'); $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.2'; $_SERVER['REMOTE_ADDR'] = '127.0.0.2'; $this->assertEquals('127.0.0.2', $this->input->ip_address()); - //IPv6 - $this->input->ip_address = FALSE; + // IPv6 + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329/1, FE80:0000:0000:0000:0202:B3FF:FE1E:8300/2'); $_SERVER['HTTP_CLIENT_IP'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8300'; $_SERVER['REMOTE_ADDR'] = 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'; $this->assertEquals('FE80:0000:0000:0000:0202:B3FF:FE1E:8300', $this->input->ip_address()); - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $this->ci_set_config('proxy_ips', '0::/32'); $_SERVER['HTTP_CLIENT_IP'] = '127.0.0.7'; $_SERVER['REMOTE_ADDR'] = '0000:0000:0000:0000:0000:0000:0000:0001'; $this->assertEquals('127.0.0.7', $this->input->ip_address()); - $this->input->ip_address = FALSE; + $reflection->setValue($this->input, FALSE); $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; // back to reality } diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index cbf0285ec..2e1127f87 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -12,7 +12,8 @@ class Security_test extends CI_TestCase { $this->ci_set_config('csrf_token_name', 'ci_csrf_token'); $this->ci_set_config('csrf_cookie_name', 'ci_csrf_cookie'); - $this->security = new Mock_Core_Security(); + $_SERVER['REQUEST_METHOD'] = 'GET'; + $this->security = new Mock_Core_Security('UTF-8'); } // -------------------------------------------------------------------- @@ -341,7 +342,7 @@ class Security_test extends CI_TestCase { // leave csrf_cookie_name as blank to test _csrf_set_hash function $this->ci_set_config('csrf_cookie_name', ''); - $this->security = new Mock_Core_Security(); + $this->security = new Mock_Core_Security('UTF-8'); $this->assertNotEmpty($this->security->get_csrf_hash()); } diff --git a/tests/codeigniter/helpers/cookie_helper_test.php b/tests/codeigniter/helpers/cookie_helper_test.php index 1fbb57f67..e984be21c 100644 --- a/tests/codeigniter/helpers/cookie_helper_test.php +++ b/tests/codeigniter/helpers/cookie_helper_test.php @@ -28,9 +28,9 @@ class Cookie_helper_test extends CI_TestCase { { $_COOKIE['foo'] = 'bar'; - $security = new Mock_Core_Security(); + $security = new Mock_Core_Security('UTF-8'); $input_cls = $this->ci_core_class('input'); - $this->ci_instance_var('input', new Mock_Core_Input($security)); + $this->ci_instance_var('input', new CI_Input($security)); $this->assertEquals('bar', get_cookie('foo', FALSE)); $this->assertEquals('bar', get_cookie('foo', TRUE)); diff --git a/tests/codeigniter/helpers/security_helper_test.php b/tests/codeigniter/helpers/security_helper_test.php index ab05d57ba..d7e3f4734 100644 --- a/tests/codeigniter/helpers/security_helper_test.php +++ b/tests/codeigniter/helpers/security_helper_test.php @@ -6,7 +6,7 @@ class Security_helper_tests extends CI_TestCase { { $this->helper('security'); $obj = new stdClass; - $obj->security = new Mock_Core_Security(); + $obj->security = new Mock_Core_Security('UTF-8'); $this->ci_instance($obj); } diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 5b7830dd8..edbe9da4a 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -13,8 +13,8 @@ class Form_validation_test extends CI_TestCase { // Same applies for lang $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); - $security = new Mock_Core_Security(); - $input = new Mock_Core_Input($security); + $security = new Mock_Core_Security('UTF-8'); + $input = new CI_Input($security); $this->ci_instance_var('lang', $lang); $this->ci_instance_var('load', $loader); diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 76a4fcc98..840df076a 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -37,7 +37,8 @@ return; $ci = $this->ci_instance(); $ldr = $this->ci_core_class('load'); $ci->load = new $ldr(); - $ci->input = new Mock_Core_Input(NULL, NULL); + $security = new Mock_Core_Security('UTF-8'); + $ci->input = new CI_Input($security); // Make sure string helper is available $this->ci_vfs_clone('system/helpers/string_helper.php'); @@ -437,4 +438,4 @@ return; $this->assertNull($this->session->native->userdata($key)); } -} \ No newline at end of file +} diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 8bac597b3..74a7d2c22 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -6,7 +6,7 @@ class Upload_test extends CI_TestCase { { $ci = $this->ci_instance(); $ci->upload = new CI_Upload(); - $ci->security = new Mock_Core_Security(); + $ci->security = new Mock_Core_Security('UTF-8'); $ci->lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load', 'line'))->getMock(); $ci->lang->expects($this->any())->method('line')->will($this->returnValue(FALSE)); $this->upload = $ci->upload; diff --git a/tests/mocks/core/input.php b/tests/mocks/core/input.php deleted file mode 100644 index 6f6a91365..000000000 --- a/tests/mocks/core/input.php +++ /dev/null @@ -1,30 +0,0 @@ -_enable_csrf = (config_item('csrf_protection') === TRUE); - $this->security = $security; - } - - public function fetch_from_array($array, $index = '', $xss_clean = FALSE) - { - return parent::_fetch_from_array($array, $index, $xss_clean); - } - - public function __set($name, $value) - { - if ($name === 'ip_address') - { - $this->ip_address = $value; - } - } -} -- cgit v1.2.3-24-g4f1b From 2ab1c1902711c8b0caf5c3e8f2fa825d72f6755d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 4 Jan 2017 15:26:35 +0200 Subject: Fix an XSS vulnerability --- tests/codeigniter/core/Security_test.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/codeigniter/core/Security_test.php b/tests/codeigniter/core/Security_test.php index cbf0285ec..4c54ec9fa 100644 --- a/tests/codeigniter/core/Security_test.php +++ b/tests/codeigniter/core/Security_test.php @@ -154,6 +154,11 @@ class Security_test extends CI_TestCase { 'on=">"x onerror="alert(1)">', $this->security->xss_clean('on=">"x onerror="alert(1)">') ); + + $this->assertEquals( + "\n><!-\n