Permalink
Browse files

Don't select year 0 when there are all 0's.

Year 0 is almost never a 'good' selection value and causes odd behavior
when paired with MySQL.

Fixes #2658
  • Loading branch information...
markstory committed Jan 15, 2014
1 parent ace586e commit f25e84f4fb6833f642e9db81450ff4fd85c1fca8
Showing with 24 additions and 1 deletion.
  1. +19 −0 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  2. +5 −1 lib/Cake/View/Helper/FormHelper.php
@@ -6273,6 +6273,25 @@ public function testDateTimeWithBogusData() {
$this->assertNotRegExp('/selected="selected">\d/', $result);
}
+/**
+ * testDateTime all zeros
+ *
+ * @return void
+ */
+ public function testDateTimeAllZeros() {
+ $result = $this->Form->dateTime('Contact.date',
+ 'DMY',
+ false,
+ array(
+ 'empty' => array('day' => '-', 'month' => '-', 'year' => '-'),
+ 'value' => '0000-00-00'
+ )
+ );
+
+ $this->assertRegExp('/<option value="">-<\/option>/', $result);
+ $this->assertNotRegExp('/<option value="0" selected="selected">0<\/option>/', $result);
+ }
+
/**
* testDateTimeEmptyAsArray
*
@@ -2825,7 +2825,11 @@ protected function _generateOptions($name, $options = array()) {
if ($min > $max) {
list($min, $max) = array($max, $min);
}
- if (!empty($options['value']) && (int)$options['value'] < $min) {
+ if (
+ !empty($options['value']) &&
+ (int)$options['value'] < $min &&
+ (int)$options['value'] > 0
+ ) {
$min = (int)$options['value'];
} elseif (!empty($options['value']) && (int)$options['value'] > $max) {
$max = (int)$options['value'];

0 comments on commit f25e84f

Please sign in to comment.