Skip to content

Commit ee5e8c9

Browse files
author
euromark
committed
fix issue with FormHelper and undefined variable and extract
1 parent 290c343 commit ee5e8c9

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/Cake/Test/Case/View/Helper/FormHelperTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6631,12 +6631,21 @@ public function testYearAutoExpandRange() {
66316631
/**
66326632
* testInputDate method
66336633
*
6634-
* Test various inputs with type date and different dateFormat values
6634+
* Test various inputs with type date and different dateFormat values.
6635+
* Failing to provide a dateFormat key should not error.
6636+
* It should simply not pre-select any value then.
66356637
*
66366638
* @return void
66376639
*/
66386640
public function testInputDate() {
6639-
$this->Form->request->data = array();
6641+
$this->Form->request->data = array(
6642+
'User' => array(
6643+
'month_year' => array('month' => date('m')),
6644+
'just_year' => array('month' => date('m')),
6645+
'just_month' => array('year' => date('Y')),
6646+
'just_day' => array('month' => date('m')),
6647+
)
6648+
);
66406649
$this->Form->create('User');
66416650
$result = $this->Form->input('month_year',
66426651
array(
@@ -6649,7 +6658,7 @@ public function testInputDate() {
66496658
)
66506659
);
66516660
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
6652-
$this->assertContains('value="2008" selected="selected"', $result);
6661+
$this->assertNotContains('value="2008" selected="selected"', $result);
66536662

66546663
$result = $this->Form->input('just_year',
66556664
array(
@@ -6660,7 +6669,7 @@ public function testInputDate() {
66606669
'maxYear' => date('Y', strtotime('+20 years'))
66616670
)
66626671
);
6663-
$this->assertContains('value="' . date('Y') . '" selected="selected"', $result);
6672+
$this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);
66646673

66656674
$result = $this->Form->input('just_month',
66666675
array(
@@ -6670,7 +6679,7 @@ public function testInputDate() {
66706679
'empty' => false,
66716680
)
66726681
);
6673-
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
6682+
$this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);
66746683

66756684
$result = $this->Form->input('just_day',
66766685
array(
@@ -6680,7 +6689,7 @@ public function testInputDate() {
66806689
'empty' => false,
66816690
)
66826691
);
6683-
$this->assertContains('value="' . date('d') . '" selected="selected"', $result);
6692+
$this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
66846693
}
66856694

66866695
/**

lib/Cake/View/Helper/FormHelper.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,7 @@ public function year($fieldName, $minYear = null, $maxYear = null, $attributes =
21142114
$attributes += array('empty' => true, 'value' => null);
21152115
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
21162116
if (is_array($value)) {
2117+
$year = null;
21172118
extract($value);
21182119
$attributes['value'] = $year;
21192120
} else {
@@ -2305,6 +2306,7 @@ public function meridian($fieldName, $attributes = array()) {
23052306
$attributes += array('empty' => true, 'value' => null);
23062307
if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) {
23072308
if (is_array($value)) {
2309+
$meridian = null;
23082310
extract($value);
23092311
$attributes['value'] = $meridian;
23102312
} else {

0 commit comments

Comments
 (0)