updating formhelper dateTime, fixes 3753, tests added

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6182 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-12-21 19:09:46 +00:00
parent 9f8b4b2cd5
commit e6bd38d7d1
2 changed files with 28 additions and 8 deletions

View file

@ -1286,7 +1286,7 @@ class FormHelper extends AppHelper {
$selected = $this->value($fieldName);
}
if (empty($selected)) {
if ($selected === null && $showEmpty !== true) {
$selected = time();
}
@ -1325,7 +1325,7 @@ class FormHelper extends AppHelper {
}
}
$elements = array('Day','Month','Year','Hour','Minute','Meridian');
$attributes = array_merge(array('minYear' => null, 'maxYear' => null, 'separator' => '-'), $attributes);
$attributes = array_merge(array('minYear' => null, 'maxYear' => null, 'separator' => '-'), (array)$attributes);
$minYear = $attributes['minYear'];
$maxYear = $attributes['maxYear'];
$separator = $attributes['separator'];
@ -1431,7 +1431,6 @@ class FormHelper extends AppHelper {
* @return array
*/
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) {
$select = array();
$attributes = array_merge(array('escape' => true, 'style' => null), $attributes);
$selectedIsEmpty = ($selected === '' || $selected === null);
@ -1463,8 +1462,9 @@ class FormHelper extends AppHelper {
$title = $title['name'];
unset($htmlOptions['name'], $htmlOptions['value']);
}
if ($name !== null) {
if ((!$selectedIsEmpty && ($selected == $name)) || ($selectedIsArray && in_array($name, $selected))) {
if ((!$selectedIsEmpty && $selected == $name) || ($selectedIsArray && in_array($name, $selected))) {
if ($attributes['style'] === 'checkbox') {
$htmlOptions['checked'] = true;
} else {

View file

@ -978,6 +978,28 @@ class FormHelperTest extends CakeTestCase {
$this->assertNoPattern('/^<input[^<>]+\/><input[^<>]+checked="checked"[^<>]+\/>$/', $result);
}
function testDateTime() {
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', null, array(), false);
$this->assertPattern('/<option[^<>]+value="'.date('m').'"[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
$this->assertPattern('/<option\s+value=""[^>]*>/', $result);
$this->assertNoPattern('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', false);
$this->assertPattern('/<option\s+value=""[^>]*>/', $result);
$this->assertNoPattern('/<option[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', '');
$this->assertPattern('/<option\s+value=""[^>]*>/', $result);
$this->assertNoPattern('/<option[^<>]+selected="selected"[^>]*>/', $result);
$this->Form->data['Contact']['data'] = null;
$result = $this->Form->dateTime('Contact.date', 'DMY', '12');
$this->assertPattern('/<option\s+value=""[^>]*>/', $result);
$this->assertNoPattern('/<option[^<>]+selected="selected"[^>]*>/', $result);
}
function testMonth() {
$result = $this->Form->month('Model.field');
$this->assertPattern('/^<select[^<>]+name="data\[Model\]\[field\]\[month\]"[^<>]*>/', $result);
@ -1119,7 +1141,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/^<input type="file"[^<>]+id="ModelUpload"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|value|id]=[^<>]*>$/', $result);
$this->Form->data['Model.upload'] = array("name" => "", "type" => "", "tmp_name" => "", "error" => 4, "size" => 0);
$result = $this->Form->file('Model.upload');
$result = $this->Form->input('Model.upload', array('type' => 'file'));
@ -1158,11 +1180,9 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->submit('cake.power.gif');
$this->assertEqual('<div class="submit"><input type="image" src="img/cake.power.gif" /></div>', $result);
$result = $this->Form->submit('Not.an.image');
$this->assertEqual('<div class="submit"><input type="submit" value="Not.an.image" /></div>', $result);
}
function testFormCreate() {