Skip to content
Permalink
Browse files

Adding tests

  • Loading branch information...
dereuromark committed May 14, 2015
1 parent 82dd42e commit 3ed209d5d3e961787b016cde8d869602579a781f
Showing with 62 additions and 6 deletions.
  1. +3 −2 src/View/Helper/FormHelper.php
  2. +59 −4 tests/TestCase/View/Helper/FormHelperTest.php
@@ -2212,7 +2212,6 @@ protected function _datetimeOptions($options)
$options[$type]['empty'] = $options['empty'][$type];
}
}
unset($options['empty']);
$hasYear = is_array($options['year']);
if ($hasYear && isset($options['minYear'])) {
@@ -2242,7 +2241,7 @@ protected function _datetimeOptions($options)
}
unset($options['interval'], $options['round']);
if ($options['val'] === true) {
if ($options['val'] === true || $options['val'] === null && isset($options['empty']) && $options['empty'] === false) {
$val = new DateTime();
$currentYear = $val->format('Y');
if (isset($options['year']['end']) && $options['year']['end'] < $currentYear) {
@@ -2251,6 +2250,8 @@ protected function _datetimeOptions($options)
$options['val'] = $val;
}
unset($options['empty']);
return $options;
}
@@ -4969,6 +4969,57 @@ public function testDateTime()
{
extract($this->dateRegex);
$result = $this->Form->dateTime('Contact.date', ['default' => true]);
$now = strtotime('now');
$expected = [
['select' => ['name' => 'Contact[date][year]']],
['option' => ['value' => '']],
'/option',
$yearsRegex,
['option' => ['value' => date('Y', $now), 'selected' => 'selected']],
date('Y', $now),
'/option',
'*/select',
['select' => ['name' => 'Contact[date][month]']],
['option' => ['value' => '']],
'/option',
$monthsRegex,
['option' => ['value' => date('m', $now), 'selected' => 'selected']],
date('F', $now),
'/option',
'*/select',
['select' => ['name' => 'Contact[date][day]']],
['option' => ['value' => '']],
'/option',
$daysRegex,
['option' => ['value' => date('d', $now), 'selected' => 'selected']],
date('j', $now),
'/option',
'*/select',
['select' => ['name' => 'Contact[date][hour]']],
['option' => ['value' => '']],
'/option',
$hoursRegex,
['option' => ['value' => date('H', $now), 'selected' => 'selected']],
date('G', $now),
'/option',
'*/select',
['select' => ['name' => 'Contact[date][minute]']],
['option' => ['value' => '']],
'/option',
$minutesRegex,
['option' => ['value' => date('i', $now), 'selected' => 'selected']],
date('i', $now),
'/option',
'*/select',
];
$this->assertHtml($expected, $result);
// Empty=>false implies Default=>true, as selecting the "first" dropdown value is useless
$result = $this->Form->dateTime('Contact.date', ['empty' => false]);
$now = strtotime('now');
$expected = [
@@ -5069,6 +5120,7 @@ public function testDatetimeEmpty()
$result = $this->Form->dateTime('Contact.date', [
'timeFormat' => 12,
'empty' => true,
'default' => true
]);
$expected = [
['select' => ['name' => 'Contact[date][year]']],
@@ -5248,7 +5300,8 @@ public function testDateTimeEmptyAsArray()
'hour' => 'HOUR',
'minute' => 'MINUTE',
'meridian' => false
]
],
'default' => true
]);
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
@@ -5259,7 +5312,8 @@ public function testDateTimeEmptyAsArray()
$this->assertNotRegExp('/<option value=""><\/option>/', $result);
$result = $this->Form->dateTime('Contact.date', [
'empty' => ['day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR']
'empty' => ['day' => 'DAY', 'month' => 'MONTH', 'year' => 'YEAR'],
'default' => true
]);
$this->assertRegExp('/<option value="">DAY<\/option>/', $result);
@@ -5852,7 +5906,7 @@ public function testInputLabelFalse()
* testInputDateMaxYear method
*
* Let's say we want to only allow users born from 2006 to 2008 to register
* This being the first singup page, we still don't have any data
* This being the first signup page, we still don't have any data
*
* @return void
*/
@@ -5864,7 +5918,8 @@ public function testInputDateMaxYear()
'label' => false,
'type' => 'date',
'minYear' => 2006,
'maxYear' => 2008
'maxYear' => 2008,
'default' => true
]);
$this->assertContains('value="2008" selected="selected"', $result);
}

0 comments on commit 3ed209d

Please sign in to comment.
You can’t perform that action at this time.