Skip to content

Commit

Permalink
fix issue with FormHelper and undefined variable and extract
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Jun 25, 2013
1 parent 290c343 commit ee5e8c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/Cake/Test/Case/View/Helper/FormHelperTest.php
Expand Up @@ -6631,12 +6631,21 @@ public function testYearAutoExpandRange() {
/**
* testInputDate method
*
* Test various inputs with type date and different dateFormat values
* Test various inputs with type date and different dateFormat values.
* Failing to provide a dateFormat key should not error.
* It should simply not pre-select any value then.
*
* @return void
*/
public function testInputDate() {
$this->Form->request->data = array();
$this->Form->request->data = array(
'User' => array(
'month_year' => array('month' => date('m')),
'just_year' => array('month' => date('m')),
'just_month' => array('year' => date('Y')),
'just_day' => array('month' => date('m')),
)
);
$this->Form->create('User');
$result = $this->Form->input('month_year',
array(
Expand All @@ -6649,7 +6658,7 @@ public function testInputDate() {
)
);
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
$this->assertContains('value="2008" selected="selected"', $result);
$this->assertNotContains('value="2008" selected="selected"', $result);

$result = $this->Form->input('just_year',
array(
Expand All @@ -6660,7 +6669,7 @@ public function testInputDate() {
'maxYear' => date('Y', strtotime('+20 years'))
)
);
$this->assertContains('value="' . date('Y') . '" selected="selected"', $result);
$this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);

$result = $this->Form->input('just_month',
array(
Expand All @@ -6670,7 +6679,7 @@ public function testInputDate() {
'empty' => false,
)
);
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
$this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);

$result = $this->Form->input('just_day',
array(
Expand All @@ -6680,7 +6689,7 @@ public function testInputDate() {
'empty' => false,
)
);
$this->assertContains('value="' . date('d') . '" selected="selected"', $result);
$this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/Cake/View/Helper/FormHelper.php
Expand Up @@ -2114,6 +2114,7 @@ public function year($fieldName, $minYear = null, $maxYear = null, $attributes =
$attributes += array('empty' => true, 'value' => null);
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
if (is_array($value)) {
$year = null;
extract($value);
$attributes['value'] = $year;
} else {
Expand Down Expand Up @@ -2305,6 +2306,7 @@ public function meridian($fieldName, $attributes = array()) {
$attributes += array('empty' => true, 'value' => null);
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
if (is_array($value)) {
$meridian = null;
extract($value);
$attributes['value'] = $meridian;
} else {
Expand Down

0 comments on commit ee5e8c9

Please sign in to comment.