Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge remote-tracking branch 'origin/2.2' into 2.2

  • Loading branch information...
commit e7a7a177cc98311bc2974babaf326d92dac1254b 2 parents 63c0c2c + 7e38f9d
@lorenzo lorenzo authored
Showing with 719 additions and 577 deletions.
  1. +18 −11 app/Config/bootstrap.php
  2. +1 −1  app/View/Layouts/ajax.ctp
  3. +1 −1  app/View/Layouts/js/default.ctp
  4. +2 −2 app/View/Layouts/rss/default.ctp
  5. +1 −1  app/View/Layouts/xml/default.ctp
  6. +5 −5 lib/Cake/Cache/CacheEngine.php
  7. +3 −3 lib/Cake/Cache/Engine/RedisEngine.php
  8. +3 −1 lib/Cake/Console/Command/Task/ExtractTask.php
  9. +19 −12 lib/Cake/Console/Templates/skel/Config/bootstrap.php
  10. +2 −2 lib/Cake/Console/Templates/skel/View/Layouts/Emails/html/default.ctp
  11. +1 −1  lib/Cake/Console/Templates/skel/View/Layouts/Emails/text/default.ctp
  12. +1 −1  lib/Cake/Console/Templates/skel/View/Layouts/ajax.ctp
  13. +1 −1  lib/Cake/Console/Templates/skel/View/Layouts/js/default.ctp
  14. +2 −2 lib/Cake/Console/Templates/skel/View/Layouts/rss/default.ctp
  15. +1 −1  lib/Cake/Console/Templates/skel/View/Layouts/xml/default.ctp
  16. +1 −26 lib/Cake/Controller/Component/EmailComponent.php
  17. +9 −20 lib/Cake/Model/Datasource/Database/Mysql.php
  18. +9 −11 lib/Cake/Model/Datasource/Database/Postgres.php
  19. +9 −0 lib/Cake/Model/Datasource/Database/Sqlite.php
  20. +1 −21 lib/Cake/Model/Datasource/Database/Sqlserver.php
  21. +109 −33 lib/Cake/Model/Datasource/DboSource.php
  22. +1 −1  lib/Cake/Model/Model.php
  23. +25 −15 lib/Cake/Network/CakeRequest.php
  24. +5 −4 lib/Cake/Routing/Dispatcher.php
  25. +6 −10 lib/Cake/Routing/Filter/CacheDispatcher.php
  26. +2 −1  lib/Cake/Routing/Router.php
  27. +1 −1  lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
  28. +1 −2  lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
  29. +1 −2  lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php
  30. +18 −0 lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
  31. +35 −1 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
  32. +33 −0 lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
  33. +33 −0 lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
  34. +79 −0 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
  35. +1 −2  lib/Cake/Test/Case/Model/ModelIntegrationTest.php
  36. +71 −90 lib/Cake/Test/Case/Model/ModelWriteTest.php
  37. +98 −94 lib/Cake/Test/Case/Network/CakeRequestTest.php
  38. +6 −9 lib/Cake/Test/Case/Routing/DispatcherTest.php
  39. +6 −10 lib/Cake/Test/Case/Routing/Filter/AssetDispatcherTest.php
  40. +23 −0 lib/Cake/Test/Case/TestSuite/CakeTestSuiteTest.php
  41. +1 −0  lib/Cake/Test/Case/Utility/InflectorTest.php
  42. +2 −120 lib/Cake/Test/Case/View/Helper/FormHelperTest.php
  43. +0 −54 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  44. +10 −0 lib/Cake/TestSuite/CakeTestCase.php
  45. +6 −2 lib/Cake/TestSuite/CakeTestSuite.php
  46. +26 −0 lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
  47. +14 −1 lib/Cake/TestSuite/Fixture/CakeTestModel.php
  48. +12 −0 lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
  49. +1 −1  lib/Cake/Utility/Inflector.php
  50. +3 −1 lib/Cake/View/HelperCollection.php
