mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing more failing tests.
Fixing use of properties that are going away.
This commit is contained in:
parent
87fe66353f
commit
4073584eef
3 changed files with 56 additions and 12 deletions
|
@ -276,7 +276,6 @@ class HelperTest extends CakeTestCase {
|
|||
$expected = array('HelperTestPost', 'body');
|
||||
$this->assertEquals($expected, $this->View->entity());
|
||||
|
||||
|
||||
$this->Helper->setEntity('2.body');
|
||||
$expected = array('HelperTestPost', '2', 'body');
|
||||
$this->assertEquals($expected, $this->View->entity());
|
||||
|
@ -303,6 +302,21 @@ class HelperTest extends CakeTestCase {
|
|||
$this->assertEquals($expected, $this->View->entity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that setEntity() and model()/field() work with associated models.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetEntityAssociated() {
|
||||
$this->Helper->setEntity('HelperTestPost', true);
|
||||
|
||||
$this->Helper->setEntity('HelperTestPost.1.HelperTestComment.1.title');
|
||||
$expected = array('HelperTestPost', '1', 'HelperTestComment', '1', 'title');
|
||||
$this->assertEquals($expected, $this->View->entity());
|
||||
|
||||
$this->assertEquals('HelperTestComment', $this->Helper->model());
|
||||
}
|
||||
|
||||
/**
|
||||
* test that 'view' doesn't break things.
|
||||
*
|
||||
|
@ -553,7 +567,7 @@ class HelperTest extends CakeTestCase {
|
|||
$expected = array('HelperTestPost');
|
||||
$this->assertEquals($expected, $this->View->entity());
|
||||
|
||||
foreach (array('year', 'month', 'day', 'hour', 'minute', 'meridian') as $d) {
|
||||
foreach (array('year', 'month', 'day', 'hour', 'min', 'meridian') as $d) {
|
||||
$this->Helper->setEntity('date.' . $d);
|
||||
$expected = array('HelperTestPost', 'date', $d);
|
||||
$this->assertEquals($expected, $this->View->entity());
|
||||
|
|
|
@ -111,7 +111,7 @@ class Helper extends Object {
|
|||
* @var array
|
||||
*/
|
||||
protected $_fieldSuffixes = array(
|
||||
'year', 'month', 'day', 'hour', 'minute', 'second', 'meridian'
|
||||
'year', 'month', 'day', 'hour', 'min', 'second', 'meridian'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -395,7 +395,6 @@ class Helper extends Object {
|
|||
if ($entity === null) {
|
||||
$view->modelScope = false;
|
||||
}
|
||||
|
||||
if ($setScope === true) {
|
||||
$view->modelScope = $entity;
|
||||
}
|
||||
|
@ -403,9 +402,10 @@ class Helper extends Object {
|
|||
if (empty($parts)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$count = count($parts);
|
||||
$lastPart = isset($parts[$count - 1]) ? $parts[$count - 1] : null;
|
||||
|
||||
// Either 'body' or 'date.month' type inputs.
|
||||
if (
|
||||
($count === 1 &&
|
||||
$view->modelScope &&
|
||||
|
@ -416,6 +416,8 @@ class Helper extends Object {
|
|||
) {
|
||||
$entity = $view->modelScope . '.' . $entity;
|
||||
}
|
||||
|
||||
// 0.name style inputs.
|
||||
if (
|
||||
$count === 2 &&
|
||||
is_numeric($parts[0]) &&
|
||||
|
@ -423,6 +425,26 @@ class Helper extends Object {
|
|||
) {
|
||||
$entity = $view->modelScope . '.' . $entity;
|
||||
}
|
||||
|
||||
$view->association = null;
|
||||
|
||||
// check for associated model.
|
||||
$reversed = array_reverse($parts);
|
||||
foreach ($reversed as $part) {
|
||||
if (preg_match('/^[A-Z]/', $part)) {
|
||||
$view->association = $part;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// habtm models are special
|
||||
if (
|
||||
isset($this->fieldset[$view->modelScope]['fields'][$parts[0]]['type']) &&
|
||||
$this->fieldset[$view->modelScope]['fields'][$parts[0]]['type'] === 'multiple'
|
||||
) {
|
||||
$entity = $parts[0] . '.' . $parts[0];
|
||||
}
|
||||
|
||||
$view->entityPath = $entity;
|
||||
return;
|
||||
|
||||
|
@ -575,7 +597,10 @@ class Helper extends Object {
|
|||
*/
|
||||
public function model() {
|
||||
$entity = $this->_View->entity();
|
||||
return isset($entity[0]) ? $entity[0] : null;
|
||||
if ($this->_View->association) {
|
||||
return $this->_View->association;
|
||||
}
|
||||
return $this->_View->modelScope;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -881,11 +906,13 @@ class Helper extends Object {
|
|||
}
|
||||
$array = array();
|
||||
if (!empty($data)) {
|
||||
foreach ($data as $var) {
|
||||
$array[$var[$key]] = $var[$key];
|
||||
foreach ($data as $row) {
|
||||
if (isset($row[$key])) {
|
||||
$array[$row[$key]] = $row[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
return empty($array) ? null : $array;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2122,9 +2122,12 @@ class FormHelper extends AppHelper {
|
|||
return $options;
|
||||
}
|
||||
|
||||
$name = !empty($this->_View->field) ? $this->_View->field : $this->_View->model;
|
||||
if (!empty($this->_View->fieldSuffix)) {
|
||||
$name .= '[' . $this->_View->fieldSuffix . ']';
|
||||
$entity = $this->_View->entity();
|
||||
$model = $this->model();
|
||||
$name = $model === $entity[0] && isset($entity[1]) ? $entity[1] : $entity[0];
|
||||
$last = $entity[count($entity) - 1];
|
||||
if (in_array($last, $this->_fieldSuffixes)) {
|
||||
$name .= '[' . $last . ']';
|
||||
}
|
||||
|
||||
if (is_array($options)) {
|
||||
|
|
Loading…
Reference in a new issue