diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 4b6cfb7e1..bd0dbb2c8 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -7430,6 +7430,53 @@ class FormHelperTest extends CakeTestCase { $this->assertNotContains('value="' . date('d') . '" selected="selected"', $result); } +/** + * testInputDate method + * + * Test various inputs with type date and different option attributes. + * + * @return void + */ + public function testInputDateOptions() { + $this->Form->create('User'); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'day', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'month', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'year', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + + $result = $this->Form->input('date', + array( + 'label' => false, + 'type' => 'hour', + 'class' => 'form-control' + ) + ); + $this->assertContains('class="form-control"', $result); + } + /** * testInputDateMaxYear method * diff --git a/lib/Cake/View/Helper/FormHelper.php b/lib/Cake/View/Helper/FormHelper.php index 880f5fd3f..2a9f5be6c 100644 --- a/lib/Cake/View/Helper/FormHelper.php +++ b/lib/Cake/View/Helper/FormHelper.php @@ -2213,6 +2213,11 @@ class FormHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::year */ public function year($fieldName, $minYear = null, $maxYear = null, $attributes = array()) { + if (is_array($minYear)) { + $attributes = $minYear; + $minYear = null; + } + $attributes += array('empty' => true, 'value' => null); if ((empty($attributes['value']) || $attributes['value'] === true) && $value = $this->value($fieldName)) { if (is_array($value)) { @@ -2310,6 +2315,11 @@ class FormHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::hour */ public function hour($fieldName, $format24Hours = false, $attributes = array()) { + if (is_array($format24Hours)) { + $attributes = $format24Hours; + $format24Hours = false; + } + $attributes += array('empty' => true, 'value' => null); $attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes);