tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | require BASEPATH . 'core/Common.php'; |
| 4 | require BASEPATH . 'helpers/form_helper.php'; |
| 5 | |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 6 | class Form_helper_test extends CI_TestCase |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 7 | { |
| 8 | public function test_form_hidden() |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 9 | { |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 10 | $expected = <<<EOH |
| 11 | |
| 12 | <input type="hidden" name="username" value="johndoe" /> |
| 13 | |
| 14 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 15 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 16 | $this->assertEquals($expected, form_hidden('username', 'johndoe')); |
| 17 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 18 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 19 | public function test_form_input() |
| 20 | { |
| 21 | $expected = <<<EOH |
| 22 | <input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" /> |
| 23 | |
| 24 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 25 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 26 | $data = array( |
| 27 | 'name' => 'username', |
| 28 | 'id' => 'username', |
| 29 | 'value' => 'johndoe', |
| 30 | 'maxlength' => '100', |
| 31 | 'size' => '50', |
| 32 | 'style' => 'width:50%', |
| 33 | ); |
| 34 | |
| 35 | $this->assertEquals($expected, form_input($data)); |
| 36 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 37 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 38 | public function test_form_password() |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 39 | { |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 40 | $expected = <<<EOH |
| 41 | <input type="password" name="password" value="" /> |
| 42 | |
| 43 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 44 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 45 | $this->assertEquals($expected, form_password('password')); |
| 46 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 47 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 48 | public function test_form_upload() |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 49 | { |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 50 | $expected = <<<EOH |
| 51 | <input type="file" name="attachment" value="" /> |
| 52 | |
| 53 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 54 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 55 | $this->assertEquals($expected, form_upload('attachment')); |
| 56 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 57 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 58 | public function test_form_textarea() |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 59 | { |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 60 | $expected = <<<EOH |
| 61 | <textarea name="notes" cols="40" rows="10" >Notes</textarea> |
| 62 | |
| 63 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 64 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 65 | $this->assertEquals($expected, form_textarea('notes', 'Notes')); |
| 66 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 67 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 68 | public function test_form_dropdown() |
| 69 | { |
| 70 | $expected = <<<EOH |
| 71 | <select name="shirts"> |
| 72 | <option value="small">Small Shirt</option> |
| 73 | <option value="med">Medium Shirt</option> |
| 74 | <option value="large" selected="selected">Large Shirt</option> |
| 75 | <option value="xlarge">Extra Large Shirt</option> |
| 76 | </select> |
| 77 | |
| 78 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 79 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 80 | $options = array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 81 | 'small' => 'Small Shirt', |
| 82 | 'med' => 'Medium Shirt', |
| 83 | 'large' => 'Large Shirt', |
| 84 | 'xlarge' => 'Extra Large Shirt', |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 85 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 86 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 87 | $this->assertEquals($expected, form_dropdown('shirts', $options, 'large')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 88 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 89 | $expected = <<<EOH |
| 90 | <select name="shirts" multiple="multiple"> |
| 91 | <option value="small" selected="selected">Small Shirt</option> |
| 92 | <option value="med">Medium Shirt</option> |
| 93 | <option value="large" selected="selected">Large Shirt</option> |
| 94 | <option value="xlarge">Extra Large Shirt</option> |
| 95 | </select> |
| 96 | |
| 97 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 98 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 99 | $shirts_on_sale = array('small', 'large'); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 100 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 101 | $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 102 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 103 | $options = array( |
| 104 | 'Swedish Cars' => array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 105 | 'volvo' => 'Volvo', |
| 106 | 'saab' => 'Saab' |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 107 | ), |
| 108 | 'German Cars' => array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 109 | 'mercedes' => 'Mercedes', |
| 110 | 'audi' => 'Audi' |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 111 | ) |
| 112 | ); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 113 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 114 | $expected = <<<EOH |
| 115 | <select name="cars" multiple="multiple"> |
| 116 | <optgroup label="Swedish Cars"> |
| 117 | <option value="volvo" selected="selected">Volvo</option> |
| 118 | <option value="saab">Saab</option> |
| 119 | </optgroup> |
| 120 | <optgroup label="German Cars"> |
| 121 | <option value="mercedes">Mercedes</option> |
| 122 | <option value="audi" selected="selected">Audi</option> |
| 123 | </optgroup> |
| 124 | </select> |
| 125 | |
| 126 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 127 | |
| 128 | $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi'))); |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 129 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 130 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 131 | public function test_form_multiselect() |
| 132 | { |
| 133 | $expected = <<<EOH |
| 134 | <select name="shirts[]" multiple="multiple"> |
| 135 | <option value="small">Small Shirt</option> |
| 136 | <option value="med" selected="selected">Medium Shirt</option> |
| 137 | <option value="large" selected="selected">Large Shirt</option> |
| 138 | <option value="xlarge">Extra Large Shirt</option> |
| 139 | </select> |
| 140 | |
| 141 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 142 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 143 | $options = array( |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 144 | 'small' => 'Small Shirt', |
| 145 | 'med' => 'Medium Shirt', |
| 146 | 'large' => 'Large Shirt', |
| 147 | 'xlarge' => 'Extra Large Shirt', |
| 148 | ); |
| 149 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 150 | $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large'))); |
| 151 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 152 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 153 | public function test_form_fieldset() |
| 154 | { |
| 155 | $expected = <<<EOH |
| 156 | <fieldset> |
| 157 | <legend>Address Information</legend> |
| 158 | |
| 159 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 160 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 161 | $this->assertEquals($expected, form_fieldset('Address Information')); |
| 162 | } |
| 163 | |
| 164 | public function test_form_fieldset_close() |
| 165 | { |
| 166 | $expected = <<<EOH |
| 167 | </fieldset></div></div> |
| 168 | EOH; |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 169 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 170 | $this->assertEquals($expected, form_fieldset_close('</div></div>')); |
| 171 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 172 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 173 | public function test_form_checkbox() |
| 174 | { |
| 175 | $expected = <<<EOH |
| 176 | <input type="checkbox" name="newsletter" value="accept" checked="checked" /> |
| 177 | |
| 178 | EOH; |
| 179 | |
| 180 | $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE)); |
| 181 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 182 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 183 | public function test_form_radio() |
| 184 | { |
| 185 | $expected = <<<EOH |
| 186 | <input type="radio" name="newsletter" value="accept" checked="checked" /> |
| 187 | |
| 188 | EOH; |
| 189 | |
| 190 | $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE)); |
| 191 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 192 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 193 | public function test_form_submit() |
| 194 | { |
| 195 | $expected = <<<EOH |
| 196 | <input type="submit" name="mysubmit" value="Submit Post!" /> |
| 197 | |
| 198 | EOH; |
| 199 | |
| 200 | $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!')); |
| 201 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 202 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 203 | public function test_form_label() |
| 204 | { |
| 205 | $expected = <<<EOH |
| 206 | <label for="username">What is your Name</label> |
| 207 | EOH; |
| 208 | |
| 209 | $this->assertEquals($expected, form_label('What is your Name', 'username')); |
| 210 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 211 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 212 | public function test_form_reset() |
| 213 | { |
| 214 | $expected = <<<EOH |
| 215 | <input type="reset" name="myreset" value="Reset" /> |
| 216 | |
| 217 | EOH; |
| 218 | |
| 219 | $this->assertEquals($expected, form_reset('myreset', 'Reset')); |
| 220 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 221 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 222 | public function test_form_button() |
| 223 | { |
| 224 | $expected = <<<EOH |
| 225 | <button name="name" type="button" >content</button> |
| 226 | |
| 227 | EOH; |
| 228 | |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 229 | $this->assertEquals($expected, form_button('name', 'content')); |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 230 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 231 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 232 | public function test_form_close() |
| 233 | { |
| 234 | $expected = <<<EOH |
| 235 | </form></div></div> |
| 236 | EOH; |
| 237 | |
| 238 | $this->assertEquals($expected, form_close('</div></div>')); |
| 239 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 240 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 241 | public function test_form_prep() |
| 242 | { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 243 | $expected = 'Here is a string containing "quoted" text.'; |
| 244 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 245 | $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.')); |
| 246 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 247 | |
tiyowan | a83f063 | 2012-03-16 23:52:43 +0400 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* End of file form_helper_test.php */ |