Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow between to be an array of strings #864

Merged
merged 3 commits into from Jan 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
229 changes: 111 additions & 118 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -34,13 +34,6 @@
*/ */
class ContactTestController extends Controller { class ContactTestController extends Controller {


/**
* name property
*
* @var string 'ContactTest'
*/
public $name = 'ContactTest';

/** /**
* uses property * uses property
* *
Expand All @@ -57,27 +50,13 @@ class ContactTestController extends Controller {
*/ */
class Contact extends CakeTestModel { class Contact extends CakeTestModel {


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/** /**
* useTable property * useTable property
* *
* @var bool false * @var bool false
*/ */
public $useTable = false; public $useTable = false;


/**
* name property
*
* @var string 'Contact'
*/
public $name = 'Contact';

/** /**
* Default schema * Default schema
* *
Expand Down Expand Up @@ -161,13 +140,6 @@ class ContactTagsContact extends CakeTestModel {
*/ */
public $useTable = false; public $useTable = false;


/**
* name property
*
* @var string 'Contact'
*/
public $name = 'ContactTagsContact';

/** /**
* Default schema * Default schema
* *
Expand Down Expand Up @@ -206,13 +178,6 @@ class ContactNonStandardPk extends Contact {
*/ */
public $primaryKey = 'pk'; public $primaryKey = 'pk';


/**
* name property
*
* @var string 'ContactNonStandardPk'
*/
public $name = 'ContactNonStandardPk';

/** /**
* schema method * schema method
* *
Expand Down Expand Up @@ -270,20 +235,6 @@ class UserForm extends CakeTestModel {
*/ */
public $useTable = false; public $useTable = false;


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/**
* name property
*
* @var string 'UserForm'
*/
public $name = 'UserForm';

/** /**
* hasMany property * hasMany property
* *
Expand Down Expand Up @@ -325,20 +276,6 @@ class OpenidUrl extends CakeTestModel {
*/ */
public $useTable = false; public $useTable = false;


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/**
* name property
*
* @var string 'OpenidUrl'
*/
public $name = 'OpenidUrl';

/** /**
* belongsTo property * belongsTo property
* *
Expand Down Expand Up @@ -388,27 +325,13 @@ public function beforeValidate($options = array()) {
*/ */
class ValidateUser extends CakeTestModel { class ValidateUser extends CakeTestModel {


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/** /**
* useTable property * useTable property
* *
* @var bool false * @var bool false
*/ */
public $useTable = false; public $useTable = false;


/**
* name property
*
* @var string 'ValidateUser'
*/
public $name = 'ValidateUser';

/** /**
* hasOne property * hasOne property
* *
Expand Down Expand Up @@ -452,13 +375,6 @@ public function beforeValidate($options = array()) {
*/ */
class ValidateProfile extends CakeTestModel { class ValidateProfile extends CakeTestModel {


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/** /**
* useTable property * useTable property
* *
Expand All @@ -480,13 +396,6 @@ class ValidateProfile extends CakeTestModel {
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
); );


/**
* name property
*
* @var string 'ValidateProfile'
*/
public $name = 'ValidateProfile';

/** /**
* hasOne property * hasOne property
* *
Expand Down Expand Up @@ -526,27 +435,13 @@ public function beforeValidate($options = array()) {
*/ */
class ValidateItem extends CakeTestModel { class ValidateItem extends CakeTestModel {


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/** /**
* useTable property * useTable property
* *
* @var bool false * @var bool false
*/ */
public $useTable = false; public $useTable = false;


/**
* name property
*
* @var string 'ValidateItem'
*/
public $name = 'ValidateItem';

/** /**
* schema property * schema property
* *
Expand Down Expand Up @@ -590,26 +485,13 @@ public function beforeValidate($options = array()) {
*/ */
class TestMail extends CakeTestModel { class TestMail extends CakeTestModel {


/**
* primaryKey property
*
* @var string 'id'
*/
public $primaryKey = 'id';

/** /**
* useTable property * useTable property
* *
* @var bool false * @var bool false
*/ */
public $useTable = false; public $useTable = false;


/**
* name property
*
* @var string 'TestMail'
*/
public $name = 'TestMail';
} }


/** /**
Expand Down Expand Up @@ -3534,6 +3416,51 @@ public function testRadio() {
'/fieldset' '/fieldset'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);

$result = $this->Form->radio(
'Model.field',
array('option A', 'option B', 'option C'),
array('separator' => '--separator--', 'between' => array('between A', 'between B', 'between C'))
);

$expected = array(
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
'input' => array(
'type' => 'hidden', 'name' => 'data[Model][field]',
'value' => '', 'id' => 'ModelField_'
),
array('input' => array(
'type' => 'radio', 'name' => 'data[Model][field]',
'value' => '0', 'id' => 'ModelField0'
)),
array('label' => array('for' => 'ModelField0')),
'option A',
'/label',
'between A',
'--separator--',
array('input' => array(
'type' => 'radio', 'name' => 'data[Model][field]',
'value' => '1', 'id' => 'ModelField1'
)),
array('label' => array('for' => 'ModelField1')),
'option B',
'/label',
'between B',
'--separator--',
array('input' => array(
'type' => 'radio', 'name' => 'data[Model][field]',
'value' => '2', 'id' => 'ModelField2'
)),
array('label' => array('for' => 'ModelField2')),
'option C',
'/label',
'between C',
'/fieldset'
);
$this->assertTags($result, $expected);
} }


/** /**
Expand Down Expand Up @@ -3607,6 +3534,72 @@ public function testRadioDisabled() {
'/fieldset' '/fieldset'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);

$result = $this->Form->input('Model.field', array(
'options' => array('1' => 'first', '2' => 'second'),
'type' => 'radio',
'before' => '--before--',
'after' => '--after--',
'separator' => '--separator--',
'between' => array('--between first--', '--between second--')
));

$expected = array(
'div' => array('class' => 'input radio'),
'--before--',
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'first',
'/label',
'--between first--',
'--separator--',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
array('label' => array('for' => 'ModelField2')),
'second',
'/label',
'--between second--',
'/fieldset',
'--after--',
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->input('Model.field', array(
'options' => array('1' => 'first', '2' => 'second'),
'type' => 'radio',
'before' => '--before--',
'after' => '--after--',
'separator' => '--separator--',
'between' => array('--between first--')
));

$expected = array(
'div' => array('class' => 'input radio'),
'--before--',
'fieldset' => array(),
'legend' => array(),
'Field',
'/legend',
array('input' => array('type' => 'hidden', 'name' => 'data[Model][field]', 'id' => 'ModelField_', 'value' => '')),
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '1', 'id' => 'ModelField1')),
array('label' => array('for' => 'ModelField1')),
'first',
'/label',
'--between first--',
'--separator--',
array('input' => array('type' => 'radio', 'name' => 'data[Model][field]', 'value' => '2', 'id' => 'ModelField2')),
array('label' => array('for' => 'ModelField2')),
'second',
'/label',
'/fieldset',
'--after--',
'/div'
);
} }


/** /**
Expand Down
9 changes: 8 additions & 1 deletion lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -1303,7 +1303,8 @@ public function checkbox($fieldName, $options = array()) {
* ### Attributes: * ### Attributes:
* *
* - `separator` - define the string in between the radio buttons * - `separator` - define the string in between the radio buttons
* - `between` - the string between legend and input set * - `between` - the string between legend and input set or array of strings to insert
* strings between each input block
* - `legend` - control whether or not the widget set has a fieldset & legend * - `legend` - control whether or not the widget set has a fieldset & legend
* - `value` - indicate a value that is should be checked * - `value` - indicate a value that is should be checked
* - `label` - boolean to indicate whether or not labels for widgets show be displayed * - `label` - boolean to indicate whether or not labels for widgets show be displayed
Expand Down Expand Up @@ -1388,6 +1389,9 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
if ($label) { if ($label) {
$optTitle = $this->Html->useTag('label', $tagName, '', $optTitle); $optTitle = $this->Html->useTag('label', $tagName, '', $optTitle);
} }
if (is_array($between)) {
$optTitle .= array_shift($between);
}
$allOptions = array_merge($attributes, $optionsHere); $allOptions = array_merge($attributes, $optionsHere);
$out[] = $this->Html->useTag('radio', $attributes['name'], $tagName, $out[] = $this->Html->useTag('radio', $attributes['name'], $tagName,
array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')), array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')),
Expand All @@ -1405,6 +1409,9 @@ public function radio($fieldName, $options = array(), $attributes = array()) {
} }
$out = $hidden . implode($separator, $out); $out = $hidden . implode($separator, $out);


if (is_array($between)) {
$between = '';
}
if ($legend) { if ($legend) {
$out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out); $out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out);
} }
Expand Down