Skip to content

Commit

Permalink
Merge pull request #2908 from markstory/3.0-datetime-fixes
Browse files Browse the repository at this point in the history
3.0 datetime fixes
  • Loading branch information
lorenzo committed Feb 27, 2014
2 parents 2d9b6cc + 61a54c1 commit 8ceb359
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 72 deletions.
7 changes: 4 additions & 3 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -83,10 +83,11 @@ public function fixturize($test) {
protected function _aliasConnections() {
$connections = ConnectionManager::configured();
ConnectionManager::alias('test', 'default');
$map = [
'test' => 'default',
];
$map = [];
foreach ($connections as $connection) {
if ($connection === 'test' || $connection === 'default') {
continue;
}
if (isset($map[$connection])) {
continue;
}
Expand Down
10 changes: 9 additions & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -894,6 +894,8 @@ protected function _getInput($fieldName, $options) {
case 'url':
$options = $this->_initInputField($fieldName, $options);
return $this->widget($options['type'], $options);
case 'date':
return $this->dateTime($fieldName, $options);
default:
return $this->{$options['type']}($fieldName, $options);
}
Expand Down Expand Up @@ -1991,8 +1993,14 @@ protected function _datetimeOptions($options) {
unset($options['interval'], $options['round']);

if (!isset($options['val'])) {
$options['val'] = new \DateTime();
$val = new \DateTime();
$currentYear = $val->format('Y');
if (isset($options['year']['end']) && $options['year']['end'] < $currentYear) {
$val->setDate($options['year']['end'], $val->format('n'), $val->format('j'));
}
$options['val'] = $val;
}

return $options;
}

Expand Down
85 changes: 17 additions & 68 deletions tests/TestCase/View/Helper/FormHelperTest.php
Expand Up @@ -4821,7 +4821,6 @@ public function testDateTimeRounding() {
* @return void
*/
public function testDatetimeWithDefault() {
$this->markTestIncomplete('Need to revisit soon.');
$result = $this->Form->dateTime('Contact.updated', array('value' => '2009-06-01 11:15:30'));
$this->assertRegExp('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertRegExp('/<option[^<>]+value="01"[^<>]+selected="selected"[^>]*>1<\/option>/', $result);
Expand Down Expand Up @@ -5406,68 +5405,23 @@ public function testYearAutoExpandRange() {
}

/**
* testInputDate method
*
* 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.
* Test that input() accepts the type of date and passes options in.
*
* @return void
*/
public function testInputDate() {
$this->markTestIncomplete('Need to revisit once models work again.');
$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')),
)
'month_year' => array('month' => date('m')),
);
$this->Form->create('User');
$result = $this->Form->input('month_year',
array(
'label' => false,
'div' => false,
'type' => 'date',
'dateFormat' => 'MY',
'minYear' => 2006,
'maxYear' => 2008
)
);
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
$this->assertNotContains('value="2008" selected="selected"', $result);

$result = $this->Form->input('just_year',
array(
'type' => 'date',
$this->Form->create($this->article);
$result = $this->Form->input('month_year', array(
'label' => false,
'dateFormat' => 'Y',
'minYear' => date('Y'),
'maxYear' => date('Y', strtotime('+20 years'))
)
);
$this->assertNotContains('value="' . date('Y') . '" selected="selected"', $result);

$result = $this->Form->input('just_month',
array(
'type' => 'date',
'label' => false,
'dateFormat' => 'M',
'empty' => false,
)
);
$this->assertNotContains('value="' . date('m') . '" selected="selected"', $result);

$result = $this->Form->input('just_day',
array(
'type' => 'date',
'label' => false,
'dateFormat' => 'D',
'empty' => false,
)
);
$this->assertNotContains('value="' . date('d') . '" selected="selected"', $result);
'minYear' => 2006,
'maxYear' => 2008
));
$this->assertContains('value="' . date('m') . '" selected="selected"', $result);
$this->assertNotContains('value="2008" selected="selected"', $result);
}

/**
Expand All @@ -5479,19 +5433,14 @@ public function testInputDate() {
* @return void
*/
public function testInputDateMaxYear() {
$this->markTestIncomplete('Need to revisit once models work again.');
$this->Form->request->data = array();
$this->Form->create('User');
$result = $this->Form->input('birthday',
array(
'label' => false,
'div' => false,
'type' => 'date',
'dateFormat' => 'DMY',
'minYear' => 2006,
'maxYear' => 2008
)
);
$this->Form->request->data = [];
$this->Form->create($this->article);
$result = $this->Form->input('birthday', array(
'label' => false,
'type' => 'date',
'minYear' => 2006,
'maxYear' => 2008
));
$this->assertContains('value="2008" selected="selected"', $result);
}

Expand Down

0 comments on commit 8ceb359

Please sign in to comment.