mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Fixing fully-qualified form field references, fixes #4068
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6535 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b1f5b76f98
commit
9a6029f03e
3 changed files with 60 additions and 36 deletions
|
@ -316,6 +316,8 @@ class Helper extends Overloadable {
|
||||||
|
|
||||||
if ($setScope) {
|
if ($setScope) {
|
||||||
$view->modelScope = false;
|
$view->modelScope = false;
|
||||||
|
} elseif (join('.', $view->entity()) == $entity) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entity === null) {
|
if ($entity === null) {
|
||||||
|
@ -326,9 +328,13 @@ class Helper extends Overloadable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sameScope = $hasField = false;
|
|
||||||
$parts = preg_split('/\/|\./', $entity);
|
|
||||||
$model = $view->model;
|
$model = $view->model;
|
||||||
|
$sameScope = $hasField = false;
|
||||||
|
$parts = array_values(Set::filter(preg_split('/\/|\./', $entity), true));
|
||||||
|
|
||||||
|
if (empty($parts)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (count($parts) === 1 || is_numeric($parts[0])) {
|
if (count($parts) === 1 || is_numeric($parts[0])) {
|
||||||
$sameScope = true;
|
$sameScope = true;
|
||||||
|
@ -343,7 +349,7 @@ class Helper extends Overloadable {
|
||||||
for ($i = 0; $i < count($parts); $i++) {
|
for ($i = 0; $i < count($parts); $i++) {
|
||||||
if ($ModelObj->hasField($parts[$i]) || array_key_exists($parts[$i], $ModelObj->validate)) {
|
if ($ModelObj->hasField($parts[$i]) || array_key_exists($parts[$i], $ModelObj->validate)) {
|
||||||
$hasField = $i;
|
$hasField = $i;
|
||||||
if ($hasField === 0) {
|
if ($hasField === 0 || ($hasField === 1 && is_numeric($parts[0]))) {
|
||||||
$sameScope = true;
|
$sameScope = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -359,7 +365,6 @@ class Helper extends Overloadable {
|
||||||
array_unshift($parts, $model);
|
array_unshift($parts, $model);
|
||||||
$hasField = true;
|
$hasField = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
|
$view->field = $view->modelId = $view->fieldSuffix = $view->association = null;
|
||||||
|
|
||||||
switch (count($parts)) {
|
switch (count($parts)) {
|
||||||
|
@ -393,6 +398,13 @@ class Helper extends Overloadable {
|
||||||
list($view->association, $view->field, $view->fieldSuffix) = $parts;
|
list($view->association, $view->field, $view->fieldSuffix) = $parts;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 4:
|
||||||
|
if ($parts[0] === $view->model) {
|
||||||
|
list($view->model, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
||||||
|
} else {
|
||||||
|
list($view->association, $view->modelId, $view->field, $view->fieldSuffix) = $parts;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($view->model) || empty($view->model)) {
|
if (!isset($view->model) || empty($view->model)) {
|
||||||
|
|
|
@ -187,7 +187,6 @@ class HelperTest extends UnitTestCase {
|
||||||
|
|
||||||
$this->assertEqual($this->View->entity(), array('HelperTestPost', 5, 'id'));
|
$this->assertEqual($this->View->entity(), array('HelperTestPost', 5, 'id'));
|
||||||
|
|
||||||
|
|
||||||
$this->Helper->setEntity('0.id');
|
$this->Helper->setEntity('0.id');
|
||||||
$this->assertTrue($this->View->modelScope);
|
$this->assertTrue($this->View->modelScope);
|
||||||
$this->assertEqual($this->View->model, 'HelperTestPost');
|
$this->assertEqual($this->View->model, 'HelperTestPost');
|
||||||
|
|
|
@ -209,6 +209,11 @@ class FormHelperTest extends CakeTestCase {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
Router::reload();
|
Router::reload();
|
||||||
|
|
||||||
|
$this->Form =& new FormHelper();
|
||||||
|
$this->Form->Html =& new HtmlHelper();
|
||||||
|
$this->Controller =& new ContactTestController();
|
||||||
|
$this->View =& new View($this->Controller);
|
||||||
|
|
||||||
ClassRegistry::addObject('view', $view);
|
ClassRegistry::addObject('view', $view);
|
||||||
ClassRegistry::addObject('Contact', new Contact());
|
ClassRegistry::addObject('Contact', new Contact());
|
||||||
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
|
ClassRegistry::addObject('OpenidUrl', new OpenidUrl());
|
||||||
|
@ -218,22 +223,6 @@ class FormHelperTest extends CakeTestCase {
|
||||||
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
|
ClassRegistry::addObject('ValidateProfile', new ValidateProfile());
|
||||||
}
|
}
|
||||||
|
|
||||||
function startTest($method) {
|
|
||||||
parent::startTest($method);
|
|
||||||
$this->Form =& new FormHelper();
|
|
||||||
$this->Form->Html =& new HtmlHelper();
|
|
||||||
$this->Controller =& new ContactTestController();
|
|
||||||
$this->View =& new View($this->Controller);
|
|
||||||
}
|
|
||||||
|
|
||||||
function endTest($method) {
|
|
||||||
parent::endTest($method);
|
|
||||||
if (isset($this->Form)) {
|
|
||||||
unset($this->Form->Html, $this->Form);
|
|
||||||
}
|
|
||||||
unset($this->Controller, $this->View);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFormCreateWithSecurity() {
|
function testFormCreateWithSecurity() {
|
||||||
$this->Form->params['_Token'] = array('key' => 'testKey');
|
$this->Form->params['_Token'] = array('key' => 'testKey');
|
||||||
|
|
||||||
|
@ -1061,6 +1050,35 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertPattern('/name="data\[ContactTag\]\[ContactTag\]\[\]"/', $result);
|
$this->assertPattern('/name="data\[ContactTag\]\[ContactTag\]\[\]"/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testFormDateTimeMulti() {
|
||||||
|
$result = $this->Form->dateTime('Contact.1.updated');
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[day\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedDay"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[month\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedMonth"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[year\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedYear"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[hour\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedHour"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[min\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedMin"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[1\]\[updated\]\[meridian\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact1UpdatedMeridian"/', $result);
|
||||||
|
|
||||||
|
$result = $this->Form->dateTime('Contact.2.updated');
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[day\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedDay"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[month\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedMonth"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[year\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedYear"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[hour\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedHour"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[min\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedMin"/', $result);
|
||||||
|
$this->assertPattern('/name="data\[Contact\]\[2\]\[updated\]\[meridian\]"/', $result);
|
||||||
|
$this->assertPattern('/id="Contact2UpdatedMeridian"/', $result);
|
||||||
|
}
|
||||||
|
|
||||||
function testMonth() {
|
function testMonth() {
|
||||||
$result = $this->Form->month('Model.field');
|
$result = $this->Form->month('Model.field');
|
||||||
|
@ -1373,10 +1391,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'last_name' => 'Abele',
|
'last_name' => 'Abele',
|
||||||
'email' => 'nate@cakephp.org'
|
'email' => 'nate@cakephp.org'
|
||||||
));
|
));
|
||||||
$this->Form->params = array(
|
$this->Form->params = array('models' => array('Person'), 'controller' => 'people');
|
||||||
'models' => array('Person'),
|
|
||||||
'controller' => 'people'
|
|
||||||
);
|
|
||||||
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
|
$options = array(1 => 'Nate', 2 => 'Garrett', 3 => 'Larry');
|
||||||
|
|
||||||
$this->Form->create();
|
$this->Form->create();
|
||||||
|
@ -1437,13 +1452,11 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'<input name="data\[Contact\]\[imnotrequired\]" type="text" value="" id="ContactImnotrequired" \/>'.
|
'<input name="data\[Contact\]\[imnotrequired\]" type="text" value="" id="ContactImnotrequired" \/>'.
|
||||||
'<\/div>$/', $result);
|
'<\/div>$/', $result);
|
||||||
|
|
||||||
|
|
||||||
$result = $this->Form->input('Contact.published', array('div' => false));
|
$result = $this->Form->input('Contact.published', array('div' => false));
|
||||||
$this->assertPattern('/^<label for="ContactPublishedMonth">Published<\/label>' .
|
$this->assertPattern('/^<label for="ContactPublishedMonth">Published<\/label>' .
|
||||||
'<select name="data\[Contact\]\[published\]\[month\]"\s+id="ContactPublishedMonth">/', $result);
|
'<select name="data\[Contact\]\[published\]\[month\]"\s+id="ContactPublishedMonth">/', $result);
|
||||||
|
|
||||||
$result = $this->Form->input('Contact.updated', array('div' => false));
|
$result = $this->Form->input('Contact.updated', array('div' => false));
|
||||||
|
|
||||||
$this->assertPattern('/^<label for="ContactUpdatedMonth">Updated<\/label>' .
|
$this->assertPattern('/^<label for="ContactUpdatedMonth">Updated<\/label>' .
|
||||||
'<select name="data\[Contact\]\[updated\]\[month\]"\s+id="ContactUpdatedMonth">/', $result);
|
'<select name="data\[Contact\]\[updated\]\[month\]"\s+id="ContactUpdatedMonth">/', $result);
|
||||||
}
|
}
|
||||||
|
@ -1588,7 +1601,7 @@ class FormHelperTest extends CakeTestCase {
|
||||||
ClassRegistry::removeObject('ValidateItem');
|
ClassRegistry::removeObject('ValidateItem');
|
||||||
ClassRegistry::removeObject('ValidateUser');
|
ClassRegistry::removeObject('ValidateUser');
|
||||||
ClassRegistry::removeObject('ValidateProfile');
|
ClassRegistry::removeObject('ValidateProfile');
|
||||||
unset($this->Form);
|
unset($this->Form->Html, $this->Form, $this->Controller, $this->View);
|
||||||
}
|
}
|
||||||
|
|
||||||
function __sortFields($fields) {
|
function __sortFields($fields) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue