Permalink
Browse files

add tests for the 'empty radio option' feature

  • Loading branch information...
1 parent a7a5563 commit 613e3824e0b598c1c5e4abcd8b47d77b01b065da @challet challet committed with markstory Mar 29, 2012
Showing with 74 additions and 0 deletions.
  1. +74 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -3551,6 +3551,80 @@ public function testRadioHiddenInputDisabling() {
$this->assertTags($result, $expected);
}
+
+/**
+ * test adding an empty option for radio buttons
+ *
+ * @return void
+ */
+ public function testRadioAddEmptyOption() {
+
+ // $options['empty'] = true
+ $result = $this->Form->input('Model.1.field', array(
+ 'type' => 'radio',
+ 'options' => array('option A'),
+ 'empty' => true,
+ 'hiddenField' => false
+ )
+ );
+ $expected = array(
+ 'div' => array('class' => 'input radio'),
+ 'fieldset' => array(),
+ 'legend' => array(),
+ 'Field',
+ '/legend',
+ array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
+ array('label' => array('for' => 'Model1Field')),
+ __('empty'),
+ '/label',
+ array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
+ array('label' => array('for' => 'Model1Field0')),
+ 'option A',
+ '/label',
+ '/fieldset',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ // $options['empty'] = 'CustomEmptyLabel'
+ $result = $this->Form->input('Model.1.field', array(
+ 'type' => 'radio',
+ 'options' => array('option A'),
+ 'empty' => 'CustomEmptyLabel',
+ 'hiddenField' => false
+ )
+ );
+ $expected = array(
+ 'div' => array('class' => 'input radio'),
+ 'fieldset' => array(),
+ 'legend' => array(),
+ 'Field',
+ '/legend',
+ array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '', 'id' => 'Model1Field')),
+ array('label' => array('for' => 'Model1Field')),
+ 'CustomEmptyLabel',
+ '/label',
+ array('input' => array('type' => 'radio', 'name' => 'data[Model][1][field]', 'value' => '0', 'id' => 'Model1Field0')),
+ array('label' => array('for' => 'Model1Field0')),
+ 'option A',
+ '/label',
+ '/fieldset',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
+
+ // $options['empty'] = false
+ $result = $this->Form->input('Model.1.field', array(
+ 'type' => 'radio',
+ 'options' => array('option A'),
+ 'empty' => false,
+ 'hiddenField' => false
+ )
+ );
+ $this->assertTextNotContains('"Model1Field"', $result);
+
+ }
+
/**
* testSelect method
*

0 comments on commit 613e382

Please sign in to comment.