Skip to content

Commit

Permalink
Fix issue with 0.Model.field inputs.
Browse files Browse the repository at this point in the history
These inputs would be incorrectly prefixed with another Model name.
  • Loading branch information
markstory committed Oct 27, 2011
1 parent 43df8d3 commit 24fd873
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/Cake/Test/Case/View/HelperTest.php
Expand Up @@ -255,7 +255,7 @@ public function testSetEntity($entity, $expected) {
*/
public function testSetEntityScoped() {
$this->Helper->setEntity('HelperTestPost', true);
$this->assertEquals(array('HelperTestPost'), $this->Helper->entity());
$this->assertEquals(array('HelperTestPost'), $this->Helper->entity());

$this->Helper->setEntity('id');
$expected = array('HelperTestPost', 'id');
Expand Down Expand Up @@ -310,6 +310,19 @@ public function testSetEntityAssociated() {
$this->assertEquals('HelperTestComment', $this->Helper->model());
}

/**
* Test creating saveMany() compatible entities
*
* @return void
*/
public function testSetEntitySaveMany() {
$this->Helper->setEntity('HelperTestPost', true);

$this->Helper->setEntity('0.HelperTestPost.id');
$expected = array('0', 'HelperTestPost', 'id');
$this->assertEquals($expected, $this->Helper->entity());
}

/**
* Test that setEntity doesn't make CamelCase fields that are not associations an
* associated model.
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/View/Helper.php
Expand Up @@ -444,9 +444,9 @@ public function setEntity($entity, $setScope = false) {
$entity = $this->_modelScope . '.' . $entity;
}

// 0.name, 0.created.month style inputs.
// 0.name, 0.created.month style inputs. Excludes inputs with the modelScope in them.
if (
$count >= 2 && is_numeric($parts[0]) && !is_numeric($parts[1]) && $this->_modelScope
$count >= 2 && is_numeric($parts[0]) && !is_numeric($parts[1]) && $this->_modelScope && strpos($entity, $this->_modelScope) === false
) {
$entity = $this->_modelScope . '.' . $entity;
}
Expand Down

0 comments on commit 24fd873

Please sign in to comment.