|
@@ 132-170 (lines=39) @@
|
| 129 |
|
* |
| 130 |
|
* @return void |
| 131 |
|
*/ |
| 132 |
|
public function testGetInputValueArrayNoChecked() |
| 133 |
|
{ |
| 134 |
|
$formFieldCheckboxes = $this->getMock('Joomla\\Form\\Field_Checkboxes', array('getOptions')); |
| 135 |
|
|
| 136 |
|
$option1 = new \stdClass; |
| 137 |
|
$option1->value = 'red'; |
| 138 |
|
$option1->text = 'red'; |
| 139 |
|
|
| 140 |
|
$option2 = new \stdClass; |
| 141 |
|
$option2->value = 'blue'; |
| 142 |
|
$option2->text = 'blue'; |
| 143 |
|
|
| 144 |
|
$optionsReturn = array($option1, $option2); |
| 145 |
|
$formFieldCheckboxes->expects($this->any()) |
| 146 |
|
->method('getOptions') |
| 147 |
|
->will($this->returnValue($optionsReturn)); |
| 148 |
|
|
| 149 |
|
// Test with one value checked, no checked element |
| 150 |
|
$element = simplexml_load_string( |
| 151 |
|
'<field name="color" type="checkboxes"> |
| 152 |
|
<option value="red">red</option> |
| 153 |
|
<option value="blue">blue</option> |
| 154 |
|
</field>'); |
| 155 |
|
$valuearray = array('red'); |
| 156 |
|
TestHelper::setValue($formFieldCheckboxes, 'element', $element); |
| 157 |
|
TestHelper::setValue($formFieldCheckboxes, 'id', 'myTestId'); |
| 158 |
|
TestHelper::setValue($formFieldCheckboxes, 'value', $valuearray); |
| 159 |
|
TestHelper::setValue($formFieldCheckboxes, 'name', 'myTestName'); |
| 160 |
|
|
| 161 |
|
$fieldsetString = '<fieldset id="myTestId" class="checkboxes"><ul>' . |
| 162 |
|
'<li><input type="checkbox" id="myTestId0" name="myTestName" value="red" checked="checked"/><label for="myTestId0">red</label></li>' . |
| 163 |
|
'<li><input type="checkbox" id="myTestId1" name="myTestName" value="blue"/><label for="myTestId1">blue</label></li></ul></fieldset>'; |
| 164 |
|
|
| 165 |
|
$this->assertEquals( |
| 166 |
|
$fieldsetString, |
| 167 |
|
TestHelper::invoke($formFieldCheckboxes, 'getInput'), |
| 168 |
|
'The field with one value did not produce the right html' |
| 169 |
|
); |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
/** |
| 173 |
|
* Test the getInput method with no value and one value in checked. |
|
@@ 225-263 (lines=39) @@
|
| 222 |
|
* |
| 223 |
|
* @return void |
| 224 |
|
*/ |
| 225 |
|
public function testGetInputNoValueTwoChecked() |
| 226 |
|
{ |
| 227 |
|
$formFieldCheckboxes = $this->getMock('Joomla\\Form\\Field_Checkboxes', array('getOptions')); |
| 228 |
|
|
| 229 |
|
$option1 = new \stdClass; |
| 230 |
|
$option1->value = 'red'; |
| 231 |
|
$option1->text = 'red'; |
| 232 |
|
|
| 233 |
|
$option2 = new \stdClass; |
| 234 |
|
$option2->value = 'blue'; |
| 235 |
|
$option2->text = 'blue'; |
| 236 |
|
|
| 237 |
|
$optionsReturn = array($option1, $option2); |
| 238 |
|
$formFieldCheckboxes->expects($this->any()) |
| 239 |
|
->method('getOptions') |
| 240 |
|
->will($this->returnValue($optionsReturn)); |
| 241 |
|
|
| 242 |
|
// Test with nothing checked, two values in checked element |
| 243 |
|
$element = simplexml_load_string( |
| 244 |
|
'<field name="color" type="checkboxes" checked="red,blue"> |
| 245 |
|
<option value="red">red</option> |
| 246 |
|
<option value="blue">blue</option> |
| 247 |
|
</field>'); |
| 248 |
|
TestHelper::setValue($formFieldCheckboxes, 'element', $element); |
| 249 |
|
TestHelper::setValue($formFieldCheckboxes, 'id', 'myTestId'); |
| 250 |
|
TestHelper::setValue($formFieldCheckboxes, 'name', 'myTestName'); |
| 251 |
|
TestHelper::setValue($formFieldCheckboxes, 'value', '""'); |
| 252 |
|
|
| 253 |
|
$expected = '<fieldset id="myTestId" class="checkboxes"><ul>' . |
| 254 |
|
'<li><input type="checkbox" id="myTestId0" name="myTestName" value="red"/><label for="myTestId0">red</label></li>' . |
| 255 |
|
'<li><input type="checkbox" id="myTestId1" name="myTestName" value="blue"/><label for="myTestId1">blue</label>' . |
| 256 |
|
'</li></ul></fieldset>'; |
| 257 |
|
|
| 258 |
|
$this->assertEquals( |
| 259 |
|
$expected, |
| 260 |
|
TestHelper::invoke($formFieldCheckboxes, 'getInput'), |
| 261 |
|
'The field with no values and two items in the checked element did not produce the right html' |
| 262 |
|
); |
| 263 |
|
} |
| 264 |
|
|
| 265 |
|
/** |
| 266 |
|
* Test the getInput method with one value and a different checked value. |
|
@@ 272-310 (lines=39) @@
|
| 269 |
|
* |
| 270 |
|
* @return void |
| 271 |
|
*/ |
| 272 |
|
public function testGetInputValueChecked() |
| 273 |
|
{ |
| 274 |
|
$formFieldCheckboxes = $this->getMock('Joomla\\Form\\Field_Checkboxes', array('getOptions')); |
| 275 |
|
|
| 276 |
|
$option1 = new \stdClass; |
| 277 |
|
$option1->value = 'red'; |
| 278 |
|
$option1->text = 'red'; |
| 279 |
|
|
| 280 |
|
$option2 = new \stdClass; |
| 281 |
|
$option2->value = 'blue'; |
| 282 |
|
$option2->text = 'blue'; |
| 283 |
|
|
| 284 |
|
$optionsReturn = array($option1, $option2); |
| 285 |
|
$formFieldCheckboxes->expects($this->any()) |
| 286 |
|
->method('getOptions') |
| 287 |
|
->will($this->returnValue($optionsReturn)); |
| 288 |
|
|
| 289 |
|
// Test with one item checked, a different value in checked element |
| 290 |
|
$element = simplexml_load_string( |
| 291 |
|
'<field name="color" type="checkboxes" checked="blue"> |
| 292 |
|
<option value="red">red</option> |
| 293 |
|
<option value="blue">blue</option> |
| 294 |
|
</field>'); |
| 295 |
|
TestHelper::setValue($formFieldCheckboxes, 'element', $element); |
| 296 |
|
TestHelper::setValue($formFieldCheckboxes, 'id', 'myTestId'); |
| 297 |
|
TestHelper::setValue($formFieldCheckboxes, 'value', 'red'); |
| 298 |
|
TestHelper::setValue($formFieldCheckboxes, 'name', 'myTestName'); |
| 299 |
|
|
| 300 |
|
$expected = '<fieldset id="myTestId" class="checkboxes"><ul><li>' . |
| 301 |
|
'<input type="checkbox" id="myTestId0" name="myTestName" value="red" checked="checked"/>' . |
| 302 |
|
'<label for="myTestId0">red</label></li><li><input type="checkbox" id="myTestId1" name="myTestName" value="blue"/>' . |
| 303 |
|
'<label for="myTestId1">blue</label></li></ul></fieldset>'; |
| 304 |
|
|
| 305 |
|
$this->assertEquals( |
| 306 |
|
$expected, |
| 307 |
|
TestHelper::invoke($formFieldCheckboxes, 'getInput'), |
| 308 |
|
'The field with one value and a different value in the checked element did not produce the right html' |
| 309 |
|
); |
| 310 |
|
} |
| 311 |
|
|
| 312 |
|
/** |
| 313 |
|
* Test the getInput method with multiple values, no checked. |
|
@@ 319-356 (lines=38) @@
|
| 316 |
|
* |
| 317 |
|
* @return void |
| 318 |
|
*/ |
| 319 |
|
public function testGetInputValuesNoChecked() |
| 320 |
|
{ |
| 321 |
|
$formFieldCheckboxes = $this->getMock('Joomla\\Form\\Field_Checkboxes', array('getOptions')); |
| 322 |
|
|
| 323 |
|
$option1 = new \stdClass; |
| 324 |
|
$option1->value = 'red'; |
| 325 |
|
$option1->text = 'red'; |
| 326 |
|
|
| 327 |
|
$option2 = new \stdClass; |
| 328 |
|
$option2->value = 'blue'; |
| 329 |
|
$option2->text = 'blue'; |
| 330 |
|
|
| 331 |
|
$optionsReturn = array($option1, $option2); |
| 332 |
|
$formFieldCheckboxes->expects($this->any()) |
| 333 |
|
->method('getOptions') |
| 334 |
|
->will($this->returnValue($optionsReturn)); |
| 335 |
|
|
| 336 |
|
// Test with two values checked, no checked element |
| 337 |
|
$element = simplexml_load_string( |
| 338 |
|
'<field name="color" type="checkboxes"> |
| 339 |
|
<option value="red">red</option> |
| 340 |
|
<option value="blue">blue</option> |
| 341 |
|
</field>'); |
| 342 |
|
TestHelper::setValue($formFieldCheckboxes, 'element', $element); |
| 343 |
|
TestHelper::setValue($formFieldCheckboxes, 'id', 'myTestId'); |
| 344 |
|
TestHelper::setValue($formFieldCheckboxes, 'value', 'yellow,green'); |
| 345 |
|
TestHelper::setValue($formFieldCheckboxes, 'name', 'myTestName'); |
| 346 |
|
|
| 347 |
|
$expected = '<fieldset id="myTestId" class="checkboxes"><ul><li>' . |
| 348 |
|
'<input type="checkbox" id="myTestId0" name="myTestName" value="red"/><label for="myTestId0">red</label></li><li>' . |
| 349 |
|
'<input type="checkbox" id="myTestId1" name="myTestName" value="blue"/><label for="myTestId1">blue</label></li></ul></fieldset>'; |
| 350 |
|
|
| 351 |
|
$this->assertEquals( |
| 352 |
|
$expected, |
| 353 |
|
TestHelper::invoke($formFieldCheckboxes, 'getInput'), |
| 354 |
|
'The field with two values did not produce the right html' |
| 355 |
|
); |
| 356 |
|
} |
| 357 |
|
|
| 358 |
|
/** |
| 359 |
|
* Test the getOptions method. |