From 59f7cb47d34f70a6d61947fedf8b18c1a74a24d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Thu, 8 Apr 2010 18:23:07 -0430 Subject: [PATCH] Improving test coverage on FormHelper to show the usage of the 'secure' key for inputs. Fixing issue with select inputs that does not honor the value of 'secure' --- cake/libs/view/helpers/form.php | 9 +++++-- .../cases/libs/view/helpers/form.test.php | 27 ++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index f92197190b4..c134d755f82 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1412,6 +1412,9 @@ function select($fieldName, $options = array(), $selected = null, $attributes = $escapeOptions = $attributes['escape']; unset($attributes['escape']); } + if (isset($attributes['secure'])) { + $secure = $attributes['secure']; + } if (isset($attributes['empty'])) { $showEmpty = $attributes['empty']; unset($attributes['empty']); @@ -1452,7 +1455,9 @@ function select($fieldName, $options = array(), $selected = null, $attributes = } if (!empty($tag) || isset($template)) { - $this->__secure(); + if (!isset($secure) || $secure == true) { + $this->__secure(); + } $select[] = sprintf($tag, $attributes['name'], $this->_parseAttributes( $attributes, array('name', 'value')) ); @@ -2169,4 +2174,4 @@ function _initInputField($field, $options = array()) { } } -?> \ No newline at end of file +?> diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 6948e1fc85d..d6513598167 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1224,6 +1224,31 @@ function testFormSecuredRadio() { $this->assertEqual($this->Form->fields, $expected); } +/** + * testDisableSecurityUsingForm method + * + * @access public + * @return void + */ + function testDisableSecurityUsingForm() { + $this->Form->params['_Token']['key'] = 'testKey'; + $this->Form->params['_Token']['disabledFields'] = array(); + $this->Form->create(); + + $this->Form->hidden('Addresses.id', array('value' => '123456')); + $this->Form->input('Addresses.title'); + $this->Form->input('Addresses.first_name', array('secure' => false)); + $this->Form->input('Addresses.city', array('type' => 'textarea', 'secure' => false)); + $this->Form->input('Addresses.zip', array( + 'type' => 'select', 'options' => array(1,2), 'secure' => false + )); + + $result = $this->Form->fields; + $expected = array( + 'Addresses.id' => '123456', 'Addresses.title', + ); + $this->assertEqual($result, $expected); + } /** * testPasswordValidation method * @@ -6173,4 +6198,4 @@ function testInputTemplate() { $this->assertTags($result, $expected); } } -?> \ No newline at end of file +?>