Skip to content

Commit

Permalink
Fixing empty value check to avoid a mistaken default value selection …
Browse files Browse the repository at this point in the history
…in Helper::value. closes #290
  • Loading branch information
lorenzo committed Mar 10, 2010
1 parent 9a9bc36 commit d8a757c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/view/helper.php
Expand Up @@ -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']);
Expand Down
13 changes: 13 additions & 0 deletions cake/tests/cases/libs/view/helper.test.php
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit d8a757c

Please sign in to comment.