From a83f063c2cebd50515b99e6ccab5afab4c958c06 Mon Sep 17 00:00:00 2001 From: tiyowan Date: Fri, 16 Mar 2012 23:52:43 +0400 Subject: Add unit tests for form_helper.php * Does not test form_open() and form_open_multipart() * Does not test set_value(), set_select(), set_checkbox() and set_radio() * Above are in progress and will be added once certain issues are resolved --- tests/codeigniter/helpers/form_helper_test.php | 252 +++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/codeigniter/helpers/form_helper_test.php (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/form_helper_test.php b/tests/codeigniter/helpers/form_helper_test.php new file mode 100644 index 000000000..80bace9d1 --- /dev/null +++ b/tests/codeigniter/helpers/form_helper_test.php @@ -0,0 +1,252 @@ + + +EOH; + + $this->assertEquals($expected, form_hidden('username', 'johndoe')); + } + + public function test_form_input() + { + $expected = << + +EOH; + + $data = array( + 'name' => 'username', + 'id' => 'username', + 'value' => 'johndoe', + 'maxlength' => '100', + 'size' => '50', + 'style' => 'width:50%', + ); + + $this->assertEquals($expected, form_input($data)); + } + + public function test_form_password() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_password('password')); + } + + public function test_form_upload() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_upload('attachment')); + } + + public function test_form_textarea() + { + $expected = <<Notes + +EOH; + + $this->assertEquals($expected, form_textarea('notes', 'Notes')); + } + + public function test_form_dropdown() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); + + $expected = << + + + + + + +EOH; + + $shirts_on_sale = array('small', 'large'); + + $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); + + $options = array( + 'Swedish Cars' => array( + 'volvo' => 'Volvo', + 'saab' => 'Saab' + ), + 'German Cars' => array( + 'mercedes' => 'Mercedes', + 'audi' => 'Audi' + ) + ); + + $expected = << + + + + + + + + + + +EOH; + + $cars_on_sale = array('volvo', 'audi'); + + $this->assertEquals($expected, form_dropdown('cars', $options, $cars_on_sale)); + + } + + public function test_form_multiselect() + { + $expected = << + + + + + + +EOH; + + $options = array( + 'small' => 'Small Shirt', + 'med' => 'Medium Shirt', + 'large' => 'Large Shirt', + 'xlarge' => 'Extra Large Shirt', + ); + + $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); + } + + public function test_form_fieldset() + { + $expected = << +Address Information + +EOH; + + $this->assertEquals($expected, form_fieldset('Address Information')); + } + + public function test_form_fieldset_close() + { + $expected = << +EOH; + + $this->assertEquals($expected, form_fieldset_close('')); + } + + public function test_form_checkbox() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); + } + + public function test_form_radio() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); + } + + public function test_form_submit() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); + } + + public function test_form_label() + { + $expected = <<What is your Name +EOH; + + $this->assertEquals($expected, form_label('What is your Name', 'username')); + } + + public function test_form_reset() + { + $expected = << + +EOH; + + $this->assertEquals($expected, form_reset('myreset', 'Reset')); + } + + public function test_form_button() + { + $expected = <<content + +EOH; + + $this->assertEquals($expected, form_button('name','content')); + } + + public function test_form_close() + { + $expected = << +EOH; + + $this->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 e1dc9ea4fcfd4983fa076b70fe631166a95d0b68 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Wed, 28 Mar 2012 16:49:49 +0700 Subject: Remove include or require declaration from all helpers test --- tests/codeigniter/helpers/array_helper_test.php | 10 ++++------ tests/codeigniter/helpers/date_helper_test.php | 10 +++++++--- tests/codeigniter/helpers/directory_helper_test.php | 9 ++++----- tests/codeigniter/helpers/email_helper_test.php | 10 ++++++---- tests/codeigniter/helpers/file_helper_test.php | 7 +++---- tests/codeigniter/helpers/html_helper_test.php | 8 +++++--- tests/codeigniter/helpers/inflector_helper_test.php | 6 ++++-- tests/codeigniter/helpers/number_helper_test.php | 7 +++---- tests/codeigniter/helpers/path_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/string_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/text_helper_test.php | 6 +++--- tests/codeigniter/helpers/url_helper_test.php | 9 ++++++--- tests/codeigniter/helpers/xml_helper_test.php | 8 +++++--- 13 files changed, 62 insertions(+), 46 deletions(-) (limited to 'tests/codeigniter/helpers') diff --git a/tests/codeigniter/helpers/array_helper_test.php b/tests/codeigniter/helpers/array_helper_test.php index 62559de83..9cd15960f 100644 --- a/tests/codeigniter/helpers/array_helper_test.php +++ b/tests/codeigniter/helpers/array_helper_test.php @@ -1,13 +1,11 @@ helper('array'); + $this->my_array = array( 'foo' => 'bar', 'sally' => 'jim', diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 662d16485..17d1ef21e 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -1,8 +1,12 @@ helper('date'); + } + // ------------------------------------------------------------------------ public function test_now_local() diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 3fae81b82..3937d2913 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -1,12 +1,11 @@ helper('directory'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/email_helper_test.php b/tests/codeigniter/helpers/email_helper_test.php index 7324e8109..a01f3d5af 100644 --- a/tests/codeigniter/helpers/email_helper_test.php +++ b/tests/codeigniter/helpers/email_helper_test.php @@ -1,10 +1,12 @@ helper('email'); + } -class Email_helper_test extends CI_TestCase -{ - public function test_valid_email() { $this->assertEquals(FALSE, valid_email('test')); diff --git a/tests/codeigniter/helpers/file_helper_test.php b/tests/codeigniter/helpers/file_helper_test.php index a596a0375..4b9c29485 100644 --- a/tests/codeigniter/helpers/file_helper_test.php +++ b/tests/codeigniter/helpers/file_helper_test.php @@ -1,12 +1,11 @@ helper('file'); + vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php index 553fc2bb1..28974b0f8 100644 --- a/tests/codeigniter/helpers/html_helper_test.php +++ b/tests/codeigniter/helpers/html_helper_test.php @@ -1,9 +1,11 @@ helper('html'); + } // ------------------------------------------------------------------------ diff --git a/tests/codeigniter/helpers/inflector_helper_test.php b/tests/codeigniter/helpers/inflector_helper_test.php index 472e28adb..9e9478711 100644 --- a/tests/codeigniter/helpers/inflector_helper_test.php +++ b/tests/codeigniter/helpers/inflector_helper_test.php @@ -1,9 +1,11 @@ helper('inflector'); + } public function test_singular() { diff --git a/tests/codeigniter/helpers/number_helper_test.php b/tests/codeigniter/helpers/number_helper_test.php index 3322b2475..4bb9a918a 100644 --- a/tests/codeigniter/helpers/number_helper_test.php +++ b/tests/codeigniter/helpers/number_helper_test.php @@ -1,12 +1,11 @@ helper('number'); + // Grab the core lang class $lang_cls = $this->ci_core_class('lang'); diff --git a/tests/codeigniter/helpers/path_helper_test.php b/tests/codeigniter/helpers/path_helper_test.php index 2e6cc6391..632f57501 100644 --- a/tests/codeigniter/helpers/path_helper_test.php +++ b/tests/codeigniter/helpers/path_helper_test.php @@ -1,9 +1,12 @@ helper('path'); + } -class Path_helper_test extends CI_TestCase -{ public function test_set_realpath() { $expected = getcwd() . DIRECTORY_SEPARATOR; diff --git a/tests/codeigniter/helpers/string_helper_test.php b/tests/codeigniter/helpers/string_helper_test.php index a884d6284..29c3d6594 100644 --- a/tests/codeigniter/helpers/string_helper_test.php +++ b/tests/codeigniter/helpers/string_helper_test.php @@ -1,9 +1,12 @@ helper('string'); + } -class String_helper_test extends CI_TestCase -{ public function test_strip_slashes() { $expected = array( diff --git a/tests/codeigniter/helpers/text_helper_test.php b/tests/codeigniter/helpers/text_helper_test.php index a0866e638..584066b0c 100644 --- a/tests/codeigniter/helpers/text_helper_test.php +++ b/tests/codeigniter/helpers/text_helper_test.php @@ -1,13 +1,13 @@ 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.'; } diff --git a/tests/codeigniter/helpers/url_helper_test.php b/tests/codeigniter/helpers/url_helper_test.php index 51a8cc7c0..c561809ce 100644 --- a/tests/codeigniter/helpers/url_helper_test.php +++ b/tests/codeigniter/helpers/url_helper_test.php @@ -1,9 +1,12 @@ helper('url'); + } -class Url_helper_test extends CI_TestCase -{ public function test_url_title() { $words = array( diff --git a/tests/codeigniter/helpers/xml_helper_test.php b/tests/codeigniter/helpers/xml_helper_test.php index 49f49e166..a83fef91e 100644 --- a/tests/codeigniter/helpers/xml_helper_test.php +++ b/tests/codeigniter/helpers/xml_helper_test.php @@ -1,9 +1,11 @@ helper('xml'); + } public function test_xml_convert() { -- cgit v1.2.3-24-g4f1b