diff --git a/lib/Cake/Test/Case/View/HelperTest.php b/lib/Cake/Test/Case/View/HelperTest.php index 5d30f23e2..4476db2ae 100644 --- a/lib/Cake/Test/Case/View/HelperTest.php +++ b/lib/Cake/Test/Case/View/HelperTest.php @@ -304,7 +304,6 @@ class HelperTest extends CakeTestCase { $this->assertEquals($expected, $this->Helper->entity()); $this->assertEquals('HelperTestComment', $this->Helper->model()); - } /** @@ -314,7 +313,11 @@ class HelperTest extends CakeTestCase { * @return void */ public function testSetEntityAssociatedCamelCaseField() { - $this->Helper->fieldset = array('HelperTestComment' => array('fields' => array('BigField' => 'something'))); + $this->Helper->fieldset = array( + 'HelperTestComment' => array( + 'fields' => array('BigField' => array('type' => 'integer')) + ) + ); $this->Helper->setEntity('HelperTestComment', true); $this->Helper->setEntity('HelperTestComment.BigField'); @@ -322,6 +325,25 @@ class HelperTest extends CakeTestCase { $this->assertEquals('BigField', $this->Helper->field()); } +/** + * Test that multiple fields work when they are camelcase and in fieldset + * + * @return void + */ + public function testSetEntityAssociatedCamelCaseFieldHabtmMultiple() { + $this->Helper->fieldset = array( + 'HelperTestComment' => array( + 'fields' => array('Tag' => array('type' => 'multiple')) + ) + ); + $this->Helper->setEntity('HelperTestComment', true); + $this->Helper->setEntity('Tag'); + + $this->assertEquals('Tag', $this->Helper->model()); + $this->assertEquals('Tag', $this->Helper->field()); + $this->assertEquals(array('Tag', 'Tag'), $this->Helper->entity()); + } + /** * test that 'view' doesn't break things. * diff --git a/lib/Cake/View/Helper.php b/lib/Cake/View/Helper.php index d8ae17d3b..63b8a45d1 100644 --- a/lib/Cake/View/Helper.php +++ b/lib/Cake/View/Helper.php @@ -454,23 +454,26 @@ class Helper extends Object { $this->_association = null; - // check for associated model. - $reversed = array_reverse($parts); - foreach ($reversed as $part) { - if (empty($this->fieldset[$this->_modelScope]['fields'][$part]) && preg_match('/^[A-Z]/', $part)) { - $this->_association = $part; - break; - } - } - // habtm models are special if ( isset($this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type']) && $this->fieldset[$this->_modelScope]['fields'][$parts[0]]['type'] === 'multiple' ) { + $this->_association = $parts[0]; $entity = $parts[0] . '.' . $parts[0]; + } else { + // check for associated model. + $reversed = array_reverse($parts); + foreach ($reversed as $part) { + if ( + !isset($this->fieldset[$this->_modelScope]['fields'][$part]) && + preg_match('/^[A-Z]/', $part) + ) { + $this->_association = $part; + break; + } + } } - $this->_entityPath = $entity; return; }