From 24fd87398df41f9c4751cc1f1013862a4b59335d Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 26 Oct 2011 23:46:15 -0400 Subject: [PATCH] Fix issue with 0.Model.field inputs. These inputs would be incorrectly prefixed with another Model name. --- lib/Cake/Test/Case/View/HelperTest.php | 15 ++++++++++++++- lib/Cake/View/Helper.php | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 9f1365209..11335da17 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -255,7 +255,7 @@ class HelperTest extends CakeTestCase { */ 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'); @@ -310,6 +310,19 @@ class HelperTest extends CakeTestCase { $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. diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index c2219be89..91fafae3b 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -444,9 +444,9 @@ class Helper extends Object { $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; }