mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'master' into 2.5
This commit is contained in:
commit
7e5c0f7185
10 changed files with 169 additions and 46 deletions
|
@ -269,6 +269,14 @@
|
|||
*/
|
||||
//date_default_timezone_set('UTC');
|
||||
|
||||
/**
|
||||
* `Config.timezone` is available in which you can set users' timezone string.
|
||||
* If a method of CakeTime class is called with $timezone parameter as null and `Config.timezone` is set,
|
||||
* then the value of `Config.timezone` will be used. This feature allows you to set users' timezone just
|
||||
* once instead of passing it each time in function calls.
|
||||
*/
|
||||
//Configure::write('Config.timezone', 'Europe/Paris')
|
||||
|
||||
/**
|
||||
*
|
||||
* Cache Engine Configuration
|
||||
|
|
|
@ -852,6 +852,7 @@ class Postgres extends DboSource {
|
|||
);
|
||||
|
||||
$out = str_replace('integer serial', 'serial', $out);
|
||||
$out = str_replace('bigint serial', 'bigserial', $out);
|
||||
if (strpos($out, 'timestamp DEFAULT')) {
|
||||
if (isset($column['null']) && $column['null']) {
|
||||
$out = str_replace('DEFAULT NULL', '', $out);
|
||||
|
|
|
@ -645,7 +645,8 @@ class DboSource extends DataSource {
|
|||
* by setting $options to `false`
|
||||
*
|
||||
* @param string $sql SQL statement
|
||||
* @param array $params parameters to be bound as values for the SQL statement
|
||||
* @param array|boolean $params Either parameters to be bound as values for the SQL statement,
|
||||
* or a boolean to control query caching.
|
||||
* @param array $options additional options for the query.
|
||||
* @return boolean|array Array of resultset rows, or false if no rows matched
|
||||
*/
|
||||
|
|
|
@ -1142,7 +1142,9 @@ class Model extends Object implements CakeEventListener {
|
|||
));
|
||||
}
|
||||
|
||||
$this->_schema = null;
|
||||
if ($sources) {
|
||||
$this->_schema = null;
|
||||
}
|
||||
}
|
||||
|
||||
$this->table = $this->useTable = $tableName;
|
||||
|
|
|
@ -572,6 +572,38 @@ class PostgresTest extends CakeTestCase {
|
|||
$db1->query('DROP TABLE ' . $db1->fullTableName('datatype_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* testCakeSchemaBegserial method
|
||||
*
|
||||
* Test that schema generated postgresql queries are valid.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCakeSchemaBigserial() {
|
||||
$db1 = ConnectionManager::getDataSource('test');
|
||||
$db1->cacheSources = false;
|
||||
|
||||
$db1->rawQuery('CREATE TABLE ' . $db1->fullTableName('bigserial_tests') . ' (
|
||||
"id" bigserial NOT NULL,
|
||||
"varchar" character varying(40) NOT NULL,
|
||||
PRIMARY KEY ("id")
|
||||
)');
|
||||
|
||||
$schema = new CakeSchema(array('connection' => 'test'));
|
||||
$result = $schema->read(array(
|
||||
'connection' => 'test',
|
||||
'models' => array('BigserialTest')
|
||||
));
|
||||
$schema->tables = array(
|
||||
'bigserial_tests' => $result['tables']['missing']['bigserial_tests']
|
||||
);
|
||||
$result = $db1->createSchema($schema, 'bigserial_tests');
|
||||
|
||||
$this->assertContains('"id" bigserial NOT NULL,', $result);
|
||||
|
||||
$db1->query('DROP TABLE ' . $db1->fullTableName('bigserial_tests'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index generation from table info.
|
||||
*
|
||||
|
|
|
@ -1415,14 +1415,16 @@ class ValidationTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function testDateMyNumeric() {
|
||||
$this->assertTrue(Validation::date('12/2006', array('my')));
|
||||
$this->assertTrue(Validation::date('01/2006', array('my')));
|
||||
$this->assertTrue(Validation::date('12-2006', array('my')));
|
||||
$this->assertTrue(Validation::date('12.2006', array('my')));
|
||||
$this->assertTrue(Validation::date('12 2006', array('my')));
|
||||
$this->assertFalse(Validation::date('12/06', array('my')));
|
||||
$this->assertFalse(Validation::date('12-06', array('my')));
|
||||
$this->assertFalse(Validation::date('12.06', array('my')));
|
||||
$this->assertFalse(Validation::date('12 06', array('my')));
|
||||
$this->assertTrue(Validation::date('01/06', array('my')));
|
||||
$this->assertTrue(Validation::date('12-06', array('my')));
|
||||
$this->assertTrue(Validation::date('12.06', array('my')));
|
||||
$this->assertTrue(Validation::date('12 06', array('my')));
|
||||
$this->assertFalse(Validation::date('13 06', array('my')));
|
||||
$this->assertFalse(Validation::date('13 2006', array('my')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1438,12 +1440,14 @@ class ValidationTest extends CakeTestCase {
|
|||
$this->assertTrue(Validation::date('2006 12', array('ym')));
|
||||
$this->assertTrue(Validation::date('1900-01', array('ym')));
|
||||
$this->assertTrue(Validation::date('2153-01', array('ym')));
|
||||
$this->assertTrue(Validation::date('06/12', array('ym')));
|
||||
$this->assertTrue(Validation::date('06-12', array('ym')));
|
||||
$this->assertTrue(Validation::date('06-12', array('ym')));
|
||||
$this->assertTrue(Validation::date('06 12', array('ym')));
|
||||
$this->assertFalse(Validation::date('2006/12 ', array('ym')));
|
||||
$this->assertFalse(Validation::date('2006/12/', array('ym')));
|
||||
$this->assertFalse(Validation::date('06/12', array('ym')));
|
||||
$this->assertFalse(Validation::date('06-12', array('ym')));
|
||||
$this->assertFalse(Validation::date('06-12', array('ym')));
|
||||
$this->assertFalse(Validation::date('06 12', array('ym')));
|
||||
$this->assertFalse(Validation::date('06/12 ', array('ym')));
|
||||
$this->assertFalse(Validation::date('06/13 ', array('ym')));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2389,6 +2389,43 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test time with selected values around 12:xx:xx
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTimeSelectedWithIntervalTwelve() {
|
||||
$result = $this->Form->input('Model.start_time', array(
|
||||
'type' => 'time',
|
||||
'timeFormat' => 12,
|
||||
'interval' => 15,
|
||||
'selected' => '00:00:00'
|
||||
));
|
||||
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
||||
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
||||
$this->assertContains('<option value="am" selected="selected">am</option>', $result);
|
||||
|
||||
$result = $this->Form->input('Model.start_time', array(
|
||||
'type' => 'time',
|
||||
'timeFormat' => 12,
|
||||
'interval' => 15,
|
||||
'selected' => '12:00:00'
|
||||
));
|
||||
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
||||
$this->assertContains('<option value="00" selected="selected">00</option>', $result);
|
||||
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
||||
|
||||
$result = $this->Form->input('Model.start_time', array(
|
||||
'type' => 'time',
|
||||
'timeFormat' => 12,
|
||||
'interval' => 15,
|
||||
'selected' => '12:15:00'
|
||||
));
|
||||
$this->assertContains('<option value="12" selected="selected">12</option>', $result);
|
||||
$this->assertContains('<option value="15" selected="selected">15</option>', $result);
|
||||
$this->assertContains('<option value="pm" selected="selected">pm</option>', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test interval & timeFormat = 12
|
||||
*
|
||||
|
@ -2893,6 +2930,34 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that inferred types do not override developer input
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInputMagicTypeDoesNotOverride() {
|
||||
$this->View->viewVars['users'] = array('value' => 'good', 'other' => 'bad');
|
||||
$result = $this->Form->input('Model.user', array('type' => 'checkbox'));
|
||||
$expected = array(
|
||||
'div' => array('class' => 'input checkbox'),
|
||||
array('input' => array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'data[Model][user]',
|
||||
'id' => 'ModelUser_',
|
||||
'value' => 0,
|
||||
)),
|
||||
array('input' => array(
|
||||
'name' => 'data[Model][user]',
|
||||
'type' => 'checkbox',
|
||||
'id' => 'ModelUser',
|
||||
'value' => 1
|
||||
)),
|
||||
'label' => array('for' => 'ModelUser'), 'User', '/label',
|
||||
'/div'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that magic input() selects are created for type=number
|
||||
*
|
||||
|
|
|
@ -105,7 +105,7 @@ class String {
|
|||
* @param string $separator The token to split the data on.
|
||||
* @param string $leftBound The left boundary to ignore separators in.
|
||||
* @param string $rightBound The right boundary to ignore separators in.
|
||||
* @return array Array of tokens in $data.
|
||||
* @return mixed Array of tokens in $data or original input if empty.
|
||||
*/
|
||||
public static function tokenize($data, $separator = ',', $leftBound = '(', $rightBound = ')') {
|
||||
if (empty($data) || is_array($data)) {
|
||||
|
|
|
@ -263,7 +263,7 @@ class Validation {
|
|||
* Used when a custom regular expression is needed.
|
||||
*
|
||||
* @param string|array $check When used as a string, $regex must also be a valid regular expression.
|
||||
* As and array: array('check' => value, 'regex' => 'valid regular expression')
|
||||
* As and array: array('check' => value, 'regex' => 'valid regular expression')
|
||||
* @param string $regex If $check is passed as a string, $regex must also be set to valid regular expression
|
||||
* @return boolean Success
|
||||
*/
|
||||
|
@ -282,17 +282,21 @@ class Validation {
|
|||
* Date validation, determines if the string passed is a valid date.
|
||||
* keys that expect full month, day and year will validate leap years
|
||||
*
|
||||
* ### Formats:
|
||||
*
|
||||
* - `dmy` 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash
|
||||
* - `mdy` 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash
|
||||
* - `ymd` 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash
|
||||
* - `dMy` 27 December 2006 or 27 Dec 2006
|
||||
* - `Mdy` December 27, 2006 or Dec 27, 2006 comma is optional
|
||||
* - `My` December 2006 or Dec 2006
|
||||
* - `my` 12/2006 or 12/06 separators can be a space, period, dash, forward slash
|
||||
* - `ym` 2006/12 or 06/12 separators can be a space, period, dash, forward slash
|
||||
* - `y` 2006 just the year without any separators
|
||||
*
|
||||
* @param string $check a valid date string
|
||||
* @param string|array $format Use a string or an array of the keys below. Arrays should be passed as array('dmy', 'mdy', etc)
|
||||
* Keys: dmy 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash
|
||||
* mdy 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash
|
||||
* ymd 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash
|
||||
* dMy 27 December 2006 or 27 Dec 2006
|
||||
* Mdy December 27, 2006 or Dec 27, 2006 comma is optional
|
||||
* My December 2006 or Dec 2006
|
||||
* my 12/2006 separators can be a space, period, dash, forward slash
|
||||
* ym 2006/12 separators can be a space, period, dash, forward slash
|
||||
* y 2006 just the year without any separators
|
||||
* @param string|array $format Use a string or an array of the keys above.
|
||||
* Arrays should be passed as array('dmy', 'mdy', etc)
|
||||
* @param string $regex If a custom regular expression is used this is the only validation that will occur.
|
||||
* @return boolean Success
|
||||
*/
|
||||
|
@ -300,16 +304,35 @@ class Validation {
|
|||
if ($regex !== null) {
|
||||
return self::_check($check, $regex);
|
||||
}
|
||||
$month = '(0[123456789]|10|11|12)';
|
||||
$separator = '([- /.])';
|
||||
$fourDigitYear = '(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))';
|
||||
$twoDigitYear = '([0-9]{2})';
|
||||
$year = '(?:' . $fourDigitYear . '|' . $twoDigitYear . ')';
|
||||
|
||||
$regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' .
|
||||
$separator . '(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29' .
|
||||
$separator . '0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])' .
|
||||
$separator . '(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
|
||||
|
||||
$regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])' .
|
||||
$separator . '(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2' . $separator . '29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))' .
|
||||
$separator . '(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
|
||||
|
||||
$regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))' .
|
||||
$separator . '(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})' .
|
||||
$separator . '(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%';
|
||||
|
||||
$regex['dmy'] = '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
|
||||
$regex['mdy'] = '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%';
|
||||
$regex['ymd'] = '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]))))$%';
|
||||
$regex['dMy'] = '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ (((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]\\d)\\d{2})$/';
|
||||
|
||||
$regex['Mdy'] = '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep)(tember)?|(Nov|Dec)(ember)?)\\ (0?[1-9]|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/';
|
||||
$regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)[ /]((1[6-9]|[2-9]\\d)\\d{2})$%';
|
||||
$regex['my'] = '%^((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9][0-9][0-9])))$%';
|
||||
$regex['ym'] = '%^((([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))([- /.])(0[123456789]|10|11|12))$%';
|
||||
$regex['y'] = '%^(([1][9][0-9][0-9])|([2][0-9][0-9][0-9]))$%';
|
||||
|
||||
$regex['My'] = '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)' .
|
||||
$separator . '((1[6-9]|[2-9]\\d)\\d{2})$%';
|
||||
|
||||
$regex['my'] = '%^(' . $month . $separator . $year . ')$%';
|
||||
$regex['ym'] = '%^(' . $year . $separator . $month . ')$%';
|
||||
$regex['y'] = '%^(' . $fourDigitYear . ')$%';
|
||||
|
||||
$format = (is_array($format)) ? array_values($format) : array($format);
|
||||
foreach ($format as $key) {
|
||||
|
@ -322,20 +345,11 @@ class Validation {
|
|||
|
||||
/**
|
||||
* Validates a datetime value
|
||||
*
|
||||
* All values matching the "date" core validation rule, and the "time" one will be valid
|
||||
*
|
||||
* @param string $check Value to check
|
||||
* @param string|array $dateFormat Format of the date part
|
||||
* Use a string or an array of the keys below. Arrays should be passed as array('dmy', 'mdy', etc)
|
||||
* ## Keys:
|
||||
*
|
||||
* - dmy 27-12-2006 or 27-12-06 separators can be a space, period, dash, forward slash
|
||||
* - mdy 12-27-2006 or 12-27-06 separators can be a space, period, dash, forward slash
|
||||
* - ymd 2006-12-27 or 06-12-27 separators can be a space, period, dash, forward slash
|
||||
* - dMy 27 December 2006 or 27 Dec 2006
|
||||
* - Mdy December 27, 2006 or Dec 27, 2006 comma is optional
|
||||
* - My December 2006 or Dec 2006
|
||||
* - my 12/2006 separators can be a space, period, dash, forward slash
|
||||
* @param string|array $dateFormat Format of the date part. See Validation::date for more information.
|
||||
* @param string $regex Regex for the date part. If a custom regular expression is used this is the only validation that will occur.
|
||||
* @return boolean True if the value is valid, false otherwise
|
||||
* @see Validation::date
|
||||
|
|
|
@ -1082,7 +1082,7 @@ class FormHelper extends AppHelper {
|
|||
$options = $this->_magicOptions($options);
|
||||
}
|
||||
|
||||
if (in_array($options['type'], array('checkbox', 'radio', 'select'))) {
|
||||
if (in_array($options['type'], array('radio', 'select'))) {
|
||||
$options = $this->_optionsOptions($options);
|
||||
}
|
||||
|
||||
|
@ -2412,10 +2412,6 @@ class FormHelper extends AppHelper {
|
|||
$round = $attributes['round'];
|
||||
$attributes = array_diff_key($attributes, $defaults);
|
||||
|
||||
if ($timeFormat == 12 && $hour == 12) {
|
||||
$hour = 0;
|
||||
}
|
||||
|
||||
if (!empty($interval) && $interval > 1 && !empty($min)) {
|
||||
$current = new DateTime();
|
||||
if ($year !== null) {
|
||||
|
|
Loading…
Reference in a new issue