Browse files

Merge pull request #538 from mcammaert/2.1

Merging input defaults with passed options to preserve nested keys
  • Loading branch information...
2 parents 9d017c2 + 9c24f81 commit 96f73d6392963287feb5da36c1e118972426fa8a @lorenzo lorenzo committed Feb 29, 2012
Showing with 15 additions and 3 deletions.
  1. +14 −2 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +1 −1 lib/Cake/View/Helper/FormHelper.php
View
16 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
@@ -6528,8 +6528,8 @@ public function testCreateCustomRoute() {
*/
public function testCreateWithInputDefaults() {
$this->Form->create('User', array(
- 'inputDefaults' => array('div' => false, 'label' => false)
- ));
+ 'inputDefaults' => array('div' => false, 'label' => false, 'error' => array('attributes'=>array('wrap' => 'small', 'class' => 'error')))
+ ));
$result = $this->Form->input('username');
$expected = array(
'input' => array('type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername')
@@ -6544,6 +6544,18 @@ public function testCreateWithInputDefaults() {
'/div'
);
$this->assertTags($result, $expected);
+
+ $User = ClassRegistry::getObject('User');
+ $User->validationErrors['username'] = array('empty');
+ $result = $this->Form->input('username', array('div' => true, 'label' => 'username', 'error' => array('empty' => __('Required'))));
+ $expected = array(
+ 'div' => array('class' => 'input text error'),
+ 'label' => array('for' => 'UserUsername'), 'username', '/label',
+ 'input' => array('class' => 'form-error', 'type' => 'text', 'name' => 'data[User][username]', 'id' => 'UserUsername'),
+ 'small' => array('class' => 'error'), 'Required', '/small',
+ '/div'
+ );
+ $this->assertTags($result, $expected);
}
/**
View
2 lib/Cake/View/Helper/FormHelper.php
@@ -946,7 +946,7 @@ public function inputs($fields = null, $blacklist = null) {
public function input($fieldName, $options = array()) {
$this->setEntity($fieldName);
- $options = array_merge(
+ $options = Set::merge(
array('before' => null, 'between' => null, 'after' => null, 'format' => null),
$this->_inputDefaults,
$options

0 comments on commit 96f73d6

Please sign in to comment.