blob: 48628d2e5ce345220a570410259e26773b4c3a6f [file] [log] [blame]
tiyowana83f0632012-03-16 23:52:43 +04001<?php
2
Andrey Andreev99b782d2012-06-09 22:24:46 +03003class Form_helper_test extends CI_TestCase
tiyowana83f0632012-03-16 23:52:43 +04004{
dchill427ecc5cd2012-10-12 16:25:51 -04005 public function set_up()
6 {
7 $this->helper('form');
8 }
9
tiyowana83f0632012-03-16 23:52:43 +040010 public function test_form_hidden()
Andrey Andreev99b782d2012-06-09 22:24:46 +030011 {
tiyowana83f0632012-03-16 23:52:43 +040012 $expected = <<<EOH
13
14<input type="hidden" name="username" value="johndoe" />
15
16EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030017
tiyowana83f0632012-03-16 23:52:43 +040018 $this->assertEquals($expected, form_hidden('username', 'johndoe'));
19 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030020
tiyowana83f0632012-03-16 23:52:43 +040021 public function test_form_input()
22 {
23 $expected = <<<EOH
24<input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%" />
25
26EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030027
tiyowana83f0632012-03-16 23:52:43 +040028 $data = array(
29 'name' => 'username',
30 'id' => 'username',
31 'value' => 'johndoe',
32 'maxlength' => '100',
33 'size' => '50',
34 'style' => 'width:50%',
35 );
36
37 $this->assertEquals($expected, form_input($data));
38 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030039
tiyowana83f0632012-03-16 23:52:43 +040040 public function test_form_password()
Andrey Andreev99b782d2012-06-09 22:24:46 +030041 {
tiyowana83f0632012-03-16 23:52:43 +040042 $expected = <<<EOH
43<input type="password" name="password" value="" />
44
45EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030046
tiyowana83f0632012-03-16 23:52:43 +040047 $this->assertEquals($expected, form_password('password'));
48 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030049
tiyowana83f0632012-03-16 23:52:43 +040050 public function test_form_upload()
Andrey Andreev99b782d2012-06-09 22:24:46 +030051 {
tiyowana83f0632012-03-16 23:52:43 +040052 $expected = <<<EOH
53<input type="file" name="attachment" value="" />
54
55EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030056
tiyowana83f0632012-03-16 23:52:43 +040057 $this->assertEquals($expected, form_upload('attachment'));
58 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030059
tiyowana83f0632012-03-16 23:52:43 +040060 public function test_form_textarea()
Andrey Andreev99b782d2012-06-09 22:24:46 +030061 {
tiyowana83f0632012-03-16 23:52:43 +040062 $expected = <<<EOH
63<textarea name="notes" cols="40" rows="10" >Notes</textarea>
64
65EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030066
tiyowana83f0632012-03-16 23:52:43 +040067 $this->assertEquals($expected, form_textarea('notes', 'Notes'));
68 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030069
tiyowana83f0632012-03-16 23:52:43 +040070 public function test_form_dropdown()
71 {
72 $expected = <<<EOH
73<select name="shirts">
74<option value="small">Small Shirt</option>
75<option value="med">Medium Shirt</option>
76<option value="large" selected="selected">Large Shirt</option>
77<option value="xlarge">Extra Large Shirt</option>
78</select>
79
80EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +030081
tiyowana83f0632012-03-16 23:52:43 +040082 $options = array(
Andrey Andreev99b782d2012-06-09 22:24:46 +030083 'small' => 'Small Shirt',
84 'med' => 'Medium Shirt',
85 'large' => 'Large Shirt',
86 'xlarge' => 'Extra Large Shirt',
tiyowana83f0632012-03-16 23:52:43 +040087 );
Andrey Andreev99b782d2012-06-09 22:24:46 +030088
tiyowana83f0632012-03-16 23:52:43 +040089 $this->assertEquals($expected, form_dropdown('shirts', $options, 'large'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030090
tiyowana83f0632012-03-16 23:52:43 +040091 $expected = <<<EOH
92<select name="shirts" multiple="multiple">
93<option value="small" selected="selected">Small Shirt</option>
94<option value="med">Medium Shirt</option>
95<option value="large" selected="selected">Large Shirt</option>
96<option value="xlarge">Extra Large Shirt</option>
97</select>
98
99EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300100
tiyowana83f0632012-03-16 23:52:43 +0400101 $shirts_on_sale = array('small', 'large');
Andrey Andreev99b782d2012-06-09 22:24:46 +0300102
tiyowana83f0632012-03-16 23:52:43 +0400103 $this->assertEquals($expected, form_dropdown('shirts', $options, $shirts_on_sale));
Andrey Andreev99b782d2012-06-09 22:24:46 +0300104
tiyowana83f0632012-03-16 23:52:43 +0400105 $options = array(
106 'Swedish Cars' => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300107 'volvo' => 'Volvo',
108 'saab' => 'Saab'
tiyowana83f0632012-03-16 23:52:43 +0400109 ),
110 'German Cars' => array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300111 'mercedes' => 'Mercedes',
112 'audi' => 'Audi'
tiyowana83f0632012-03-16 23:52:43 +0400113 )
114 );
Andrey Andreev99b782d2012-06-09 22:24:46 +0300115
tiyowana83f0632012-03-16 23:52:43 +0400116 $expected = <<<EOH
117<select name="cars" multiple="multiple">
118<optgroup label="Swedish Cars">
119<option value="volvo" selected="selected">Volvo</option>
120<option value="saab">Saab</option>
121</optgroup>
122<optgroup label="German Cars">
123<option value="mercedes">Mercedes</option>
124<option value="audi" selected="selected">Audi</option>
125</optgroup>
126</select>
127
128EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300129
130 $this->assertEquals($expected, form_dropdown('cars', $options, array('volvo', 'audi')));
tiyowana83f0632012-03-16 23:52:43 +0400131 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300132
tiyowana83f0632012-03-16 23:52:43 +0400133 public function test_form_multiselect()
134 {
135 $expected = <<<EOH
136<select name="shirts[]" multiple="multiple">
137<option value="small">Small Shirt</option>
138<option value="med" selected="selected">Medium Shirt</option>
139<option value="large" selected="selected">Large Shirt</option>
140<option value="xlarge">Extra Large Shirt</option>
141</select>
142
143EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300144
tiyowana83f0632012-03-16 23:52:43 +0400145 $options = array(
Andrey Andreev99b782d2012-06-09 22:24:46 +0300146 'small' => 'Small Shirt',
147 'med' => 'Medium Shirt',
148 'large' => 'Large Shirt',
149 'xlarge' => 'Extra Large Shirt',
150 );
151
tiyowana83f0632012-03-16 23:52:43 +0400152 $this->assertEquals($expected, form_multiselect('shirts[]', $options, array('med', 'large')));
153 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300154
tiyowana83f0632012-03-16 23:52:43 +0400155 public function test_form_fieldset()
156 {
157 $expected = <<<EOH
158<fieldset>
159<legend>Address Information</legend>
160
161EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300162
tiyowana83f0632012-03-16 23:52:43 +0400163 $this->assertEquals($expected, form_fieldset('Address Information'));
164 }
165
166 public function test_form_fieldset_close()
167 {
168 $expected = <<<EOH
169</fieldset></div></div>
170EOH;
Andrey Andreev99b782d2012-06-09 22:24:46 +0300171
tiyowana83f0632012-03-16 23:52:43 +0400172 $this->assertEquals($expected, form_fieldset_close('</div></div>'));
173 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300174
tiyowana83f0632012-03-16 23:52:43 +0400175 public function test_form_checkbox()
176 {
177 $expected = <<<EOH
178<input type="checkbox" name="newsletter" value="accept" checked="checked" />
179
180EOH;
181
182 $this->assertEquals($expected, form_checkbox('newsletter', 'accept', TRUE));
183 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300184
tiyowana83f0632012-03-16 23:52:43 +0400185 public function test_form_radio()
186 {
187 $expected = <<<EOH
188<input type="radio" name="newsletter" value="accept" checked="checked" />
189
190EOH;
191
192 $this->assertEquals($expected, form_radio('newsletter', 'accept', TRUE));
193 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300194
tiyowana83f0632012-03-16 23:52:43 +0400195 public function test_form_submit()
196 {
197 $expected = <<<EOH
198<input type="submit" name="mysubmit" value="Submit Post!" />
199
200EOH;
201
202 $this->assertEquals($expected, form_submit('mysubmit', 'Submit Post!'));
203 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300204
tiyowana83f0632012-03-16 23:52:43 +0400205 public function test_form_label()
206 {
207 $expected = <<<EOH
208<label for="username">What is your Name</label>
209EOH;
210
211 $this->assertEquals($expected, form_label('What is your Name', 'username'));
212 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300213
tiyowana83f0632012-03-16 23:52:43 +0400214 public function test_form_reset()
215 {
216 $expected = <<<EOH
217<input type="reset" name="myreset" value="Reset" />
218
219EOH;
220
221 $this->assertEquals($expected, form_reset('myreset', 'Reset'));
222 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300223
tiyowana83f0632012-03-16 23:52:43 +0400224 public function test_form_button()
225 {
226 $expected = <<<EOH
227<button name="name" type="button" >content</button>
228
229EOH;
230
Andrey Andreev99b782d2012-06-09 22:24:46 +0300231 $this->assertEquals($expected, form_button('name', 'content'));
tiyowana83f0632012-03-16 23:52:43 +0400232 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300233
tiyowana83f0632012-03-16 23:52:43 +0400234 public function test_form_close()
235 {
236 $expected = <<<EOH
237</form></div></div>
238EOH;
239
240 $this->assertEquals($expected, form_close('</div></div>'));
241 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300242
tiyowana83f0632012-03-16 23:52:43 +0400243 public function test_form_prep()
244 {
Andrey Andreev99b782d2012-06-09 22:24:46 +0300245 $expected = 'Here is a string containing &quot;quoted&quot; text.';
246
tiyowana83f0632012-03-16 23:52:43 +0400247 $this->assertEquals($expected, form_prep('Here is a string containing "quoted" text.'));
248 }
Andrey Andreev99b782d2012-06-09 22:24:46 +0300249
tiyowana83f0632012-03-16 23:52:43 +0400250}
251
252/* End of file form_helper_test.php */