mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-09 04:52:42 +00:00
Fixing Helper::value() when models exist in ClassRegistry
and field values are empty. Fixes #1817
This commit is contained in:
parent
81a2563a05
commit
1d0d3f80fb
2 changed files with 37 additions and 13 deletions
|
@ -366,7 +366,34 @@ class HelperTest extends CakeTestCase {
|
|||
$this->Helper->setEntity('Post.2.created.year');
|
||||
$result = $this->Helper->value('Post.2.created.year');
|
||||
$this->assertEqual($result, '2008');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test default values with value()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testValueWithDefault() {
|
||||
$this->Helper->request->data = array('zero' => 0);
|
||||
$this->Helper->setEntity('zero');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
||||
$this->assertEqual($result, array('value' => 0));
|
||||
|
||||
$this->Helper->request->data = array('zero' => '0');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
||||
$this->assertEqual($result, array('value' => '0'));
|
||||
|
||||
$this->Helper->setEntity('inexistent');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'inexistent');
|
||||
$this->assertEqual($result, array('value' => 'something'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test habtm data fetching and ensure no pollution happens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testValueHabtmKeys() {
|
||||
$this->Helper->request->data = array(
|
||||
'HelperTestTag' => array('HelperTestTag' => '')
|
||||
);
|
||||
|
@ -393,18 +420,15 @@ class HelperTest extends CakeTestCase {
|
|||
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
|
||||
$this->assertEqual($result, array(3 => 3, 5 => 5));
|
||||
|
||||
$this->Helper->request->data = array('zero' => 0);
|
||||
$this->Helper->setEntity('zero');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
||||
$this->assertEqual($result, array('value' => 0));
|
||||
|
||||
$this->Helper->request->data = array('zero' => '0');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'zero');
|
||||
$this->assertEqual($result, array('value' => '0'));
|
||||
|
||||
$this->Helper->setEntity('inexistent');
|
||||
$result = $this->Helper->value(array('default' => 'something'), 'inexistent');
|
||||
$this->assertEqual($result, array('value' => 'something'));
|
||||
$this->Helper->request->data = array(
|
||||
'HelperTestTag' => array(
|
||||
'body' => '',
|
||||
'title' => 'winning'
|
||||
),
|
||||
);
|
||||
$this->Helper->setEntity('HelperTestTag.body');
|
||||
$result = $this->Helper->value('HelperTestTag.body');
|
||||
$this->assertEqual($result, '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -638,7 +638,7 @@ class Helper extends Object {
|
|||
$result = Set::extract($data, implode('.', $entity));
|
||||
}
|
||||
|
||||
$habtmKey = $entity[0];
|
||||
$habtmKey = $this->field();
|
||||
if (empty($result) && isset($data[$habtmKey][$habtmKey]) && is_array($data[$habtmKey])) {
|
||||
$result = $data[$habtmKey][$habtmKey];
|
||||
} elseif (empty($result) && isset($data[$habtmKey]) && is_array($data[$habtmKey])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue