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