Permalink
Browse files

Fixing empty value check to avoid a mistaken default value selection …

…in Helper::value. closes #290
  • Loading branch information...
1 parent 9a9bc36 commit d8a757ce759983320343d84567a9b820b0932ff5 @lorenzo lorenzo committed Mar 10, 2010
Showing with 14 additions and 1 deletion.
  1. +1 −1 cake/libs/view/helper.php
  2. +13 −0 cake/tests/cases/libs/view/helper.test.php
@@ -700,7 +700,7 @@ function value($options = array(), $field = null, $key = 'value') {
}
if (is_array($options)) {
- if (empty($result) && isset($options['default'])) {
+ if ($result === null && isset($options['default'])) {
$result = $options['default'];
}
unset($options['default']);
@@ -385,6 +385,19 @@ function testValue() {
$this->Helper->setEntity('HelperTestTag.HelperTestTag');
$result = $this->Helper->value('HelperTestTag.HelperTestTag');
$this->assertEqual($result, array(3 => 3, 5 => 5));
+
+ $this->Helper->data = array('zero' => 0);
+ $this->Helper->setEntity('zero');
+ $result = $this->Helper->value(array('default' => 'something'), 'zero');
+ $this->assertEqual($result, array('value' => 0));
+
+ $this->Helper->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'));
}
/**

0 comments on commit d8a757c

Please sign in to comment.