From 74ffd17ab06327ca62ddfe28a186cae7ba6bd459 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 00:41:03 +0300 Subject: Deprecated form helper function form_prep(). This function has been broken for YEARS and it's value-caching logic has only introduced various problems. We have html_escape() since CI 2.1.0 which is a perfect replacement, so it should be used instead. Fixes #228 & #1630 --- tests/codeigniter/core/Common_test.php | 18 ++++++++---- tests/codeigniter/helpers/form_helper_test.php | 39 +++++++++++++++++++++----- 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Common_test.php b/tests/codeigniter/core/Common_test.php index 27d48efc2..999b49cb3 100644 --- a/tests/codeigniter/core/Common_test.php +++ b/tests/codeigniter/core/Common_test.php @@ -2,8 +2,6 @@ class Common_test extends CI_TestCase { - // ------------------------------------------------------------------------ - public function test_is_php() { $this->assertEquals(TRUE, is_php('1.2.0')); @@ -16,12 +14,12 @@ class Common_test extends CI_TestCase { { $this->assertEquals(' class="foo" id="bar"', _stringify_attributes(array('class' => 'foo', 'id' => 'bar'))); - $atts = new Stdclass; + $atts = new stdClass; $atts->class = 'foo'; $atts->id = 'bar'; $this->assertEquals(' class="foo" id="bar"', _stringify_attributes($atts)); - $atts = new Stdclass; + $atts = new stdClass; $this->assertEquals('', _stringify_attributes($atts)); $this->assertEquals(' class="foo" id="bar"', _stringify_attributes('class="foo" id="bar"')); @@ -35,10 +33,20 @@ class Common_test extends CI_TestCase { { $this->assertEquals('width=800,height=600', _stringify_attributes(array('width' => '800', 'height' => '600'), TRUE)); - $atts = new Stdclass; + $atts = new stdClass; $atts->width = 800; $atts->height = 600; $this->assertEquals('width=800,height=600', _stringify_attributes($atts, TRUE)); } + // ------------------------------------------------------------------------ + + public function test_html_escape() + { + $this->assertEquals( + html_escape('Here is a string containing "quoted" text.'), + 'Here is a string containing "quoted" text.' + ); + } + } \ No newline at end of file diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php index 48628d2e5..03278581d 100644 --- a/tests/codeigniter/helpers/form_helper_test.php +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -7,6 +7,8 @@ class Form_helper_test extends CI_TestCase $this->helper('form'); } + // ------------------------------------------------------------------------ + public function test_form_hidden() { $expected = <<assertEquals($expected, form_hidden('username', 'johndoe')); } + // ------------------------------------------------------------------------ + public function test_form_input() { $expected = <<assertEquals($expected, form_input($data)); } + // ------------------------------------------------------------------------ + public function test_form_password() { $expected = <<assertEquals($expected, form_password('password')); } + // ------------------------------------------------------------------------ + public function test_form_upload() { $expected = <<assertEquals($expected, form_upload('attachment')); } + // ------------------------------------------------------------------------ + public function test_form_textarea() { $expected = <<assertEquals($expected, form_textarea('notes', 'Notes')); } + // ------------------------------------------------------------------------ + public function test_form_dropdown() { $expected = <<assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); } + // ------------------------------------------------------------------------ + public function test_form_multiselect() { $expected = <<assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); } + // ------------------------------------------------------------------------ + public function test_form_fieldset() { $expected = <<assertEquals($expected, form_fieldset('Address Information')); } + // ------------------------------------------------------------------------ + public function test_form_fieldset_close() { $expected = <<assertEquals($expected, form_fieldset_close('')); } + // ------------------------------------------------------------------------ + public function test_form_checkbox() { $expected = <<assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); } + // ------------------------------------------------------------------------ + public function test_form_radio() { $expected = <<assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); } + // ------------------------------------------------------------------------ + public function test_form_submit() { $expected = <<assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); } + // ------------------------------------------------------------------------ + public function test_form_label() { $expected = <<assertEquals($expected, form_label('What is your Name', 'username')); } + // ------------------------------------------------------------------------ + public function test_form_reset() { $expected = <<assertEquals($expected, form_reset('myreset', 'Reset')); } + // ------------------------------------------------------------------------ + public function test_form_button() { $expected = <<assertEquals($expected, form_button('name', 'content')); } + // ------------------------------------------------------------------------ + public function test_form_close() { $expected = <<assertEquals($expected, form_close('')); } - public function test_form_prep() - { - $expected = 'Here is a string containing "quoted" text.'; - - $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); - } - } /* End of file form_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 5232ba07752ffa783d03754c3a869d9f73ccae69 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 15:25:05 +0300 Subject: Docblock improvements to the Config library and remove CI_Config::_assign_to_config() Existance of _assign_to_config() is pointless as this method consists just of a foreach calling CI_Config::set_item() and is only called by CodeIgniter.php - moved that foreach() in there instead. --- tests/codeigniter/core/Config_test.php | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Config_test.php b/tests/codeigniter/core/Config_test.php index d652a625e..be426d070 100644 --- a/tests/codeigniter/core/Config_test.php +++ b/tests/codeigniter/core/Config_test.php @@ -9,7 +9,7 @@ class Config_test extends CI_TestCase { // set predictable config values $this->cfg = array( 'index_page' => 'index.php', - 'base_url' => 'http://example.com/', + 'base_url' => 'http://example.com/', 'subclass_prefix' => 'MY_' ); $this->ci_set_config($this->cfg); @@ -38,7 +38,6 @@ class Config_test extends CI_TestCase { $this->assertFalse($this->config->item('not_yet_set')); $this->config->set_item('not_yet_set', 'is set'); - $this->assertEquals('is set', $this->config->item('not_yet_set')); } @@ -50,7 +49,6 @@ class Config_test extends CI_TestCase { $this->assertFalse($this->config->slash_item('no_good_item')); $this->assertEquals($this->cfg['base_url'], $this->config->slash_item('base_url')); - $this->assertEquals($this->cfg['subclass_prefix'].'/', $this->config->slash_item('subclass_prefix')); } @@ -124,7 +122,7 @@ class Config_test extends CI_TestCase { $q_string = $this->config->item('enable_query_strings'); $this->config->set_item('enable_query_strings', FALSE); - $uri= 'test'; + $uri = 'test'; $uri2 = '1'; $this->assertEquals($index_page.'/'.$uri, $this->config->site_url($uri)); $this->assertEquals($index_page.'/'.$uri.'/'.$uri2, $this->config->site_url(array($uri, $uri2))); @@ -137,7 +135,6 @@ class Config_test extends CI_TestCase { $this->assertEquals($index_page.'/'.$uri.$suffix.'?'.$arg, $this->config->site_url($uri.'?'.$arg)); $this->config->set_item('url_suffix', FALSE); - $this->config->set_item('enable_query_strings', TRUE); $this->assertEquals($index_page.'?'.$uri, $this->config->site_url($uri)); @@ -233,22 +230,4 @@ class Config_test extends CI_TestCase { $this->assertNull($this->config->load($file)); } - // -------------------------------------------------------------------- - - public function test_assign_to_config() - { - $key1 = 'test'; - $key2 = '1'; - $val1 = 'foo'; - $val2 = 'bar'; - $cfg = array( - $key1 => $val1, - $key2 => $val2 - ); - - $this->assertNull($this->config->_assign_to_config($cfg)); - $this->assertEquals($val1, $this->config->item($key1)); - $this->assertEquals($val2, $this->config->item($key2)); - } - } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9aced4a0b04632b6e5737fd11de9a10fad87653d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 27 Oct 2012 18:04:40 +0300 Subject: Fix Loader tests --- tests/codeigniter/core/Loader_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index f7c338a20..816587a49 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -36,7 +36,7 @@ class Loader_test extends CI_TestCase { $this->assertAttributeInstanceOf($class, $lib, $this->ci_obj); // Test no lib given - $this->assertFalse($this->load->library()); + $this->assertNull($this->load->library()); // Test a string given to params $this->assertNull($this->load->library($lib, ' ')); @@ -450,7 +450,7 @@ class Loader_test extends CI_TestCase { public function test_load_config() { $cfg = 'someconfig'; - $this->assertNull($this->load->config($cfg, FALSE)); + $this->assertTrue($this->load->config($cfg, FALSE)); $this->assertContains($cfg, $this->ci_obj->config->loaded); } -- cgit v1.2.3-24-g4f1b