Clean up changes code standards and tests.

Refs #2582
This commit is contained in:
mark_story 2014-02-17 11:03:49 -05:00
parent b32deed4aa
commit 3433f4a1f0
2 changed files with 12 additions and 30 deletions

View file

@ -690,7 +690,7 @@ class FormHelperTest extends CakeTestCase {
$key = 'testKey'; $key = 'testKey';
$fields = array('Model.password', 'Model.username', 'Model.valid' => '0'); $fields = array('Model.password', 'Model.username', 'Model.valid' => '0');
$secureAttributes = array('form' => 'MyTestForm'); $secureAttributes = array('form' => 'MyTestForm');
$this->Form->request['_Token'] = array('key' => $key); $this->Form->request['_Token'] = array('key' => $key);
$result = $this->Form->secure($fields, $secureAttributes); $result = $this->Form->secure($fields, $secureAttributes);
@ -713,25 +713,6 @@ class FormHelperTest extends CakeTestCase {
'/div' '/div'
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$path = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS;
$this->Form->Html->loadConfig('htmlhelper_tags', $path);
$result = $this->Form->secure($fields, $secureAttributes);
$expected = array(
'div' => array('class' => 'hidden'),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][fields]',
'value' => $hash, 'id' => 'preg:/TokenFields\d+/',
'form' => 'MyTestForm',
)),
array('input' => array(
'type' => 'hidden', 'name' => 'data[_Token][unlocked]',
'value' => '', 'id' => 'preg:/TokenUnlocked\d+/',
'form' => 'MyTestForm',
)),
'/div'
);
$this->assertTags($result, $expected);
} }
/** /**
@ -9052,10 +9033,10 @@ class FormHelperTest extends CakeTestCase {
public function testFormEnd() { public function testFormEnd() {
$this->assertEquals('</form>', $this->Form->end()); $this->assertEquals('</form>', $this->Form->end());
$result = $this->Form->end('', array('form' => 'MyTestFormWithSupportForSecurityComponent')); $result = $this->Form->end('', array('form' => 'form-name'));
$expected = array( $expected = array(
'div' => array('class' => 'submit'), 'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => '', 'form' => 'MyTestFormWithSupportForSecurityComponent'), 'input' => array('type' => 'submit', 'value' => ''),
'/div', '/div',
'/form' '/form'
); );

View file

@ -541,20 +541,21 @@ class FormHelper extends AppHelper {
} }
/** /**
* Generates a hidden field with a security hash based on the fields used in the form. * Generates a hidden field with a security hash based on the fields used in
* the form.
* *
* If $secureAttributes is set, these html attributes will be merged into the hidden input tags generated for the * If $secureAttributes is set, these html attributes will be merged into
* Security Component. This is especially useful to set HTML5 attributes like 'form'. * the hidden input tags generated for the Security Component. This is
* especially useful to set HTML5 attributes like 'form'.
* *
* @param array|null $fields If set specifies the list of fields to use when generating the hash, else $this->fields * @param array|null $fields If set specifies the list of fields to use when
* is being used. * generating the hash, else $this->fields is being used.
* @param array $secureAttributes will be passed as html attributes into the hidden input elements generated for the * @param array $secureAttributes will be passed as html attributes into the hidden
* Security Component. * input elements generated for the Security Component.
* @return string A hidden input field with a security hash * @return string A hidden input field with a security hash
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::secure * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::secure
*/ */
public function secure($fields = array(), $secureAttributes = array()) { public function secure($fields = array(), $secureAttributes = array()) {
if (!isset($this->request['_Token']) || empty($this->request['_Token'])) { if (!isset($this->request['_Token']) || empty($this->request['_Token'])) {
return; return;
} }