View
29 app/Config/bootstrap.php
@@ -89,17 +89,24 @@
* The settings below can be used to set additional paths to models, views and controllers.
*
* App::build(array(
- * 'Plugin' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
- * 'Model' => array('/full/path/to/models/', '/next/full/path/to/models/'),
- * 'View' => array('/full/path/to/views/', '/next/full/path/to/views/'),
- * 'Controller' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'),
- * 'Model/Datasource' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
- * 'Model/Behavior' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
- * 'Controller/Component' => array('/full/path/to/components/', '/next/full/path/to/components/'),
- * 'View/Helper' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
- * 'Vendor' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
- * 'Console/Command' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
- * 'Locale' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
+ * 'Model' => array('/path/to/models', '/next/path/to/models'),
+ * 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
+ * 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
+ * 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
+ * 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
+ * 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
+ * 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
+ * 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
+ * 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
+ * 'View' => array('/path/to/views', '/next/path/to/views'),
+ * 'View/Helper' => array('/path/to/helpers', '/next/path/to/helpers'),
+ * 'Console' => array('/path/to/consoles', '/next/path/to/consoles'),
+ * 'Console/Command' => array('/path/to/commands', '/next/path/to/commands'),
+ * 'Console/Command/Task' => array('/path/to/tasks', '/next/path/to/tasks'),
+ * 'Lib' => array('/path/to/libs', '/next/path/to/libs'),
+ * 'Locale' => array('/path/to/locales', '/next/path/to/locales'),
+ * 'Vendor' => array('/path/to/vendors', '/next/path/to/vendors'),
+ * 'Plugin' => array('/path/to/plugins', '/next/path/to/plugins'),
* ));
*
*/
View
2  app/View/Layouts/ajax.ctp
@@ -16,4 +16,4 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
-<?php echo $content_for_layout; ?>
+<?php echo $this->fetch('content'); ?>
View
2  app/View/Layouts/js/default.ctp
@@ -1,2 +1,2 @@
<?php echo $scripts_for_layout; ?>
-<script type="text/javascript"><?php echo $content_for_layout; ?></script>
+<script type="text/javascript"><?php echo $this->fetch('content'); ?></script>
View
4 app/View/Layouts/rss/default.ctp
@@ -8,7 +8,7 @@ if (!isset($channel['title'])) {
echo $this->Rss->document(
$this->Rss->channel(
- array(), $channel, $content_for_layout
+ array(), $channel, $this->fetch('content')
)
);
-?>
+?>
View
2  app/View/Layouts/xml/default.ctp
@@ -1 +1 @@
-<?php echo $content_for_layout; ?>
+<?php echo $this->fetch('content'); ?>
View
10 lib/Cake/Cache/CacheEngine.php
@@ -129,7 +129,7 @@ public function gc($expires = null) {
*
* @param string $groups name of the group to be cleared
* @return boolean
- **/
+ */
public function clearGroup($group) {
return false;
}
@@ -140,10 +140,10 @@ public function clearGroup($group) {
* the token representing each group in the cache key
*
* @return array
- **/
- public function groups() {
- return $this->settings['groups'];
- }
+ */
+ public function groups() {
+ return $this->settings['groups'];
+ }
/**
* Cache Engine settings
View
6 lib/Cake/Cache/Engine/RedisEngine.php
@@ -115,7 +115,7 @@ public function write($key, $value, $duration) {
public function read($key) {
$value = $this->_Redis->get($key);
if (ctype_digit($value)) {
- $value = (int) $value;
+ $value = (int)$value;
}
if ($value !== false && is_string($value)) {
$value = unserialize($value);
@@ -132,7 +132,7 @@ public function read($key) {
* @throws CacheException when you try to increment with compress = true
*/
public function increment($key, $offset = 1) {
- return (int) $this->_Redis->incrBy($key, $offset);
+ return (int)$this->_Redis->incrBy($key, $offset);
}
/**
@@ -144,7 +144,7 @@ public function increment($key, $offset = 1) {
* @throws CacheException when you try to decrement with compress = true
*/
public function decrement($key, $offset = 1) {
- return (int) $this->_Redis->decrBy($key, $offset);
+ return (int)$this->_Redis->decrBy($key, $offset);
}
/**
View
4 lib/Cake/Console/Command/Task/ExtractTask.php
@@ -464,6 +464,8 @@ protected function _processValidationRules($field, $rules, $file, $domain) {
* @return void
*/
protected function _buildFiles() {
+ $paths = $this->_paths;
+ $paths[] = realpath(APP) . DS;
foreach ($this->_translations as $domain => $translations) {
foreach ($translations as $msgid => $details) {
$plural = $details['msgid_plural'];
@@ -474,7 +476,7 @@ protected function _buildFiles() {
$occurrences[] = $file . ':' . implode(';', $lines);
}
$occurrences = implode("\n#: ", $occurrences);
- $header = '#: ' . str_replace($this->_paths, '', $occurrences) . "\n";
+ $header = '#: ' . str_replace($paths, '', $occurrences) . "\n";
if ($plural === false) {
$sentence = "msgid \"{$msgid}\"\n";
View
31 lib/Cake/Console/Templates/skel/Config/bootstrap.php
@@ -30,17 +30,24 @@
* The settings below can be used to set additional paths to models, views and controllers.
*
* App::build(array(
- * 'Plugin' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
- * 'Model' => array('/full/path/to/models/', '/next/full/path/to/models/'),
- * 'View' => array('/full/path/to/views/', '/next/full/path/to/views/'),
- * 'Controller' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'),
- * 'Model/Datasource' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
- * 'Model/Behavior' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
- * 'Controller/Component' => array('/full/path/to/components/', '/next/full/path/to/components/'),
- * 'View/Helper' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
- * 'Vendor' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
- * 'Console/Command' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
- * 'Locale' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
+ * 'Model' => array('/path/to/models', '/next/path/to/models'),
+ * 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
+ * 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
+ * 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
+ * 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
+ * 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
+ * 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
+ * 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
+ * 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
+ * 'View' => array('/path/to/views', '/next/path/to/views'),
+ * 'View/Helper' => array('/path/to/helpers', '/next/path/to/helpers'),
+ * 'Console' => array('/path/to/consoles', '/next/path/to/consoles'),
+ * 'Console/Command' => array('/path/to/commands', '/next/path/to/commands'),
+ * 'Console/Command/Task' => array('/path/to/tasks', '/next/path/to/tasks'),
+ * 'Lib' => array('/path/to/libs', '/next/path/to/libs'),
+ * 'Locale' => array('/path/to/locales', '/next/path/to/locales'),
+ * 'Vendor' => array('/path/to/vendors', '/next/path/to/vendors'),
+ * 'Plugin' => array('/path/to/plugins', '/next/path/to/plugins'),
* ));
*
*/
@@ -83,4 +90,4 @@
Configure::write('Dispatcher.filters', array(
'AssetDispatcher',
'CacheDispatcher'
-));
+));
View
4 lib/Cake/Console/Templates/skel/View/Layouts/Emails/html/default.ctp
@@ -24,8 +24,8 @@
</head>
<body>
- <?php echo $content_for_layout;?>
+ <?php echo $this->fetch('content');?>
<p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body>
-</html>
+</html>
View
2  lib/Cake/Console/Templates/skel/View/Layouts/Emails/text/default.ctp
@@ -17,6 +17,6 @@
*/
?>
-<?php echo $content_for_layout;?>
+<?php echo $this->fetch('content');?>
This email was sent using the CakePHP Framework, http://cakephp.org.
View
2  lib/Cake/Console/Templates/skel/View/Layouts/ajax.ctp
@@ -16,4 +16,4 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
?>
-<?php echo $content_for_layout; ?>
+<?php echo $this->fetch('content'); ?>
View
2  lib/Cake/Console/Templates/skel/View/Layouts/js/default.ctp
@@ -1,2 +1,2 @@
<?php echo $scripts_for_layout; ?>
-<script type="text/javascript"><?php echo $content_for_layout; ?></script>
+<script type="text/javascript"><?php echo $this->fetch('content'); ?></script>
View
4 lib/Cake/Console/Templates/skel/View/Layouts/rss/default.ctp
@@ -8,7 +8,7 @@ if (!isset($channel['title'])) {
echo $this->Rss->document(
$this->Rss->channel(
- array(), $channel, $content_for_layout
+ array(), $channel, $this->fetch('content')
)
);
-?>
+?>
View
2  lib/Cake/Console/Templates/skel/View/Layouts/xml/default.ctp
@@ -1 +1 @@
-<?php echo $content_for_layout; ?>
+<?php echo $this->fetch('content'); ?>
View
27 lib/Cake/Controller/Component/EmailComponent.php
@@ -421,31 +421,6 @@ protected function _findFiles($attachment) {
}
/**
- * Encode the specified string using the current charset
- *
- * @param string $subject String to encode
- * @return string Encoded string
- */
- protected function _encode($subject) {
- $subject = $this->_strip($subject);
-
- $nl = "\r\n";
- if ($this->delivery == 'mail') {
- $nl = '';
- }
- $internalEncoding = function_exists('mb_internal_encoding');
- if ($internalEncoding) {
- $restore = mb_internal_encoding();
- mb_internal_encoding($this->charset);
- }
- $return = mb_encode_mimeheader($subject, $this->charset, 'B', $nl);
- if ($internalEncoding) {
- mb_internal_encoding($restore);
- }
- return $return;
- }
-
-/**
* Format addresses to be an array with email as key and alias as value
*
* @param array $addresses
@@ -455,7 +430,7 @@ protected function _formatAddresses($addresses) {
$formatted = array();
foreach ($addresses as $address) {
if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) {
- $formatted[$this->_strip($matches[3])] = $this->_encode($matches[2]);
+ $formatted[$this->_strip($matches[3])] = $matches[2];
} else {
$address = $this->_strip($address);
$formatted[$address] = $address;
View
29 lib/Cake/Model/Datasource/Database/Mysql.php
@@ -78,17 +78,6 @@ class Mysql extends DboSource {
protected $_useAlias = true;
/**
- * Index of basic SQL commands
- *
- * @var array
- */
- protected $_commands = array(
- 'begin' => 'START TRANSACTION',
- 'commit' => 'COMMIT',
- 'rollback' => 'ROLLBACK'
- );
-
-/**
* List of engine specific additional field parameters used on table creating
*
* @var array
@@ -263,15 +252,6 @@ public function getEncoding() {
}
/**
- * Gets the version string of the database server
- *
- * @return string The database encoding
- */
- public function getVersion() {
- return $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
- }
-
-/**
* Query charset by collation
*
* @param string $name Collation name
@@ -696,4 +676,13 @@ public function getSchemaName() {
return $this->config['database'];
}
+/**
+ * Check if the server support nested transactions
+ *
+ * @return boolean
+ */
+ public function supportNestedTransaction() {
+ return $this->nestedTransaction && version_compare($this->getVersion(), '4.1', '>=');
+ }
+
}
View
20 lib/Cake/Model/Datasource/Database/Postgres.php
@@ -34,17 +34,6 @@ class Postgres extends DboSource {
public $description = "PostgreSQL DBO Driver";
/**
- * Index of basic SQL commands
- *
- * @var array
- */
- protected $_commands = array(
- 'begin' => 'BEGIN',
- 'commit' => 'COMMIT',
- 'rollback' => 'ROLLBACK'
- );
-
-/**
* Base driver configuration settings. Merged with user settings.
*
* @var array
@@ -906,4 +895,13 @@ public function getSchemaName() {
return $this->config['schema'];
}
+/**
+ * Check if the server support nested transactions
+ *
+ * @return boolean
+ */
+ public function supportNestedTransaction() {
+ return $this->nestedTransaction && version_compare($this->getVersion(), '8.0', '>=');
+ }
+
}
View
9 lib/Cake/Model/Datasource/Database/Sqlite.php
@@ -559,4 +559,13 @@ public function getSchemaName() {
return "main"; // Sqlite Datasource does not support multidb
}
+/**
+ * Check if the server support nested transactions
+ *
+ * @return boolean
+ */
+ public function supportNestedTransaction() {
+ return $this->nestedTransaction && version_compare($this->getVersion(), '3.6.8', '>=');
+ }
+
}
View
22 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -99,31 +99,12 @@ class Sqlserver extends DboSource {
);
/**
- * Index of basic SQL commands
- *
- * @var array
- */
- protected $_commands = array(
- 'begin' => 'BEGIN TRANSACTION',
- 'commit' => 'COMMIT',
- 'rollback' => 'ROLLBACK'
- );
-
-/**
* Magic column name used to provide pagination support for SQLServer 2008
* which lacks proper limit/offset support.
*/
const ROW_COUNTER = '_cake_page_rownum_';
/**
- * The version of SQLServer being used. If greater than 11
- * Normal limit offset statements will be used
- *
- * @var string
- */
- protected $_version;
-
-/**
* Connects to the database using options in the given configuration array.
*
* @return boolean True if the database could be connected, else false
@@ -151,7 +132,6 @@ public function connect() {
throw new MissingConnectionException(array('class' => $e->getMessage()));
}
- $this->_version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
return $this->connected;
}
@@ -515,7 +495,7 @@ public function renderStatement($type, $data) {
}
// For older versions use the subquery version of pagination.
- if (version_compare($this->_version, '11', '<') && preg_match('/FETCH\sFIRST\s+([0-9]+)/i', $limit, $offset)) {
+ if (version_compare($this->getVersion(), '11', '<') && preg_match('/FETCH\sFIRST\s+([0-9]+)/i', $limit, $offset)) {
preg_match('/OFFSET\s*(\d+)\s*.*?(\d+)\s*ROWS/', $limit, $limitOffset);
$limit = 'TOP ' . intval($limitOffset[2]);
View
142 lib/Cake/Model/Datasource/DboSource.php
@@ -70,6 +70,15 @@ class DboSource extends DataSource {
public $cacheMethods = true;
/**
+ * Flag to support nested transactions. If it is set to false, you will be able to use
+ * the transaction methods (begin/commit/rollback), but just the global transaction will
+ * be executed.
+ *
+ * @var boolean
+ */
+ public $nestedTransaction = true;
+
+/**
* Print full query debug info?
*
* @var boolean
@@ -184,17 +193,6 @@ class DboSource extends DataSource {
protected $_transactionNesting = 0;
/**
- * Index of basic SQL commands
- *
- * @var array
- */
- protected $_commands = array(
- 'begin' => 'BEGIN',
- 'commit' => 'COMMIT',
- 'rollback' => 'ROLLBACK'
- );
-
-/**
* Default fields that are used by the DBO
*
* @var array
@@ -294,13 +292,22 @@ public function disconnect() {
/**
* Get the underlying connection object.
*
- * @return PDOConnection
+ * @return PDO
*/
public function getConnection() {
return $this->_connection;
}
/**
+ * Gets the version string of the database server
+ *
+ * @return string The database version
+ */
+ public function getVersion() {
+ return $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
+ }
+
+/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement
@@ -2020,6 +2027,15 @@ public function truncate($table) {
}
/**
+ * Check if the server support nested transactions
+ *
+ * @return boolean
+ */
+ public function supportNestedTransaction() {
+ return false;
+ }
+
+/**
* Begin a transaction
*
* @return boolean True on success, false on fail
@@ -2027,15 +2043,33 @@ public function truncate($table) {
* or a transaction has not started).
*/
public function begin() {
- if ($this->_transactionStarted || $this->_connection->beginTransaction()) {
- if ($this->fullDebug && empty($this->_transactionNesting)) {
- $this->logQuery('BEGIN');
+ if ($this->_transactionStarted) {
+ if ($this->supportNestedTransaction()) {
+ return $this->_beginNested();
}
- $this->_transactionStarted = true;
$this->_transactionNesting++;
- return true;
+ return $this->_transactionStarted;
}
- return false;
+
+ $this->_transactionNesting = 0;
+ if ($this->fullDebug) {
+ $this->logQuery('BEGIN');
+ }
+ return $this->_transactionStarted = $this->_connection->beginTransaction();
+ }
+
+/**
+ * Begin a nested transaction
+ *
+ * @return boolean
+ */
+ protected function _beginNested() {
+ $query = 'SAVEPOINT LEVEL' . ++$this->_transactionNesting;
+ if ($this->fullDebug) {
+ $this->logQuery($query);
+ }
+ $this->_connection->exec($query);
+ return true;
}
/**
@@ -2046,19 +2080,38 @@ public function begin() {
* or a transaction has not started).
*/
public function commit() {
- if ($this->_transactionStarted) {
- $this->_transactionNesting--;
- if ($this->_transactionNesting <= 0) {
- $this->_transactionStarted = false;
- $this->_transactionNesting = 0;
- if ($this->fullDebug) {
- $this->logQuery('COMMIT');
- }
- return $this->_connection->commit();
+ if (!$this->_transactionStarted) {
+ return false;
+ }
+
+ if ($this->_transactionNesting === 0) {
+ if ($this->fullDebug) {
+ $this->logQuery('COMMIT');
}
- return true;
+ $this->_transactionStarted = false;
+ return $this->_connection->commit();
}
- return false;
+
+ if ($this->supportNestedTransaction()) {
+ return $this->_commitNested();
+ }
+
+ $this->_transactionNesting--;
+ return true;
+ }
+
+/**
+ * Commit a nested transaction
+ *
+ * @return boolean
+ */
+ protected function _commitNested() {
+ $query = 'RELEASE SAVEPOINT LEVEL' . $this->_transactionNesting--;
+ if ($this->fullDebug) {
+ $this->logQuery($query);
+ }
+ $this->_connection->exec($query);
+ return true;
}
/**
@@ -2069,15 +2122,38 @@ public function commit() {
* or a transaction has not started).
*/
public function rollback() {
- if ($this->_transactionStarted && $this->_connection->rollBack()) {
+ if (!$this->_transactionStarted) {
+ return false;
+ }
+
+ if ($this->_transactionNesting === 0) {
if ($this->fullDebug) {
$this->logQuery('ROLLBACK');
}
$this->_transactionStarted = false;
- $this->_transactionNesting = 0;
- return true;
+ return $this->_connection->rollBack();
}
- return false;
+
+ if ($this->supportNestedTransaction()) {
+ return $this->_rollbackNested();
+ }
+
+ $this->_transactionNesting--;
+ return true;
+ }
+
+/**
+ * Rollback a nested transaction
+ *
+ * @return boolean
+ */
+ protected function _rollbackNested() {
+ $query = 'ROLLBACK TO SAVEPOINT LEVEL' . $this->_transactionNesting--;
+ if ($this->fullDebug) {
+ $this->logQuery($query);
+ }
+ $this->_connection->exec($query);
+ return true;
}
/**
View
2  lib/Cake/Model/Model.php
@@ -1629,7 +1629,7 @@ public function save($data = null, $validate = true, $fieldList = array()) {
if (!array_key_exists('format', $colType)) {
$time = strtotime('now');
} else {
- $time = $colType['formatter']($colType['format']);
+ $time = call_user_func($colType['formatter'], $colType['format']);
}
if (!empty($this->whitelist)) {
$this->whitelist[] = $updateCol;
View
40 lib/Cake/Network/CakeRequest.php
@@ -320,21 +320,31 @@ protected function _processFiles() {
if (isset($_FILES['data'])) {
foreach ($_FILES['data'] as $key => $data) {
- foreach ($data as $model => $fields) {
- if (is_array($fields)) {
- foreach ($fields as $field => $value) {
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $this->data[$model][$field][$k][$key] = $v;
- }
- } else {
- $this->data[$model][$field][$key] = $value;
- }
- }
- } else {
- $this->data[$model][$key] = $fields;
- }
- }
+ $this->_processFileData('', $data, $key);
+ }
+ }
+ }
+
+/**
+ * Recursively walks the FILES array restructuring the data
+ * into something sane and useable.
+ *
+ * @param string $path The dot separated path to insert $data into.
+ * @param array $data The data to traverse/insert.
+ * @param string $field The terminal field name, which is the top level key in $_FILES.
+ * @return void
+ */
+ protected function _processFileData($path, $data, $field) {
+ foreach ($data as $key => $fields) {
+ $newPath = $key;
+ if (!empty($path)) {
+ $newPath = $path . '.' . $key;
+ }
+ if (is_array($fields)) {
+ $this->_processFileData($newPath, $fields, $field);
+ } else {
+ $newPath .= '.' . $field;
+ $this->data = Set::insert($this->data, $newPath, $fields);
}
}
}
View
9 lib/Cake/Routing/Dispatcher.php
@@ -44,7 +44,7 @@ class Dispatcher implements CakeEventListener {
* Event manager, used to handle dispatcher filters
*
* @var CakeEventMaanger
- **/
+ */
protected $_eventManager;
/**
@@ -63,7 +63,7 @@ public function __construct($base = false) {
* creted. Attaches the default listeners and filters
*
* @return CakeEventmanger
- **/
+ */
public function getEventManager() {
if (!$this->_eventManager) {
$this->_eventManager = new CakeEventManager();
@@ -77,7 +77,7 @@ public function getEventManager() {
* Returns the list of events this object listents to.
*
* @return array
- **/
+ */
public function implementedEvents() {
return array('Dispatcher.beforeDispatch' => 'parseParams');
}
@@ -88,7 +88,8 @@ public function implementedEvents() {
*
* @param CakeEventManager $manager
* @return void
- **/
+ * @throws MissingDispatcherFilterException
+ */
protected function _attachFilters($manager) {
$filters = Configure::read('Dispatcher.filters');
if (empty($filters)) {
View
16 lib/Cake/Routing/Filter/CacheDispatcher.php
@@ -1,19 +1,15 @@
<?php
/**
- *
- * PHP 5
- *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://cakephp.org CakePHP(tm) Project
- * @package Cake.Routing
- * @since CakePHP(tm) v 2.2
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @since CakePHP(tm) v 2.2
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('DispatcherFilter', 'Routing');
@@ -31,7 +27,7 @@ class CacheDispatcher extends DispatcherFilter {
* This filter should run before the request gets parsed by router
*
* @var int
- **/
+ */
public $priority = 9;
/**
@@ -68,4 +64,4 @@ public function beforeDispatch($event) {
}
}
-}
+}
View
3  lib/Cake/Routing/Router.php
@@ -1014,7 +1014,8 @@ public static function reverse($params, $full = false) {
public static function normalize($url = '/') {
if (is_array($url)) {
$url = Router::url($url);
- } elseif (preg_match('/^[a-z\-]+:\/\//', $url)) {
+ }
+ if (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url;
}
$request = Router::getRequest();
View
2  lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
@@ -410,7 +410,7 @@ public function testGroupsReadWrite() {
$this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups'));
}
- /**
+/**
* Tests that deleteing from a groups-enabled config is possible
*
* @return void
View
3  lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
@@ -220,7 +220,6 @@ public function testIncrement() {
$this->assertEquals(3, $result);
}
-
/**
* test clearing redis.
*
@@ -333,4 +332,4 @@ public function testGroupClear() {
$this->assertFalse(Cache::read('test_groups', 'redis_groups'));
}
-}
+}
View
3  lib/Cake/Test/Case/Controller/Component/Auth/FormAuthenticateTest.php
@@ -163,7 +163,6 @@ public function testPluginModel() {
), App::RESET);
CakePlugin::load('TestPlugin');
- $ts = date('Y-m-d H:i:s');
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
$user['id'] = 1;
$user['username'] = 'gwoo';
@@ -185,7 +184,7 @@ public function testPluginModel() {
'username' => 'gwoo',
'created' => '2007-03-17 01:16:23'
);
- $this->assertTrue($result['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result['updated']);
unset($result['updated']);
$this->assertEquals($expected, $result);
CakePlugin::unload();
View
18 lib/Cake/Test/Case/Controller/Component/EmailComponentTest.php
@@ -868,4 +868,22 @@ public function testMessageId() {
$this->assertNotRegExp('/Message-ID:/', $result);
}
+/**
+ * Make sure from/to are not double encoded when UTF-8 is present
+ */
+ public function testEncodingFrom() {
+ $this->Controller->EmailTest->to = 'Teßt <test@example.com>';
+ $this->Controller->EmailTest->from = 'Teßt <test@example.com>';
+ $this->Controller->EmailTest->subject = 'Cake Debug Test';
+ $this->Controller->EmailTest->replyTo = 'noreply@example.com';
+ $this->Controller->EmailTest->template = null;
+
+ $this->Controller->EmailTest->delivery = 'DebugComp';
+ $this->assertTrue($this->Controller->EmailTest->send('This is the body of the message'));
+ $result = DebugCompTransport::$lastEmail;
+
+ $this->assertContains('From: =?UTF-8?B?VGXDn3Qg?= <test@example.com>', $result);
+ $this->assertContains('To: =?UTF-8?B?VGXDn3Qg?= <test@example.com>', $result);
+ }
+
}
View
36 lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
@@ -45,7 +45,7 @@ class MysqlTest extends CakeTestCase {
public $fixtures = array(
'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment',
'core.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test',
- 'core.binary_test'
+ 'core.binary_test', 'app.address'
);
/**
@@ -3579,4 +3579,38 @@ public function testTruncateStatements() {
->with("TRUNCATE TABLE `$schema`.`tbl_articles`");
$this->Dbo->truncate('articles');
}
+
+/**
+ * Test nested transaction
+ *
+ * @return void
+ */
+ public function testNestedTransaction() {
+ $this->skipIf($this->Dbo->supportNestedTransaction() === false, 'The MySQL server do not support nested transaction');
+
+ $this->loadFixtures('Address');
+ $model = ClassRegistry::init('Address');
+ $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
+ $model->cacheQueries = false;
+ $this->Dbo->cacheMethods = false;
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->commit());
+ $this->assertEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+ }
+
}
View
33 lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
@@ -909,4 +909,37 @@ public function testTruncateStatements() {
$this->Dbo->truncate('articles');
}
+/**
+ * Test nested transaction
+ *
+ * @return void
+ */
+ public function testNestedTransaction() {
+ $this->skipIf($this->Dbo->supportNestedTransaction() === false, 'The Postgres server do not support nested transaction');
+
+ $this->loadFixtures('Article');
+ $model = new Article();
+ $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
+ $model->cacheQueries = false;
+ $this->Dbo->cacheMethods = false;
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->commit());
+ $this->assertEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+ }
+
}
View
33 lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php
@@ -383,4 +383,37 @@ public function testUuidPrimaryKeyInsertion() {
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid');
}
+/**
+ * Test nested transaction
+ *
+ * @return void
+ */
+ public function testNestedTransaction() {
+ $this->skipIf($this->Dbo->supportNestedTransaction() === false, 'The Sqlite version do not support nested transaction');
+
+ $this->loadFixtures('User');
+ $model = new User();
+ $model->hasOne = $model->hasMany = $model->belongsTo = $model->hasAndBelongsToMany = array();
+ $model->cacheQueries = false;
+ $this->Dbo->cacheMethods = false;
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->begin());
+ $this->assertTrue($model->delete(1));
+ $this->assertEmpty($model->read(null, 1));
+ $this->assertTrue($this->Dbo->commit());
+ $this->assertEmpty($model->read(null, 1));
+
+ $this->assertTrue($this->Dbo->rollback());
+ $this->assertNotEmpty($model->read(null, 1));
+ }
+
}
View
79 lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
@@ -35,6 +35,8 @@ class MockDataSource extends DataSource {
class DboTestSource extends DboSource {
+ public static $nested = true;
+
public function connect($config = array()) {
$this->connected = true;
}
@@ -51,6 +53,10 @@ public function setConnection($conn) {
$this->_connection = $conn;
}
+ public function supportNestedTransaction() {
+ return $this->nestedTransaction && self::$nested;
+ }
+
}
/**
@@ -835,6 +841,79 @@ public function testTransactionLogging() {
}
/**
+ * Test nested transaction calls
+ *
+ * @return void
+ */
+ public function testTransactionNested() {
+ $conn = $this->getMock('MockPDO');
+ $db = new DboTestSource();
+ $db->setConnection($conn);
+ DboTestSource::$nested = true;
+
+ $conn->expects($this->at(0))->method('beginTransaction')->will($this->returnValue(true));
+ $conn->expects($this->at(1))->method('exec')->with($this->equalTo('SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+ $conn->expects($this->at(2))->method('exec')->with($this->equalTo('RELEASE SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+ $conn->expects($this->at(3))->method('exec')->with($this->equalTo('SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+ $conn->expects($this->at(4))->method('exec')->with($this->equalTo('ROLLBACK TO SAVEPOINT LEVEL1'))->will($this->returnValue(true));
+ $conn->expects($this->at(5))->method('commit')->will($this->returnValue(true));
+
+ $this->_runTransactions($db);
+ }
+
+/**
+ * Test nested transaction calls without support
+ *
+ * @return void
+ */
+ public function testTransactionNestedWithoutSupport() {
+ $conn = $this->getMock('MockPDO');
+ $db = new DboTestSource();
+ $db->setConnection($conn);
+ $db->nestedTransaction = false;
+ DboTestSource::$nested = true;
+
+ $conn->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));
+ $conn->expects($this->never())->method('exec');
+ $conn->expects($this->once())->method('commit')->will($this->returnValue(true));
+
+ $this->_runTransactions($db);
+ }
+
+/**
+ * Test nested transaction disabled
+ *
+ * @return void
+ */
+ public function testTransactionNestedDisabled() {
+ $conn = $this->getMock('MockPDO');
+ $db = new DboTestSource();
+ $db->setConnection($conn);
+ DboTestSource::$nested = false;
+
+ $conn->expects($this->once())->method('beginTransaction')->will($this->returnValue(true));
+ $conn->expects($this->never())->method('exec');
+ $conn->expects($this->once())->method('commit')->will($this->returnValue(true));
+
+ $this->_runTransactions($db);
+ }
+
+/**
+ * Nested transaction calls
+ *
+ * @param DboTestSource $db
+ * @return void
+ */
+ protected function _runTransactions($db) {
+ $db->begin();
+ $db->begin();
+ $db->commit();
+ $db->begin();
+ $db->rollback();
+ $db->commit();
+ }
+
+/**
* Test build statement with some fields missing
*
* @return void
View
3  lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -1866,7 +1866,6 @@ public function testWithAssociation() {
'doomed' => true
))));
- $ts = date('Y-m-d H:i:s');
$TestModel->save();
$TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC';
@@ -1920,7 +1919,7 @@ public function testWithAssociation() {
)
)
);
- $this->assertTrue($result['Something']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result['Something']['updated']);
unset($result['Something']['updated']);
$this->assertEquals($expected, $result);
}
View
161 lib/Cake/Test/Case/Model/ModelWriteTest.php
@@ -1613,7 +1613,6 @@ public function testSaveHabtmNoPrimaryData() {
);
$this->assertEquals($expected, $result);
- $ts = date('Y-m-d H:i:s');
$TestModel->id = 2;
$data = array('Tag' => array('Tag' => array(2)));
$TestModel->save($data);
@@ -1627,7 +1626,7 @@ public function testSaveHabtmNoPrimaryData() {
'body' => 'Second Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:41:23',
- 'updated' => $ts
+ 'updated' => self::date()
),
'Tag' => array(
array(
@@ -2561,29 +2560,28 @@ public function testSaveMultipleHabtm() {
$this->assertEquals($expected, $result);
- $ts = date('Y-m-d H:i:s');
$TestModel->id = 1;
$data = array(
'JoinA' => array(
'id' => '1',
'name' => 'New name for Join A 1',
- 'updated' => $ts
+ 'updated' => self::date()
),
'JoinB' => array(
array(
'id' => 1,
'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
)),
'JoinC' => array(
array(
'id' => 1,
'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
)));
$TestModel->set($data);
@@ -2596,7 +2594,7 @@ public function testSaveMultipleHabtm() {
'name' => 'New name for Join A 1',
'body' => 'Join A 1 Body',
'created' => '2008-01-03 10:54:23',
- 'updated' => $ts
+ 'updated' => self::date()
),
'JoinB' => array(
0 => array(
@@ -2609,8 +2607,8 @@ public function testSaveMultipleHabtm() {
'join_a_id' => 1,
'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
))),
'JoinC' => array(
0 => array(
@@ -2623,8 +2621,8 @@ public function testSaveMultipleHabtm() {
'join_a_id' => 1,
'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
))));
$this->assertEquals($expected, $result);
@@ -2642,7 +2640,6 @@ public function testSaveAll() {
$result = $TestModel->find('all');
$this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3]));
- $ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array(
'Post' => array(
@@ -2669,10 +2666,10 @@ public function testSaveAll() {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working'
));
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Author']['created'] >= $ts);
- $this->assertTrue($result[3]['Author']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Author']['created']);
+ $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[3]['Author']['created'], $result[3]['Author']['updated']);
$this->assertEquals($expected, $result[3]);
@@ -2684,7 +2681,6 @@ public function testSaveAll() {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel);
- $ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array(
array(
'title' => 'Multi-record post 1',
@@ -2718,16 +2714,15 @@ public function testSaveAll() {
'body' => 'Second multi-record post',
'published' => 'N'
)));
- $this->assertTrue($result[0]['Post']['created'] >= $ts);
- $this->assertTrue($result[0]['Post']['updated'] >= $ts);
- $this->assertTrue($result[1]['Post']['created'] >= $ts);
- $this->assertTrue($result[1]['Post']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[0]['Post']['created']);
+ $this->assertEquals(self::date(), $result[0]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[1]['Post']['created']);
+ $this->assertEquals(self::date(), $result[1]['Post']['updated']);
unset($result[0]['Post']['created'], $result[0]['Post']['updated']);
unset($result[1]['Post']['created'], $result[1]['Post']['updated']);
$this->assertEquals($expected, $result);
$TestModel = new Comment();
- $ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAll(array(
'Comment' => array(
'article_id' => 2,
@@ -2748,8 +2743,8 @@ public function testSaveAll() {
'comment' => 'New comment with attachment',
'published' => 'Y'
);
- $this->assertTrue($result[6]['Comment']['created'] >= $ts);
- $this->assertTrue($result[6]['Comment']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[6]['Comment']['created']);
+ $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']);
$this->assertEquals($expected, $result[6]['Comment']);
@@ -2758,8 +2753,8 @@ public function testSaveAll() {
'comment_id' => '7',
'attachment' => 'some_file.tgz'
);
- $this->assertTrue($result[6]['Attachment']['created'] >= $ts);
- $this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
+ $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']);
$this->assertEquals($expected, $result[6]['Attachment']);
}
@@ -4056,7 +4051,6 @@ public function testSaveAllTransaction() {
array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '')
);
- $ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1));
@@ -4098,8 +4092,8 @@ public function testSaveAllTransaction() {
'title' => 'New Fourth Post',
'body' => null,
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
));
$expected[] = array(
@@ -4109,8 +4103,8 @@ public function testSaveAllTransaction() {
'title' => 'New Fifth Post',
'body' => null,
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
));
$this->assertEquals($expected, $result);
@@ -4125,7 +4119,6 @@ public function testSaveAllTransaction() {
array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post')
);
- $ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1));
@@ -4167,8 +4160,8 @@ public function testSaveAllTransaction() {
'title' => 'New Fourth Post',
'body' => 'Third Post Body',
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
));
$expected[] = array(
@@ -4178,8 +4171,8 @@ public function testSaveAllTransaction() {
'title' => 'Third Post',
'body' => 'Third Post Body',
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
));
}
$this->assertEquals($expected, $result);
@@ -4264,7 +4257,6 @@ public function testSaveAllValidation() {
'author_id' => 2
));
- $ts = date('Y-m-d H:i:s');
$this->assertTrue($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
@@ -4305,10 +4297,10 @@ public function testSaveAllValidation() {
'body' => 'Fourth post body',
'published' => 'N'
)));
- $this->assertTrue($result[0]['Post']['updated'] >= $ts);
- $this->assertTrue($result[1]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[0]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[1]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result);
@@ -4399,10 +4391,10 @@ public function testSaveAllValidation() {
)
);
- $this->assertTrue($result[0]['Post']['updated'] >= $ts);
- $this->assertTrue($result[1]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
+ $this->assertEquals(self::date(), $result[0]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[1]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
unset(
$result[0]['Post']['updated'], $result[1]['Post']['updated'],
$result[3]['Post']['updated'], $result[3]['Post']['created']
@@ -4731,7 +4723,6 @@ public function testSaveAssociated() {
$result = $TestModel->find('all');
$this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3]));
- $ts = date('Y-m-d H:i:s');
$TestModel->saveAssociated(array(
'Post' => array(
@@ -4758,10 +4749,10 @@ public function testSaveAssociated() {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working'
));
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Author']['created'] >= $ts);
- $this->assertTrue($result[3]['Author']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Author']['created']);
+ $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset(
$result[3]['Post']['updated'], $result[3]['Post']['created'],
$result[3]['Author']['updated'], $result[3]['Author']['created']
@@ -4769,10 +4760,7 @@ public function testSaveAssociated() {
$this->assertEquals($expected, $result[3]);
$this->assertEquals(4, count($result));
- $ts = date('Y-m-d H:i:s');
-
$TestModel = new Comment();
- $ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAssociated(array(
'Comment' => array(
'article_id' => 2,
@@ -4793,8 +4781,8 @@ public function testSaveAssociated() {
'comment' => 'New comment with attachment',
'published' => 'Y'
);
- $this->assertTrue($result[6]['Comment']['updated'] >= $ts);
- $this->assertTrue($result[6]['Comment']['created'] >= $ts);
+ $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
+ $this->assertEquals(self::date(), $result[6]['Comment']['created']);
unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']);
$this->assertEquals($expected, $result[6]['Comment']);
@@ -4803,8 +4791,8 @@ public function testSaveAssociated() {
'comment_id' => '7',
'attachment' => 'some_file.tgz'
);
- $this->assertTrue($result[6]['Attachment']['updated'] >= $ts);
- $this->assertTrue($result[6]['Attachment']['created'] >= $ts);
+ $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
+ $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']);
$this->assertEquals($expected, $result[6]['Attachment']);
}
@@ -4823,7 +4811,6 @@ public function testSaveMany() {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel);
- $ts = date('Y-m-d H:i:s');
$TestModel->saveMany(array(
array(
'title' => 'Multi-record post 1',
@@ -4860,10 +4847,10 @@ public function testSaveMany() {
)
)
);
- $this->assertTrue($result[0]['Post']['updated'] >= $ts);
- $this->assertTrue($result[0]['Post']['created'] >= $ts);
- $this->assertTrue($result[1]['Post']['updated'] >= $ts);
- $this->assertTrue($result[1]['Post']['created'] >= $ts);
+ $this->assertEquals(self::date(), $result[0]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[0]['Post']['created']);
+ $this->assertEquals(self::date(), $result[1]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[1]['Post']['created']);
unset($result[0]['Post']['updated'], $result[0]['Post']['created']);
unset($result[1]['Post']['updated'], $result[1]['Post']['created']);
$this->assertEquals($expected, $result);
@@ -5414,7 +5401,6 @@ public function testSaveManyTransaction() {
array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '')
);
- $ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1));
@@ -5467,10 +5453,10 @@ public function testSaveManyTransaction() {
'published' => 'N',
));
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
- $this->assertTrue($result[4]['Post']['created'] >= $ts);
- $this->assertTrue($result[4]['Post']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[4]['Post']['created']);
+ $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
$this->assertEquals($expected, $result);
@@ -5485,7 +5471,6 @@ public function testSaveManyTransaction() {
array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post')
);
- $ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1));
@@ -5537,10 +5522,10 @@ public function testSaveManyTransaction() {
'body' => 'Third Post Body',
'published' => 'N'
));
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
- $this->assertTrue($result[4]['Post']['created'] >= $ts);
- $this->assertTrue($result[4]['Post']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[4]['Post']['created']);
+ $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
}
@@ -5609,7 +5594,6 @@ public function testSaveManyValidation() {
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
$TestModel = new Post();
- $ts = date('Y-m-d H:i:s');
$data = array(
array(
'id' => '1',
@@ -5672,10 +5656,10 @@ public function testSaveManyValidation() {
)
);
- $this->assertTrue($result[0]['Post']['updated'] >= $ts);
- $this->assertTrue($result[1]['Post']['updated'] >= $ts);
- $this->assertTrue($result[3]['Post']['created'] >= $ts);
- $this->assertTrue($result[3]['Post']['updated'] >= $ts);
+ $this->assertEquals(self::date(), $result[0]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[1]['Post']['updated']);
+ $this->assertEquals(self::date(), $result[3]['Post']['created']);
+ $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result);
@@ -6372,7 +6356,6 @@ public function testSaveAllFieldListValidateBelongsTo() {
$result = $TestModel->find('all');
$this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3]));
- $ts = date('Y-m-d H:i:s');
// test belongsTo
$fieldList = array(
@@ -6398,15 +6381,15 @@ public function testSaveAllFieldListValidateBelongsTo() {
'title' => 'Post without body',
'body' => null,
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts,
+ 'created' => self::date(),
+ 'updated' => self::date(),
),
'Author' => array (
'id' => '5',
'user' => 'bob',
'password' => null,
- 'created' => $ts,
- 'updated' => $ts,
+ 'created' => self::date(),
+ 'updated' => self::date(),
'test' => 'working',
),
);
@@ -6418,7 +6401,6 @@ public function testSaveAllFieldListValidateBelongsTo() {
// test multirecord
$this->db->truncate($TestModel);
- $ts = date('Y-m-d H:i:s');
$fieldList = array('title', 'author_id');
$TestModel->saveAll(array(
array(
@@ -6444,8 +6426,8 @@ public function testSaveAllFieldListValidateBelongsTo() {
'title' => 'Multi-record post 1',
'body' => '',
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
)
),
array(
@@ -6455,8 +6437,8 @@ public function testSaveAllFieldListValidateBelongsTo() {
'title' => 'Multi-record post 2',
'body' => '',
'published' => 'N',
- 'created' => $ts,
- 'updated' => $ts
+ 'created' => self::date(),
+ 'updated' => self::date()
)
)
);
@@ -6544,7 +6526,6 @@ public function testSaveAllDeepFieldListValidateBelongsTo() {
$result = $TestModel->find('all');
$this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3]));
- $ts = date('Y-m-d H:i:s');
// test belongsTo
$fieldList = array(
View
192 lib/Cake/Test/Case/Network/CakeRequestTest.php
@@ -30,10 +30,6 @@ class CakeRequestTest extends CakeTestCase {
*/
public function setUp() {
parent::setUp();
- $this->_server = $_SERVER;
- $this->_get = $_GET;
- $this->_post = $_POST;
- $this->_files = $_FILES;
$this->_app = Configure::read('App');
$this->_case = null;
if (isset($_GET['case'])) {
@@ -51,10 +47,6 @@ public function setUp() {
*/
public function tearDown() {
parent::tearDown();
- $_SERVER = $this->_server;
- $_GET = $this->_get;
- $_POST = $this->_post;
- $_FILES = $this->_files;
if (!empty($this->_case)) {
$_GET['case'] = $this->_case;
}
@@ -217,94 +209,106 @@ public function testPostParsing() {
*
* @return void
*/
- public function testFILESParsing() {
- $_FILES = array('data' => array('name' => array(
- 'File' => array(
- array('data' => 'cake_sqlserver_patch.patch'),
- array('data' => 'controller.diff'),
- array('data' => ''),
- array('data' => ''),
- ),
- 'Post' => array('attachment' => 'jquery-1.2.1.js'),
- ),
- 'type' => array(
- 'File' => array(
- array('data' => ''),
- array('data' => ''),
- array('data' => ''),
- array('data' => ''),
+ public function testFilesParsing() {
+ $_FILES = array(
+ 'data' => array(
+ 'name' => array(
+ 'File' => array(
+ array('data' => 'cake_sqlserver_patch.patch'),
+ array('data' => 'controller.diff'),
+ array('data' => ''),
+ array('data' => ''),
+ ),
+ 'Post' => array('attachment' => 'jquery-1.2.1.js'),
+ ),
+ 'type' => array(
+ 'File' => array(
+ array('data' => ''),
+ array('data' => ''),
+ array('data' => ''),
+ array('data' => ''),
+ ),
+ 'Post' => array('attachment' => 'application/x-javascript'),
),
- 'Post' => array('attachment' => 'application/x-javascript'),
- ),
- 'tmp_name' => array(
- 'File' => array(
- array('data' => '/private/var/tmp/phpy05Ywj'),
- array('data' => '/private/var/tmp/php7MBztY'),
- array('data' => ''),
- array('data' => ''),
+ 'tmp_name' => array(
+ 'File' => array(
+ array('data' => '/private/var/tmp/phpy05Ywj'),
+ array('data' => '/private/var/tmp/php7MBztY'),
+ array('data' => ''),
+ array('data' => ''),
+ ),
+ 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
),
- 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
- ),
- 'error' => array(
- 'File' => array(
- array('data' => 0),
- array('data' => 0),
- array('data' => 4),
- array('data' => 4)
+ 'error' => array(
+ 'File' => array(
+ array('data' => 0),
+ array('data' => 0),
+ array('data' => 4),
+ array('data' => 4)
+ ),
+ 'Post' => array('attachment' => 0)
),
- 'Post' => array('attachment' => 0)
- ),
- 'size' => array(
- 'File' => array(
- array('data' => 6271),
- array('data' => 350),
- array('data' => 0),
- array('data' => 0),
+ 'size' => array(
+ 'File' => array(
+ array('data' => 6271),
+ array('data' => 350),
+ array('data' => 0),
+ array('data' => 0),
+ ),
+ 'Post' => array('attachment' => 80469)
),
- 'Post' => array('attachment' => 80469)
- ),
- ));
+ )
+ );
$request = new CakeRequest('some/path');
$expected = array(
'File' => array(
- array('data' => array(
- 'name' => 'cake_sqlserver_patch.patch',
- 'type' => '',
- 'tmp_name' => '/private/var/tmp/phpy05Ywj',
- 'error' => 0,
- 'size' => 6271,
- )),
array(
'data' => array(
- 'name' => 'controller.diff',
- 'type' => '',
- 'tmp_name' => '/private/var/tmp/php7MBztY',
- 'error' => 0,
- 'size' => 350,
- )),
- array('data' => array(
- 'name' => '',
- 'type' => '',
- 'tmp_name' => '',
- 'error' => 4,
- 'size' => 0,
- )),
- array('data' => array(
- 'name' => '',
- 'type' => '',
- 'tmp_name' => '',
- 'error' => 4,
- 'size' => 0,
- )),
+ 'name' => 'cake_sqlserver_patch.patch',
+ 'type' => '',
+ 'tmp_name' => '/private/var/tmp/phpy05Ywj',
+ 'error' => 0,
+ 'size' => 6271,
+ )
+ ),
+ array(
+ 'data' => array(
+ 'name' => 'controller.diff',
+ 'type' => '',
+ 'tmp_name' => '/private/var/tmp/php7MBztY',
+ 'error' => 0,
+ 'size' => 350,
+ )
+ ),
+ array(
+ 'data' => array(
+ 'name' => '',
+ 'type' => '',
+ 'tmp_name' => '',
+ 'error' => 4,
+ 'size' => 0,
+ )
+ ),
+ array(
+ 'data' => array(
+ 'name' => '',
+ 'type' => '',
+ 'tmp_name' => '',
+ 'error' => 4,
+ 'size' => 0,
+ )
+ ),
),
- 'Post' => array('attachment' => array(
- 'name' => 'jquery-1.2.1.js',
- 'type' => 'application/x-javascript',
- 'tmp_name' => '/private/var/tmp/phpEwlrIo',
- 'error' => 0,
- 'size' => 80469,
- ))
+ 'Post' => array(
+ 'attachment' => array(
+ 'name' => 'jquery-1.2.1.js',
+ 'type' => 'application/x-javascript',
+ 'tmp_name' => '/private/var/tmp/phpEwlrIo',
+ 'error' => 0,
+ 'size' => 80469,
+ )
+ )
);
$this->assertEquals($expected, $request->data);
@@ -343,12 +347,12 @@ public function testFILESParsing() {
1 => array(
'birth_cert' => '/private/var/tmp/phpbsUWfH',
'passport' => '/private/var/tmp/php7f5zLt',
- 'drivers_license' => '/private/var/tmp/phpMXpZgT',
+ 'drivers_license' => '/private/var/tmp/phpMXpZgT',
),
2 => array(
'birth_cert' => '/private/var/tmp/php5kHZt0',
- 'passport' => '/private/var/tmp/phpnYkOuM',
- 'drivers_license' => '/private/var/tmp/php9Rq0P3',
+ 'passport' => '/private/var/tmp/phpnYkOuM',
+ 'drivers_license' => '/private/var/tmp/php9Rq0P3',
)
)
),
@@ -357,12 +361,12 @@ public function testFILESParsing() {
1 => array(
'birth_cert' => 0,
'passport' => 0,
- 'drivers_license' => 0,
+ 'drivers_license' => 0,
),
2 => array(
'birth_cert' => 0,
- 'passport' => 0,
- 'drivers_license' => 0,
+ 'passport' => 0,
+ 'drivers_license' => 0,
)
)
),
@@ -371,12 +375,12 @@ public function testFILESParsing() {
1 => array(
'birth_cert' => 123,
'passport' => 458,
- 'drivers_license' => 875,
+ 'drivers_license' => 875,
),
2 => array(
'birth_cert' => 876,
- 'passport' => 976,
- 'drivers_license