Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Patrick Barabe 2014-02-20 08:52:36 -07:00
commit 08ba104543
3 changed files with 122 additions and 13 deletions

View file

@ -159,7 +159,7 @@ class RequestHandlerComponent extends Component {
return;
}
$accepts = $this->response->mapType($this->request->parseAccept());
$accepts = $this->response->mapType($accept);
$preferedTypes = current($accepts);
if (array_intersect($preferedTypes, array('html', 'xhtml'))) {
return null;

View file

@ -6552,6 +6552,22 @@ class FormHelperTest extends CakeTestCase {
'*/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '12a';
$result = $this->Form->month('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
date('F', strtotime('2008-01-01 00:00:00')),
'/option',
array('option' => array('value' => '02')),
date('F', strtotime('2008-02-01 00:00:00')),
'/option',
'*/select',
);
$this->assertTags($result, $expected);
}
/**
@ -6662,6 +6678,23 @@ class FormHelperTest extends CakeTestCase {
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '12e';
$result = $this->Form->day('Model.field');
$expected = array(
array('select' => array('name' => 'data[Model][field][day]', 'id' => 'ModelFieldDay')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$daysRegex,
'/select',
);
$this->assertTags($result, $expected);
}
/**
@ -6754,6 +6787,25 @@ class FormHelperTest extends CakeTestCase {
'/select',
);
$this->assertTags($result, $expected);
$result = $this->Form->minute('Model.field', array('value' => '#invalid#'));
$expected = array(
array('select' => array('name' => 'data[Model][field][min]', 'id' => 'ModelFieldMin')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '01')),
'01',
'/option',
array('option' => array('value' => '02')),
'02',
'/option',
$minutesRegex,
'/select',
);
$this->assertTags($result, $expected);
}
/**
@ -6852,6 +6904,23 @@ class FormHelperTest extends CakeTestCase {
'/select',
);
$this->assertTags($result, $expected);
$this->Form->request->data['Model']['field'] = '18a';
$result = $this->Form->hour('Model.field', false);
$expected = array(
array('select' => array('name' => 'data[Model][field][hour]', 'id' => 'ModelFieldHour')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '01')),
'1',
'/option',
array('option' => array('value' => '02')),
'2',
'/option',
$hoursRegex,
'/select',
);
$this->assertTags($result, $expected);
}
/**
@ -7034,6 +7103,22 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->year('published', array(), array(), array('empty' => false));
$this->assertContains('data[Contact][published][year]', $result);
$this->Form->request->data['Contact']['published'] = '2014ee';
$result = $this->Form->year('Contact.published', 2010, 2011);
$expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear')),
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '2011')),
'2011',
'/option',
array('option' => array('value' => '2010')),
'2010',
'/option',
'/select',
);
$this->assertTags($result, $expected);
}
/**

View file

@ -2116,7 +2116,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) {
$attributes['value'] = date_create($attributes['value'])->format('d');
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('d');
}
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
}
@ -2163,7 +2167,11 @@ class FormHelper extends AppHelper {
}
if (strlen($attributes['value']) > 4 || $attributes['value'] === 'now') {
$attributes['value'] = date_create($attributes['value'])->format('Y');
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('Y');
}
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
}
@ -2199,7 +2207,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('month', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) {
$attributes['value'] = date_create($attributes['value'])->format('m');
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('m');
}
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
}
@ -2235,11 +2247,15 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) {
$Date = new DateTime($attributes['value']);
if ($format24Hours) {
$attributes['value'] = $Date->format('H');
} else {
$attributes['value'] = $Date->format('g');
try {
$date = new DateTime($attributes['value']);
if ($format24Hours) {
$attributes['value'] = $date->format('H');
} else {
$attributes['value'] = $date->format('g');
}
} catch (Exception $e) {
$attributes['value'] = null;
}
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
@ -2278,7 +2294,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) {
$attributes['value'] = date_create($attributes['value'])->format('i');
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('i');
}
} elseif ($attributes['value'] === false) {
$attributes['value'] = null;
}
@ -2329,7 +2349,7 @@ class FormHelper extends AppHelper {
* - `value` The selected value of the input.
*
* @param string $fieldName Prefix name for the SELECT element
* @param array|string $attributes Array of Attributes
* @param array $attributes Array of Attributes
* @return string Completed meridian select input
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::meridian
*/
@ -2346,7 +2366,11 @@ class FormHelper extends AppHelper {
$attributes['value'] = date('a');
}
} else {
$attributes['value'] = date_create($attributes['value'])->format('a');
$date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('a');
}
}
}
}
@ -2380,7 +2404,7 @@ class FormHelper extends AppHelper {
* @param string $fieldName Prefix name for the SELECT element
* @param string $dateFormat DMY, MDY, YMD, or null to not generate date inputs.
* @param string $timeFormat 12, 24, or null to not generate time inputs.
* @param array|string $attributes array of Attributes
* @param array $attributes Array of Attributes
* @return string Generated set of select boxes for the date and time formats chosen.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::dateTime
*/