From bfaed32e589e80eaf3b4cd75a1f3b824b4fcf091 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 21 Sep 2012 00:06:26 +0200 Subject: [PATCH 1/3] allow between to be an array of strings --- .../Test/Case/View/Helper/FormHelperTest.php | 197 +++++++----------- lib/Cake/View/Helper/FormHelper.php | 9 +- 2 files changed, 87 insertions(+), 119 deletions(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 2fd7c9866..9fb127599 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -34,13 +34,6 @@ App::uses('Router', 'Routing'); */ class ContactTestController extends Controller { -/** - * name property - * - * @var string 'ContactTest' - */ - public $name = 'ContactTest'; - /** * uses property * @@ -57,13 +50,6 @@ class ContactTestController extends Controller { */ class Contact extends CakeTestModel { -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - /** * useTable property * @@ -71,13 +57,6 @@ class Contact extends CakeTestModel { */ public $useTable = false; -/** - * name property - * - * @var string 'Contact' - */ - public $name = 'Contact'; - /** * Default schema * @@ -161,13 +140,6 @@ class ContactTagsContact extends CakeTestModel { */ public $useTable = false; -/** - * name property - * - * @var string 'Contact' - */ - public $name = 'ContactTagsContact'; - /** * Default schema * @@ -206,13 +178,6 @@ class ContactNonStandardPk extends Contact { */ public $primaryKey = 'pk'; -/** - * name property - * - * @var string 'ContactNonStandardPk' - */ - public $name = 'ContactNonStandardPk'; - /** * schema method * @@ -270,20 +235,6 @@ class UserForm extends CakeTestModel { */ public $useTable = false; -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - -/** - * name property - * - * @var string 'UserForm' - */ - public $name = 'UserForm'; - /** * hasMany property * @@ -325,20 +276,6 @@ class OpenidUrl extends CakeTestModel { */ public $useTable = false; -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - -/** - * name property - * - * @var string 'OpenidUrl' - */ - public $name = 'OpenidUrl'; - /** * belongsTo property * @@ -388,13 +325,6 @@ class OpenidUrl extends CakeTestModel { */ class ValidateUser extends CakeTestModel { -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - /** * useTable property * @@ -402,13 +332,6 @@ class ValidateUser extends CakeTestModel { */ public $useTable = false; -/** - * name property - * - * @var string 'ValidateUser' - */ - public $name = 'ValidateUser'; - /** * hasOne property * @@ -452,13 +375,6 @@ class ValidateUser extends CakeTestModel { */ class ValidateProfile extends CakeTestModel { -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - /** * useTable property * @@ -480,13 +396,6 @@ class ValidateProfile extends CakeTestModel { 'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null) ); -/** - * name property - * - * @var string 'ValidateProfile' - */ - public $name = 'ValidateProfile'; - /** * hasOne property * @@ -526,13 +435,6 @@ class ValidateProfile extends CakeTestModel { */ class ValidateItem extends CakeTestModel { -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - /** * useTable property * @@ -540,13 +442,6 @@ class ValidateItem extends CakeTestModel { */ public $useTable = false; -/** - * name property - * - * @var string 'ValidateItem' - */ - public $name = 'ValidateItem'; - /** * schema property * @@ -590,13 +485,6 @@ class ValidateItem extends CakeTestModel { */ class TestMail extends CakeTestModel { -/** - * primaryKey property - * - * @var string 'id' - */ - public $primaryKey = 'id'; - /** * useTable property * @@ -604,12 +492,6 @@ class TestMail extends CakeTestModel { */ public $useTable = false; -/** - * name property - * - * @var string 'TestMail' - */ - public $name = 'TestMail'; } /** @@ -3534,6 +3416,51 @@ class FormHelperTest extends CakeTestCase { '/fieldset' ); $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); } /** @@ -3607,6 +3534,40 @@ class FormHelperTest extends CakeTestCase { '/fieldset' ); $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--') + )); + //die(debug($result, null, false)); + $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); } /** diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 5f3a03d49..5029d92dd 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -1303,7 +1303,8 @@ class FormHelper extends AppHelper { * ### Attributes: * * - `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 * - `value` - indicate a value that is should be checked * - `label` - boolean to indicate whether or not labels for widgets show be displayed @@ -1388,6 +1389,9 @@ class FormHelper extends AppHelper { if ($label) { $optTitle = $this->Html->useTag('label', $tagName, '', $optTitle); } + if (is_array($between)) { + $optTitle .= array_shift($between); + } $allOptions = array_merge($attributes, $optionsHere); $out[] = $this->Html->useTag('radio', $attributes['name'], $tagName, array_diff_key($allOptions, array('name' => '', 'type' => '', 'id' => '')), @@ -1405,6 +1409,9 @@ class FormHelper extends AppHelper { } $out = $hidden . implode($separator, $out); + if (is_array($between)) { + $between = ''; + } if ($legend) { $out = $this->Html->useTag('fieldset', '', $this->Html->useTag('legend', $legend) . $between . $out); } From 490bbf836d36c2e42112b32d9394c4dc5ba9335b Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 21 Sep 2012 00:09:42 +0200 Subject: [PATCH 2/3] remove debug statement --- lib/Cake/Test/Case/View/Helper/FormHelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 9fb127599..23c0aa38a 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -3543,7 +3543,7 @@ class FormHelperTest extends CakeTestCase { 'separator' => '--separator--', 'between' => array('--between first--', '--between second--') )); - //die(debug($result, null, false)); + $expected = array( 'div' => array('class' => 'input radio'), '--before--', From 7aa78c40f3a714897766c542be51ea1e2f0e6ff1 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 21 Sep 2012 02:57:10 +0200 Subject: [PATCH 3/3] test case to proof that less between strings also work and do not error --- .../Test/Case/View/Helper/FormHelperTest.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 23c0aa38a..fff5fea41 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -3568,6 +3568,38 @@ class FormHelperTest extends CakeTestCase { '/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' + ); } /**