mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
fixing fieldSuffix in Helper::setEntity(), closes #3724 added tests.
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6143 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
98859c8c72
commit
16ee2d2661
2 changed files with 25 additions and 5 deletions
|
@ -328,19 +328,23 @@ class Helper extends Overloadable {
|
|||
$sameScope = $hasField = false;
|
||||
$parts = preg_split('/\/|\./', $entity);
|
||||
|
||||
$model = $view->model;
|
||||
if(count($parts) === 1 || is_numeric($parts[0])) {
|
||||
$sameScope = true;
|
||||
$model = $view->model;
|
||||
} else {
|
||||
$sameScope = false;
|
||||
$model = $parts[0];
|
||||
if (ClassRegistry::isKeySet($parts[0])) {
|
||||
$model = $parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (ClassRegistry::isKeySet($model)) {
|
||||
$ModelObj =& ClassRegistry::getObject($model);
|
||||
for ($i = 1; $i < count($parts); $i++) {
|
||||
for ($i = 0; $i < count($parts); $i++) {
|
||||
if ($ModelObj->hasField($parts[$i]) || array_key_exists($parts[$i], $ModelObj->validate)) {
|
||||
$hasField = $i;
|
||||
if ($hasField === 0) {
|
||||
$sameScope = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ class HelperTestPost extends Model {
|
|||
'title' => array('type' => 'string', 'null' => false, 'default' => '', 'length' => '255'),
|
||||
'body' => array('type' => 'string', 'null' => true, 'default' => '', 'length' => ''),
|
||||
'number' => array('type' => 'integer', 'null' => false, 'default' => '', 'length' => '8'),
|
||||
'date' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
||||
'created' => array('type' => 'date', 'null' => true, 'default' => '', 'length' => ''),
|
||||
'modified' => array('type' => 'datetime', 'null' => true, 'default' => '', 'length' => null)
|
||||
);
|
||||
|
@ -277,6 +278,22 @@ class HelperTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
function testFieldSuffixForDate() {
|
||||
$this->Helper->setEntity('HelperTestPost', true);
|
||||
$this->assertEqual($this->View->model, 'HelperTestPost');
|
||||
$this->assertEqual($this->View->field, null);
|
||||
$this->assertEqual($this->View->modelId, null);
|
||||
$this->assertEqual($this->View->association, null);
|
||||
$this->assertEqual($this->View->fieldSuffix, null);
|
||||
|
||||
$this->Helper->setEntity('date.month');
|
||||
$this->assertEqual($this->View->model, 'HelperTestPost');
|
||||
$this->assertEqual($this->View->field, 'date');
|
||||
$this->assertEqual($this->View->modelId, null);
|
||||
$this->assertEqual($this->View->association, null);
|
||||
$this->assertEqual($this->View->fieldSuffix, 'month');
|
||||
|
||||
}
|
||||
|
||||
function testMulitDimensionValue() {
|
||||
$this->Helper->data = array();
|
||||
|
@ -304,7 +321,6 @@ class HelperTest extends UnitTestCase {
|
|||
$this->Helper->data['HelperTestPost']['0']['id'] = 100;
|
||||
$result = $this->Helper->value('0.id');
|
||||
$this->assertEqual($result, 100);
|
||||
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
|
Loading…
Add table
Reference in a new issue