Skip to content

Commit

Permalink
add tests for the 'empty radio option' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
challet authored and markstory committed Apr 7, 2012
1 parent a7a5563 commit 613e382
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -3551,6 +3551,80 @@ public function testRadioHiddenInputDisabling() {
$this->assertTags($result, $expected); $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 * testSelect method
* *
Expand Down

0 comments on commit 613e382

Please sign in to comment.