blob: 1a30ed993fa2b318742d68b0edc141a7b6f8889a [file] [log] [blame]
tiyowana83f0632012-03-16 23:52:43 +04001<?php
2
3require BASEPATH . 'core/Common.php';
4require BASEPATH . 'helpers/form_helper.php';
5
Andrey Andreev99b782d2012-06-09 22:24:46 +03006class Form_helper_test extends CI_TestCase
tiyowana83f0632012-03-16 23:52:43 +04007{
8 public function test_form_hidden()
Andrey Andreev99b782d2012-06-09 22:24:46 +03009 {
tiyowana83f0632012-03-16 23:52:43 +040010 $expected = <<<EOH
11
12<input type="hidden" name="username" value="johndoe" />
13
14EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030015
tiyowana83f0632012-03-16 23:52:43 +040016 $this->assertEquals($expected, form_hidden('username', 'johndoe'));
17 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030018
tiyowana83f0632012-03-16 23:52:43 +040019 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
24EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030025
tiyowana83f0632012-03-16 23:52:43 +040026 $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 Andreev99b782d2012-06-09 22:24:46 +030037
tiyowana83f0632012-03-16 23:52:43 +040038 public function test_form_password()
Andrey Andreev99b782d2012-06-09 22:24:46 +030039 {
tiyowana83f0632012-03-16 23:52:43 +040040 $expected = <<<EOH
41<input type="password" name="password" value="" />
42
43EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030044
tiyowana83f0632012-03-16 23:52:43 +040045 $this->assertEquals($expected, form_password('password'));
46 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030047
tiyowana83f0632012-03-16 23:52:43 +040048 public function test_form_upload()
Andrey Andreev99b782d2012-06-09 22:24:46 +030049 {
tiyowana83f0632012-03-16 23:52:43 +040050 $expected = <<<EOH
51<input type="file" name="attachment" value="" />
52
53EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030054
tiyowana83f0632012-03-16 23:52:43 +040055 $this->assertEquals($expected, form_upload('attachment'));
56 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030057
tiyowana83f0632012-03-16 23:52:43 +040058 public function test_form_textarea()
Andrey Andreev99b782d2012-06-09 22:24:46 +030059 {
tiyowana83f0632012-03-16 23:52:43 +040060 $expected = <<<EOH
61<textarea name="notes" cols="40" rows="10" >Notes</textarea>
62
63EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030064
tiyowana83f0632012-03-16 23:52:43 +040065 $this->assertEquals($expected, form_textarea('notes', 'Notes'));
66 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030067
tiyowana83f0632012-03-16 23:52:43 +040068 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
78EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030079
tiyowana83f0632012-03-16 23:52:43 +040080 $options = array(
Andrey Andreev99b782d2012-06-09 22:24:46 +030081 'small' => 'Small Shirt',
82 'med' => 'Medium Shirt',
83 'large' => 'Large Shirt',
84 'xlarge' => 'Extra Large Shirt',
tiyowana83f0632012-03-16 23:52:43 +040085 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030086
tiyowana83f0632012-03-16 23:52:43 +040087 $this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030088
tiyowana83f0632012-03-16 23:52:43 +040089 $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
97EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030098
tiyowana83f0632012-03-16 23:52:43 +040099 $shirts_on_sale = array('small', 'large');
Andrey Andreev99b782d2012-06-09 22:24:46 +0300100
tiyowana83f0632012-03-16 23:52:43 +0400101 $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale));
Andrey Andreev99b782d2012-06-09 22:24:46 +0300102
tiyowana83f0632012-03-16 23:52:43 +0400103 $options = array(
104 'Swedish Cars' => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300105 'volvo' => 'Volvo',
106 'saab' => 'Saab'
tiyowana83f0632012-03-16 23:52:43 +0400107 ),
108 'German Cars' => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300109 'mercedes' => 'Mercedes',
110 'audi' => 'Audi'
tiyowana83f0632012-03-16 23:52:43 +0400111 )
112 );
Andrey Andreev99b782d2012-06-09 22:24:46 +0300113
tiyowana83f0632012-03-16 23:52:43 +0400114 $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
126EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300127
128 $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
tiyowana83f0632012-03-16 23:52:43 +0400129 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300130
tiyowana83f0632012-03-16 23:52:43 +0400131 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
141EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300142
tiyowana83f0632012-03-16 23:52:43 +0400143 $options = array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300144 'small' => 'Small Shirt',
145 'med' => 'Medium Shirt',
146 'large' => 'Large Shirt',
147 'xlarge' => 'Extra Large Shirt',
148 );
149
tiyowana83f0632012-03-16 23:52:43 +0400150 $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large')));
151 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300152
tiyowana83f0632012-03-16 23:52:43 +0400153 public function test_form_fieldset()
154 {
155 $expected = <<<EOH
156<fieldset>
157<legend>Address Information</legend>
158
159EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300160
tiyowana83f0632012-03-16 23:52:43 +0400161 $this->assertEquals($expected, form_fieldset('Address Information'));
162 }
163
164 public function test_form_fieldset_close()
165 {
166 $expected = <<<EOH
167</fieldset></div></div>
168EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300169
tiyowana83f0632012-03-16 23:52:43 +0400170 $this->assertEquals($expected, form_fieldset_close('</div></div>'));
171 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300172
tiyowana83f0632012-03-16 23:52:43 +0400173 public function test_form_checkbox()
174 {
175 $expected = <<<EOH
176<input type="checkbox" name="newsletter" value="accept" checked="checked" />
177
178EOH;
179
180 $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
181 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300182
tiyowana83f0632012-03-16 23:52:43 +0400183 public function test_form_radio()
184 {
185 $expected = <<<EOH
186<input type="radio" name="newsletter" value="accept" checked="checked" />
187
188EOH;
189
190 $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
191 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300192
tiyowana83f0632012-03-16 23:52:43 +0400193 public function test_form_submit()
194 {
195 $expected = <<<EOH
196<input type="submit" name="mysubmit" value="Submit Post!" />
197
198EOH;
199
200 $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
201 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300202
tiyowana83f0632012-03-16 23:52:43 +0400203 public function test_form_label()
204 {
205 $expected = <<<EOH
206<label for="username">What is your Name</label>
207EOH;
208
209 $this->assertEquals($expected, form_label('What is your Name', 'username'));
210 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300211
tiyowana83f0632012-03-16 23:52:43 +0400212 public function test_form_reset()
213 {
214 $expected = <<<EOH
215<input type="reset" name="myreset" value="Reset" />
216
217EOH;
218
219 $this->assertEquals($expected, form_reset('myreset', 'Reset'));
220 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300221
tiyowana83f0632012-03-16 23:52:43 +0400222 public function test_form_button()
223 {
224 $expected = <<<EOH
225<button name="name" type="button" >content</button>
226
227EOH;
228
Andrey Andreev99b782d2012-06-09 22:24:46 +0300229 $this->assertEquals($expected, form_button('name', 'content'));
tiyowana83f0632012-03-16 23:52:43 +0400230 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300231
tiyowana83f0632012-03-16 23:52:43 +0400232 public function test_form_close()
233 {
234 $expected = <<<EOH
235</form></div></div>
236EOH;
237
238 $this->assertEquals($expected, form_close('</div></div>'));
239 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300240
tiyowana83f0632012-03-16 23:52:43 +0400241 public function test_form_prep()
242 {
Andrey Andreev99b782d2012-06-09 22:24:46 +0300243 $expected = 'Here is a string containing &quot;quoted&quot; text.';
244
tiyowana83f0632012-03-16 23:52:43 +0400245 $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.'));
246 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300247
tiyowana83f0632012-03-16 23:52:43 +0400248}
249
250/* End of file form_helper_test.php */