Adding Helper/FormHelper fixes for field names which are like model names (Ticket #3588)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6011 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-11-17 04:27:24 +00:00
parent 3c7d0e90ee
commit b3e4b64aa6
2 changed files with 23 additions and 3 deletions

View file

@ -328,7 +328,7 @@ class Helper extends Overloadable {
$sameScope = $hasField = false;
$parts = preg_split('/\/|\./', $entity);
if($parts[0] !== $view->model) {
if($parts[0] !== $view->model || count($parts) == 1) {
$sameScope = true;
if (ClassRegistry::isKeySet($view->model)) {
$modelObj =& ClassRegistry::getObject($view->model);
@ -341,7 +341,7 @@ class Helper extends Overloadable {
}
}
if (ClassRegistry::isKeySet($parts[0])) {
if (ClassRegistry::isKeySet($parts[0]) && ($parts[0] != strtolower($parts[0]))) {
$sameScope = false;
$newModelObj =& ClassRegistry::getObject($parts[0]);
for ($i = 1; $i < count($parts); $i++) {

View file

@ -469,7 +469,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/^<div[^<>]+class="input"[^<>]*><label[^<>]+for="UserUser"[^<>]*>User<\/label>/', $result);
$this->assertPattern('/<select[^<>]+>\s+<option value=""\s*><\/option>\s+<option value="value"/', $result);
$this->assertPattern('/<select[^<>]+multiple="multiple"[^<>\/]*>/', $result);
$this->assertNoPattern('/<select[^<>]+[^name|id|multiple]=[^<>\/]*>/', $result);
$this->assertNoPattern('/<select[^<>]+[^(name|id|multipl)]=[^<>\/]*>/', $result);
}
function testFormInputs() {
@ -503,6 +503,19 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/^<fieldset><legend[^<>]*>Hello<\/legend>.+<\/fieldset>$/s', $result);
}
function testSelectAsCheckbox() {
$result = $this->Form->select('Model.multi_field', array('first', 'second', 'third'), array(0, 1), array('multiple' => 'checkbox'));
$this->assertPattern('/^(<input[^<>]+>\s*<label[^<>]*>\w+<\/label>\s*){3}$/', $result);
$this->assertNoPattern('/<label[^<>]*>[^(first|second)]<\/label>/', $result);
/*$this->assertPattern('/^<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="0"[^<>]+checked="checked">/', $result);
$this->assertPattern('/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="1"[^<>]+checked="checked">/', $result);
$this->assertPattern('/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="2">third/', $result);
$this->assertNoPattern('/<input type="checkbox"[^<>]+name="data\[Model\]\[multi_field\]\[\]+value="[^012]"[^<>\/]*>$/', $result);*/
$this->assertNoPattern('/<select[^<>]*>/', $result);
$this->assertNoPattern('/<\/select>/', $result);
}
function testLabel() {
$this->Form->text('Person/name');
$result = $this->Form->label();
@ -1189,6 +1202,13 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+id="ContactPassword"[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
$result = $this->Form->text('user_form');
$this->assertPattern('/^<input[^<>]+name="user_form"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+type="text"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+value=""[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+id="ContactUserForm"[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^id|name|type|value]=[^<>]*>$/', $result);
}
function testEditFormWithData() {