Skip to content

Commit

Permalink
Add fix and test for CamelBack input names.
Browse files Browse the repository at this point in the history
Refs #1974
  • Loading branch information
markstory committed Sep 9, 2011
1 parent 8880e0c commit fa8bdfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 21 additions & 0 deletions lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -87,6 +87,7 @@ public function schema($field = false) {
'author_id' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
'BigField' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
);
Expand Down Expand Up @@ -228,6 +229,10 @@ public static function entityProvider() {
array(
'HelperTest.1.Comment.body',
array('HelperTest', '1', 'Comment', 'body')
),
array(
'HelperTestComment.BigField',
array('HelperTestComment', 'BigField')
)
);
}
Expand Down Expand Up @@ -299,6 +304,22 @@ public function testSetEntityAssociated() {
$this->assertEquals($expected, $this->Helper->entity());

$this->assertEquals('HelperTestComment', $this->Helper->model());

}

/**
* Test that setEntity doesn't make CamelCase fields that are not associations an
* associated model.
*
* @return void
*/
public function testSetEntityAssociatedCamelCaseField() {
$this->Helper->fieldset = array('HelperTestComment' => array('fields' => array('BigField' => 'something')));
$this->Helper->setEntity('HelperTestComment', true);
$this->Helper->setEntity('HelperTestComment.BigField');

$this->assertEquals('HelperTestComment', $this->Helper->model());
$this->assertEquals('BigField', $this->Helper->field());
}

/**
Expand Down
9 changes: 8 additions & 1 deletion lib/Cake/View/Helper.php
Expand Up @@ -64,6 +64,13 @@ class Helper extends Object {
*/
public $plugin = null;

/**
* Fields this helper is using.
*
* @var array
*/
public $fieldset = array();

/**
* Holds tag templates.
*
Expand Down Expand Up @@ -449,7 +456,7 @@ public function setEntity($entity, $setScope = false) {
// check for associated model.
$reversed = array_reverse($parts);
foreach ($reversed as $part) {
if (preg_match('/^[A-Z]/', $part)) {
if (empty($this->fieldset[$this->_modelScope]['fields'][$part]) && preg_match('/^[A-Z]/', $part)) {
$this->_association = $part;
break;
}
Expand Down

0 comments on commit fa8bdfd

Please sign in to comment.