@@ -73,6 +73,11 @@ public function testIsMultiple()
73
73
$ field = new ChoiceFormField ($ node );
74
74
75
75
$ this ->assertTrue ($ field ->isMultiple (), '->isMultiple() returns true for selects with the multiple attribute ' );
76
+
77
+ $ node = $ this ->createNode ('select ' , '' , array ('multiple ' => '' ));
78
+ $ field = new ChoiceFormField ($ node );
79
+
80
+ $ this ->assertTrue ($ field ->isMultiple (), '->isMultiple() returns true for selects with an empty multiple attribute ' );
76
81
}
77
82
78
83
public function testSelects ()
@@ -107,6 +112,14 @@ public function testSelects()
107
112
}
108
113
}
109
114
115
+ public function testSelectWithEmptyBooleanAttribute ()
116
+ {
117
+ $ node = $ this ->createSelectNode (array ('foo ' => false , 'bar ' => true ), array (), '' );
118
+ $ field = new ChoiceFormField ($ node );
119
+
120
+ $ this ->assertEquals ('bar ' , $ field ->getValue ());
121
+ }
122
+
110
123
public function testMultipleSelects ()
111
124
{
112
125
$ node = $ this ->createSelectNode (array ('foo ' => false , 'bar ' => false ), array ('multiple ' => 'multiple ' ));
@@ -166,12 +179,25 @@ public function testRadioButtons()
166
179
}
167
180
}
168
181
182
+ public function testRadioButtonsWithEmptyBooleanAttribute ()
183
+ {
184
+ $ node = $ this ->createNode ('input ' , '' , array ('type ' => 'radio ' , 'name ' => 'name ' , 'value ' => 'foo ' ));
185
+ $ field = new ChoiceFormField ($ node );
186
+ $ node = $ this ->createNode ('input ' , '' , array ('type ' => 'radio ' , 'name ' => 'name ' , 'value ' => 'bar ' , 'checked ' => '' ));
187
+ $ field ->addChoice ($ node );
188
+
189
+ $ this ->assertTrue ($ field ->hasValue (), '->hasValue() returns true when a radio button is selected ' );
190
+ $ this ->assertEquals ('bar ' , $ field ->getValue (), '->getValue() returns the value attribute of the selected radio button ' );
191
+ }
192
+
169
193
public function testRadioButtonIsDisabled ()
170
194
{
171
195
$ node = $ this ->createNode ('input ' , '' , array ('type ' => 'radio ' , 'name ' => 'name ' , 'value ' => 'foo ' , 'disabled ' => 'disabled ' ));
172
196
$ field = new ChoiceFormField ($ node );
173
197
$ node = $ this ->createNode ('input ' , '' , array ('type ' => 'radio ' , 'name ' => 'name ' , 'value ' => 'bar ' ));
174
198
$ field ->addChoice ($ node );
199
+ $ node = $ this ->createNode ('input ' , '' , array ('type ' => 'radio ' , 'name ' => 'name ' , 'value ' => 'baz ' , 'disabled ' => '' ));
200
+ $ field ->addChoice ($ node );
175
201
176
202
$ field ->select ('foo ' );
177
203
$ this ->assertEquals ('foo ' , $ field ->getValue (), '->getValue() returns the value attribute of the selected radio button ' );
@@ -180,6 +206,10 @@ public function testRadioButtonIsDisabled()
180
206
$ field ->select ('bar ' );
181
207
$ this ->assertEquals ('bar ' , $ field ->getValue (), '->getValue() returns the value attribute of the selected radio button ' );
182
208
$ this ->assertFalse ($ field ->isDisabled ());
209
+
210
+ $ field ->select ('baz ' );
211
+ $ this ->assertEquals ('baz ' , $ field ->getValue (), '->getValue() returns the value attribute of the selected radio button ' );
212
+ $ this ->assertTrue ($ field ->isDisabled ());
183
213
}
184
214
185
215
public function testCheckboxes ()
@@ -225,6 +255,15 @@ public function testCheckboxes()
225
255
}
226
256
}
227
257
258
+ public function testCheckboxWithEmptyBooleanAttribute ()
259
+ {
260
+ $ node = $ this ->createNode ('input ' , '' , array ('type ' => 'checkbox ' , 'name ' => 'name ' , 'value ' => 'foo ' , 'checked ' => '' ));
261
+ $ field = new ChoiceFormField ($ node );
262
+
263
+ $ this ->assertTrue ($ field ->hasValue (), '->hasValue() returns true when the checkbox is checked ' );
264
+ $ this ->assertEquals ('foo ' , $ field ->getValue ());
265
+ }
266
+
228
267
public function testTick ()
229
268
{
230
269
$ node = $ this ->createSelectNode (array ('foo ' => false , 'bar ' => false ));
@@ -284,7 +323,7 @@ public function testOptionWithNoValue()
284
323
$ this ->assertEquals ('foo ' , $ field ->getValue (), '->select() changes the selected option ' );
285
324
}
286
325
287
- protected function createSelectNode ($ options , $ attributes = array ())
326
+ protected function createSelectNode ($ options , $ attributes = array (), $ selectedAttrText = ' selected ' )
288
327
{
289
328
$ document = new \DOMDocument ();
290
329
$ node = $ document ->createElement ('select ' );
@@ -298,7 +337,7 @@ protected function createSelectNode($options, $attributes = array())
298
337
$ option = $ document ->createElement ('option ' , $ value );
299
338
$ option ->setAttribute ('value ' , $ value );
300
339
if ($ selected ) {
301
- $ option ->setAttribute ('selected ' , ' selected ' );
340
+ $ option ->setAttribute ('selected ' , $ selectedAttrText );
302
341
}
303
342
$ node ->appendChild ($ option );
304
343
}
0 commit comments