Merge branch 'master' into 2.5

This commit is contained in:
mark_story 2014-02-24 21:19:17 -05:00
commit 0f584c0e8b
7 changed files with 177 additions and 24 deletions

View file

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

View file

@ -207,7 +207,9 @@ class CakeRequest implements ArrayAccess {
$query = $_GET; $query = $_GET;
} }
unset($query[$this->base . '/' . str_replace('.', '_', urldecode($this->url))]); $unsetUrl = '/' . str_replace('.', '_', urldecode($this->url));
unset($query[$unsetUrl]);
unset($query[$this->base . $unsetUrl]);
if (strpos($this->url, '?') !== false) { if (strpos($this->url, '?') !== false) {
list(, $querystr) = explode('?', $this->url); list(, $querystr) = explode('?', $this->url);
parse_str($querystr, $queryArgs); parse_str($querystr, $queryArgs);

View file

@ -684,7 +684,7 @@ class HttpSocket extends CakeSocket {
} }
unset($this->config[$key]); unset($this->config[$key]);
} }
if (empty($this->_context['ssl']['cafile'])) { if (empty($this->config['context']['ssl']['cafile'])) {
$this->config['context']['ssl']['cafile'] = CAKE . 'Config' . DS . 'cacert.pem'; $this->config['context']['ssl']['cafile'] = CAKE . 'Config' . DS . 'cacert.pem';
} }
if (!empty($this->config['context']['ssl']['verify_host'])) { if (!empty($this->config['context']['ssl']['verify_host'])) {

View file

@ -1660,12 +1660,15 @@ class ValidationTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testDecimalLocaleSet() { public function testDecimalLocaleSet() {
$this->skipIf(DS === '\\', 'The locale is not supported in Windows and affect the others tests.'); $this->skipIf(DS === '\\', 'The locale is not supported in Windows and affects other tests.');
$restore = setlocale(LC_NUMERIC, 0); $restore = setlocale(LC_NUMERIC, 0);
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available."); $this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
$this->assertTrue(Validation::decimal(1.54)); $this->assertTrue(Validation::decimal(1.54), '1.54 should be considered a valid float');
$this->assertTrue(Validation::decimal('1.54')); $this->assertTrue(Validation::decimal('1.54'), '"1.54" should be considered a valid float');
$this->assertTrue(Validation::decimal(12345.67), '12345.67 should be considered a valid float');
$this->assertTrue(Validation::decimal('12,345.67'), '"12,345.67" should be considered a valid float');
setlocale(LC_NUMERIC, $restore); setlocale(LC_NUMERIC, $restore);
} }

View file

@ -6604,6 +6604,22 @@ class FormHelperTest extends CakeTestCase {
'*/select', '*/select',
); );
$this->assertTags($result, $expected); $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);
} }
/** /**
@ -6714,6 +6730,23 @@ class FormHelperTest extends CakeTestCase {
'/select', '/select',
); );
$this->assertTags($result, $expected); $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);
} }
/** /**
@ -6806,6 +6839,25 @@ class FormHelperTest extends CakeTestCase {
'/select', '/select',
); );
$this->assertTags($result, $expected); $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);
} }
/** /**
@ -6904,6 +6956,23 @@ class FormHelperTest extends CakeTestCase {
'/select', '/select',
); );
$this->assertTags($result, $expected); $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);
} }
/** /**
@ -7086,6 +7155,22 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->year('published', array(), array(), array('empty' => false)); $result = $this->Form->year('published', array(), array(), array('empty' => false));
$this->assertContains('data[Contact][published][year]', $result); $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);
} }
/** /**
@ -7397,6 +7482,25 @@ class FormHelperTest extends CakeTestCase {
$this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false); $this->assertTrue(strpos($result, '<input type="hidden" name="data[extra]" value="value"/>') !== false);
} }
/**
* Test using postButton with N dimensional data.
*
* @return void
*/
public function testPostButtonNestedData() {
$data = array(
'one' => array(
'two' => array(
3, 4, 5
)
)
);
$result = $this->Form->postButton('Send', '/', array('data' => $data));
$this->assertContains('<input type="hidden" name="data[one][two][0]" value="3"', $result);
$this->assertContains('<input type="hidden" name="data[one][two][1]" value="4"', $result);
$this->assertContains('<input type="hidden" name="data[one][two][2]" value="5"', $result);
}
/** /**
* Test that postButton adds _Token fields. * Test that postButton adds _Token fields.
* *
@ -7518,6 +7622,25 @@ class FormHelperTest extends CakeTestCase {
)); ));
} }
/**
* Test using postLink with N dimensional data.
*
* @return void
*/
public function testPostLinkNestedData() {
$data = array(
'one' => array(
'two' => array(
3, 4, 5
)
)
);
$result = $this->Form->postLink('Send', '/', array('data' => $data));
$this->assertContains('<input type="hidden" name="data[one][two][0]" value="3"', $result);
$this->assertContains('<input type="hidden" name="data[one][two][1]" value="4"', $result);
$this->assertContains('<input type="hidden" name="data[one][two][2]" value="5"', $result);
}
/** /**
* test creating postLinks after a GET form. * test creating postLinks after a GET form.
* *

View file

@ -426,10 +426,11 @@ class Validation {
} }
} }
// Workaround localized floats. // account for localized floats.
if (is_float($check)) { $data = localeconv();
$check = str_replace(',', '.', strval($check)); $check = str_replace($data['thousands_sep'], '', $check);
} $check = str_replace($data['decimal_point'], '.', $check);
return self::_check($check, $regex); return self::_check($check, $regex);
} }

View file

@ -1735,7 +1735,7 @@ class FormHelper extends AppHelper {
public function postButton($title, $url, $options = array()) { public function postButton($title, $url, $options = array()) {
$out = $this->create(false, array('id' => false, 'url' => $url)); $out = $this->create(false, array('id' => false, 'url' => $url));
if (isset($options['data']) && is_array($options['data'])) { if (isset($options['data']) && is_array($options['data'])) {
foreach ($options['data'] as $key => $value) { foreach (Hash::flatten($options['data']) as $key => $value) {
$out .= $this->hidden($key, array('value' => $value, 'id' => false)); $out .= $this->hidden($key, array('value' => $value, 'id' => false));
} }
unset($options['data']); unset($options['data']);
@ -1810,7 +1810,7 @@ class FormHelper extends AppHelper {
$fields = array(); $fields = array();
if (isset($options['data']) && is_array($options['data'])) { if (isset($options['data']) && is_array($options['data'])) {
foreach ($options['data'] as $key => $value) { foreach (Hash::flatten($options['data']) as $key => $value) {
$fields[$key] = $value; $fields[$key] = $value;
$out .= $this->hidden($key, array('value' => $value, 'id' => false)); $out .= $this->hidden($key, array('value' => $value, 'id' => false));
} }
@ -2153,7 +2153,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('day', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('day', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { 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) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
} }
@ -2200,7 +2204,11 @@ class FormHelper extends AppHelper {
} }
if (strlen($attributes['value']) > 4 || $attributes['value'] === 'now') { 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) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
} }
@ -2236,7 +2244,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('month', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('month', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { 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) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
} }
@ -2272,11 +2284,15 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('hour', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { if (strlen($attributes['value']) > 2) {
$Date = new DateTime($attributes['value']); try {
$date = new DateTime($attributes['value']);
if ($format24Hours) { if ($format24Hours) {
$attributes['value'] = $Date->format('H'); $attributes['value'] = $date->format('H');
} else { } else {
$attributes['value'] = $Date->format('g'); $attributes['value'] = $date->format('g');
}
} catch (Exception $e) {
$attributes['value'] = null;
} }
} elseif ($attributes['value'] === false) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
@ -2315,7 +2331,11 @@ class FormHelper extends AppHelper {
$attributes = $this->_dateTimeSelected('min', $fieldName, $attributes); $attributes = $this->_dateTimeSelected('min', $fieldName, $attributes);
if (strlen($attributes['value']) > 2) { 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) { } elseif ($attributes['value'] === false) {
$attributes['value'] = null; $attributes['value'] = null;
} }
@ -2366,7 +2386,7 @@ class FormHelper extends AppHelper {
* - `value` The selected value of the input. * - `value` The selected value of the input.
* *
* @param string $fieldName Prefix name for the SELECT element * @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 * @return string Completed meridian select input
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::meridian * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::meridian
*/ */
@ -2383,7 +2403,11 @@ class FormHelper extends AppHelper {
$attributes['value'] = date('a'); $attributes['value'] = date('a');
} }
} else { } else {
$attributes['value'] = date_create($attributes['value'])->format('a'); $date = date_create($attributes['value']);
$attributes['value'] = null;
if ($date) {
$attributes['value'] = $date->format('a');
}
} }
} }
} }
@ -2417,7 +2441,7 @@ class FormHelper extends AppHelper {
* @param string $fieldName Prefix name for the SELECT element * @param string $fieldName Prefix name for the SELECT element
* @param string $dateFormat DMY, MDY, YMD, or null to not generate date inputs. * @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 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. * @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 * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#FormHelper::dateTime
*/ */