Permalink
Browse files

Start updating hidden() and initInputField.

Start updating hidden fields and initInputField to use the new widget
system and context classes.

Move 'form-error' into a setting. We've had a number of debates around
this, and I don't think I'd like to have more of them in the future.
While we can prescribe 'error' or 'form-error', giving a tiny bit of
config is not going to end the world.
  • Loading branch information...
1 parent e45cf77 commit 41893816de37418d57e46b14a020d6807977ff6b @markstory markstory committed Feb 12, 2014
Showing with 20 additions and 10 deletions.
  1. +13 −3 src/View/Helper/FormHelper.php
  2. +7 −7 tests/TestCase/View/Helper/FormHelperTest.php
@@ -428,7 +428,8 @@ protected function _csrfField() {
return '';
}
return $this->hidden('_csrfToken', array(
- 'value' => $this->request->params['_csrfToken'], 'id' => 'Token' . mt_rand(),
+ 'value' => $this->request->params['_csrfToken'],
+ 'id' => 'Token' . mt_rand(),
'secure' => static::SECURE_SKIP
));
}
@@ -2848,8 +2849,17 @@ protected function _initInputField($field, $options = []) {
$options['disabled'] = true;
}
- $options['val'] = $this->_context->val($field);
- $options += $this->_context->attributes($field);
+ if (!isset($options['name'])) {
+ $options['name'] = $field;
+ }
+ if (isset($options['value']) && !isset($options['val'])) {
+ $options['val'] = $options['value'];
+ unset($options['value']);
+ }
+ if (!isset($options['val'])) {
+ $options['val'] = $this->_context->val($field);
+ }
+ $options += (array)$this->_context->attributes($field);
if ($this->_context->hasError($field)) {
$options = $this->addClass($options, $this->settings['errorClass']);
@@ -599,7 +599,7 @@ public function testAddContextProviderInvalid() {
* @return array
*/
public function contextSelectionProvider() {
- $entity = $this->getMock('Cake\ORM\Entity');
+ $entity = new Article();
$collection = $this->getMock('Cake\Collection\Collection', ['extract'], [[$entity]]);
$data = [
'schema' => [
@@ -623,6 +623,7 @@ public function contextSelectionProvider() {
* @return void
*/
public function testCreateContextSelectionBuiltIn($data, $class) {
+ $this->loadFixtures('Article');
$this->Form->create($data);
$this->assertInstanceOf($class, $this->Form->context());
}
@@ -1115,12 +1116,11 @@ public function testGetFormWithFalseModel() {
public function testCreateWithSecurity() {
$this->Form->request->params['_csrfToken'] = 'testKey';
$encoding = strtolower(Configure::read('App.encoding'));
- $article = new Article();
- $result = $this->Form->create($article, [
- 'url' => '/contacts/add',
+ $result = $this->Form->create($this->article, [
+ 'url' => '/articles/publish',
]);
$expected = array(
- 'form' => array('method' => 'post', 'action' => '/contacts/add', 'accept-charset' => $encoding),
+ 'form' => array('method' => 'post', 'action' => '/articles/publish', 'accept-charset' => $encoding),
'div' => array('style' => 'display:none;'),
array('input' => array('type' => 'hidden', 'name' => '_method', 'value' => 'POST')),
array('input' => array(
@@ -1130,7 +1130,7 @@ public function testCreateWithSecurity() {
);
$this->assertTags($result, $expected);
- $result = $this->Form->create($article, ['url' => '/contacts/add', 'id' => 'MyForm']);
+ $result = $this->Form->create($this->article, ['url' => '/articles/publish', 'id' => 'MyForm']);
$expected['form']['id'] = 'MyForm';
$this->assertTags($result, $expected);
}
@@ -1163,7 +1163,7 @@ public function testCreateEndGetNoSecurity() {
*/
public function testCreateClearingFields() {
$this->Form->fields = array('model_id');
- $this->Form->create(new Article());
+ $this->Form->create($this->article);
$this->assertEquals(array(), $this->Form->fields);
}

0 comments on commit 4189381

Please sign in to comment.