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

This commit is contained in:
Jose Lorenzo Rodriguez 2012-04-23 23:34:45 -04:30
commit e7a7a177cc
50 changed files with 720 additions and 578 deletions

View file

@ -89,17 +89,24 @@ Cache::config('default', array('engine' => 'File'));
* The settings below can be used to set additional paths to models, views and controllers. * The settings below can be used to set additional paths to models, views and controllers.
* *
* App::build(array( * App::build(array(
* 'Plugin' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'), * 'Model' => array('/path/to/models', '/next/path/to/models'),
* 'Model' => array('/full/path/to/models/', '/next/full/path/to/models/'), * 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
* 'View' => array('/full/path/to/views/', '/next/full/path/to/views/'), * 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
* 'Controller' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'), * 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
* 'Model/Datasource' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'), * 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
* 'Model/Behavior' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'), * 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
* 'Controller/Component' => array('/full/path/to/components/', '/next/full/path/to/components/'), * 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
* 'View/Helper' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'), * 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
* 'Vendor' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'), * 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
* 'Console/Command' => array('/full/path/to/shells/', '/next/full/path/to/shells/'), * 'View' => array('/path/to/views', '/next/path/to/views'),
* 'Locale' => array('/full/path/to/locale/', '/next/full/path/to/locale/') * '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 file

@ -16,4 +16,4 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
?> ?>
<?php echo $content_for_layout; ?> <?php echo $this->fetch('content'); ?>

View file

@ -1,2 +1,2 @@
<?php echo $scripts_for_layout; ?> <?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 file

@ -8,7 +8,7 @@ if (!isset($channel['title'])) {
echo $this->Rss->document( echo $this->Rss->document(
$this->Rss->channel( $this->Rss->channel(
array(), $channel, $content_for_layout array(), $channel, $this->fetch('content')
) )
); );
?> ?>

View file

@ -1 +1 @@
<?php echo $content_for_layout; ?> <?php echo $this->fetch('content'); ?>

View file

@ -129,7 +129,7 @@ abstract class CacheEngine {
* *
* @param string $groups name of the group to be cleared * @param string $groups name of the group to be cleared
* @return boolean * @return boolean
**/ */
public function clearGroup($group) { public function clearGroup($group) {
return false; return false;
} }
@ -140,10 +140,10 @@ abstract class CacheEngine {
* the token representing each group in the cache key * the token representing each group in the cache key
* *
* @return array * @return array
**/ */
public function groups() { public function groups() {
return $this->settings['groups']; return $this->settings['groups'];
} }
/** /**
* Cache Engine settings * Cache Engine settings

View file

@ -115,7 +115,7 @@ class RedisEngine extends CacheEngine {
public function read($key) { public function read($key) {
$value = $this->_Redis->get($key); $value = $this->_Redis->get($key);
if (ctype_digit($value)) { if (ctype_digit($value)) {
$value = (int) $value; $value = (int)$value;
} }
if ($value !== false && is_string($value)) { if ($value !== false && is_string($value)) {
$value = unserialize($value); $value = unserialize($value);
@ -132,7 +132,7 @@ class RedisEngine extends CacheEngine {
* @throws CacheException when you try to increment with compress = true * @throws CacheException when you try to increment with compress = true
*/ */
public function increment($key, $offset = 1) { public function increment($key, $offset = 1) {
return (int) $this->_Redis->incrBy($key, $offset); return (int)$this->_Redis->incrBy($key, $offset);
} }
/** /**
@ -144,7 +144,7 @@ class RedisEngine extends CacheEngine {
* @throws CacheException when you try to decrement with compress = true * @throws CacheException when you try to decrement with compress = true
*/ */
public function decrement($key, $offset = 1) { public function decrement($key, $offset = 1) {
return (int) $this->_Redis->decrBy($key, $offset); return (int)$this->_Redis->decrBy($key, $offset);
} }
/** /**

View file

@ -464,6 +464,8 @@ class ExtractTask extends AppShell {
* @return void * @return void
*/ */
protected function _buildFiles() { protected function _buildFiles() {
$paths = $this->_paths;
$paths[] = realpath(APP) . DS;
foreach ($this->_translations as $domain => $translations) { foreach ($this->_translations as $domain => $translations) {
foreach ($translations as $msgid => $details) { foreach ($translations as $msgid => $details) {
$plural = $details['msgid_plural']; $plural = $details['msgid_plural'];
@ -474,7 +476,7 @@ class ExtractTask extends AppShell {
$occurrences[] = $file . ':' . implode(';', $lines); $occurrences[] = $file . ':' . implode(';', $lines);
} }
$occurrences = implode("\n#: ", $occurrences); $occurrences = implode("\n#: ", $occurrences);
$header = '#: ' . str_replace($this->_paths, '', $occurrences) . "\n"; $header = '#: ' . str_replace($paths, '', $occurrences) . "\n";
if ($plural === false) { if ($plural === false) {
$sentence = "msgid \"{$msgid}\"\n"; $sentence = "msgid \"{$msgid}\"\n";

View file

@ -30,17 +30,24 @@ Cache::config('default', array('engine' => 'File'));
* The settings below can be used to set additional paths to models, views and controllers. * The settings below can be used to set additional paths to models, views and controllers.
* *
* App::build(array( * App::build(array(
* 'Plugin' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'), * 'Model' => array('/path/to/models', '/next/path/to/models'),
* 'Model' => array('/full/path/to/models/', '/next/full/path/to/models/'), * 'Model/Behavior' => array('/path/to/behaviors', '/next/path/to/behaviors'),
* 'View' => array('/full/path/to/views/', '/next/full/path/to/views/'), * 'Model/Datasource' => array('/path/to/datasources', '/next/path/to/datasources'),
* 'Controller' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'), * 'Model/Datasource/Database' => array('/path/to/databases', '/next/path/to/database'),
* 'Model/Datasource' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'), * 'Model/Datasource/Session' => array('/path/to/sessions', '/next/path/to/sessions'),
* 'Model/Behavior' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'), * 'Controller' => array('/path/to/controllers', '/next/path/to/controllers'),
* 'Controller/Component' => array('/full/path/to/components/', '/next/full/path/to/components/'), * 'Controller/Component' => array('/path/to/components', '/next/path/to/components'),
* 'View/Helper' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'), * 'Controller/Component/Auth' => array('/path/to/auths', '/next/path/to/auths'),
* 'Vendor' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'), * 'Controller/Component/Acl' => array('/path/to/acls', '/next/path/to/acls'),
* 'Console/Command' => array('/full/path/to/shells/', '/next/full/path/to/shells/'), * 'View' => array('/path/to/views', '/next/path/to/views'),
* 'Locale' => array('/full/path/to/locale/', '/next/full/path/to/locale/') * '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 file

@ -24,7 +24,7 @@
</head> </head>
<body> <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> <p>This email was sent using the <a href="http://cakephp.org">CakePHP Framework</a></p>
</body> </body>

View file

@ -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. This email was sent using the CakePHP Framework, http://cakephp.org.

View file

@ -16,4 +16,4 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php) * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
?> ?>
<?php echo $content_for_layout; ?> <?php echo $this->fetch('content'); ?>

View file

@ -1,2 +1,2 @@
<?php echo $scripts_for_layout; ?> <?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 file

@ -8,7 +8,7 @@ if (!isset($channel['title'])) {
echo $this->Rss->document( echo $this->Rss->document(
$this->Rss->channel( $this->Rss->channel(
array(), $channel, $content_for_layout array(), $channel, $this->fetch('content')
) )
); );
?> ?>

View file

@ -1 +1 @@
<?php echo $content_for_layout; ?> <?php echo $this->fetch('content'); ?>

View file

@ -420,31 +420,6 @@ class EmailComponent extends Component {
return null; return null;
} }
/**
* 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 * Format addresses to be an array with email as key and alias as value
* *
@ -455,7 +430,7 @@ class EmailComponent extends Component {
$formatted = array(); $formatted = array();
foreach ($addresses as $address) { foreach ($addresses as $address) {
if (preg_match('/((.*))?\s?<(.+)>/', $address, $matches) && !empty($matches[2])) { 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 { } else {
$address = $this->_strip($address); $address = $this->_strip($address);
$formatted[$address] = $address; $formatted[$address] = $address;

View file

@ -77,17 +77,6 @@ class Mysql extends DboSource {
*/ */
protected $_useAlias = true; 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 * List of engine specific additional field parameters used on table creating
* *
@ -262,15 +251,6 @@ class Mysql extends DboSource {
return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value; return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value;
} }
/**
* 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 * Query charset by collation
* *
@ -696,4 +676,13 @@ class Mysql extends DboSource {
return $this->config['database']; 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 file

@ -33,17 +33,6 @@ class Postgres extends DboSource {
*/ */
public $description = "PostgreSQL DBO Driver"; 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. * Base driver configuration settings. Merged with user settings.
* *
@ -906,4 +895,13 @@ class Postgres extends DboSource {
return $this->config['schema']; 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 file

@ -559,4 +559,13 @@ class Sqlite extends DboSource {
return "main"; // Sqlite Datasource does not support multidb 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 file

@ -98,31 +98,12 @@ class Sqlserver extends DboSource {
'boolean' => array('name' => 'bit') 'boolean' => array('name' => 'bit')
); );
/**
* 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 * Magic column name used to provide pagination support for SQLServer 2008
* which lacks proper limit/offset support. * which lacks proper limit/offset support.
*/ */
const ROW_COUNTER = '_cake_page_rownum_'; 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. * Connects to the database using options in the given configuration array.
* *
@ -151,7 +132,6 @@ class Sqlserver extends DboSource {
throw new MissingConnectionException(array('class' => $e->getMessage())); throw new MissingConnectionException(array('class' => $e->getMessage()));
} }
$this->_version = $this->_connection->getAttribute(PDO::ATTR_SERVER_VERSION);
return $this->connected; return $this->connected;
} }
@ -515,7 +495,7 @@ class Sqlserver extends DboSource {
} }
// For older versions use the subquery version of pagination. // 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); preg_match('/OFFSET\s*(\d+)\s*.*?(\d+)\s*ROWS/', $limit, $limitOffset);
$limit = 'TOP ' . intval($limitOffset[2]); $limit = 'TOP ' . intval($limitOffset[2]);

View file

@ -69,6 +69,15 @@ class DboSource extends DataSource {
*/ */
public $cacheMethods = true; 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? * Print full query debug info?
* *
@ -183,17 +192,6 @@ class DboSource extends DataSource {
*/ */
protected $_transactionNesting = 0; 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 * Default fields that are used by the DBO
* *
@ -294,12 +292,21 @@ class DboSource extends DataSource {
/** /**
* Get the underlying connection object. * Get the underlying connection object.
* *
* @return PDOConnection * @return PDO
*/ */
public function getConnection() { public function getConnection() {
return $this->_connection; 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. * Returns a quoted and escaped string of $data for use in an SQL statement.
* *
@ -2019,6 +2026,15 @@ class DboSource extends DataSource {
return $this->execute('TRUNCATE TABLE ' . $this->fullTableName($table)); return $this->execute('TRUNCATE TABLE ' . $this->fullTableName($table));
} }
/**
* Check if the server support nested transactions
*
* @return boolean
*/
public function supportNestedTransaction() {
return false;
}
/** /**
* Begin a transaction * Begin a transaction
* *
@ -2027,15 +2043,33 @@ class DboSource extends DataSource {
* or a transaction has not started). * or a transaction has not started).
*/ */
public function begin() { public function begin() {
if ($this->_transactionStarted || $this->_connection->beginTransaction()) { if ($this->_transactionStarted) {
if ($this->fullDebug && empty($this->_transactionNesting)) { if ($this->supportNestedTransaction()) {
$this->logQuery('BEGIN'); return $this->_beginNested();
} }
$this->_transactionStarted = true;
$this->_transactionNesting++; $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 @@ class DboSource extends DataSource {
* or a transaction has not started). * or a transaction has not started).
*/ */
public function commit() { public function commit() {
if ($this->_transactionStarted) { if (!$this->_transactionStarted) {
$this->_transactionNesting--; return false;
if ($this->_transactionNesting <= 0) {
$this->_transactionStarted = false;
$this->_transactionNesting = 0;
if ($this->fullDebug) {
$this->logQuery('COMMIT');
}
return $this->_connection->commit();
}
return true;
} }
return false;
if ($this->_transactionNesting === 0) {
if ($this->fullDebug) {
$this->logQuery('COMMIT');
}
$this->_transactionStarted = false;
return $this->_connection->commit();
}
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 @@ class DboSource extends DataSource {
* or a transaction has not started). * or a transaction has not started).
*/ */
public function rollback() { public function rollback() {
if ($this->_transactionStarted && $this->_connection->rollBack()) { if (!$this->_transactionStarted) {
return false;
}
if ($this->_transactionNesting === 0) {
if ($this->fullDebug) { if ($this->fullDebug) {
$this->logQuery('ROLLBACK'); $this->logQuery('ROLLBACK');
} }
$this->_transactionStarted = false; $this->_transactionStarted = false;
$this->_transactionNesting = 0; return $this->_connection->rollBack();
return true;
} }
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 file

@ -1629,7 +1629,7 @@ class Model extends Object implements CakeEventListener {
if (!array_key_exists('format', $colType)) { if (!array_key_exists('format', $colType)) {
$time = strtotime('now'); $time = strtotime('now');
} else { } else {
$time = $colType['formatter']($colType['format']); $time = call_user_func($colType['formatter'], $colType['format']);
} }
if (!empty($this->whitelist)) { if (!empty($this->whitelist)) {
$this->whitelist[] = $updateCol; $this->whitelist[] = $updateCol;

View file

@ -320,21 +320,31 @@ class CakeRequest implements ArrayAccess {
if (isset($_FILES['data'])) { if (isset($_FILES['data'])) {
foreach ($_FILES['data'] as $key => $data) { foreach ($_FILES['data'] as $key => $data) {
foreach ($data as $model => $fields) { $this->_processFileData('', $data, $key);
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; /**
} * Recursively walks the FILES array restructuring the data
} else { * into something sane and useable.
$this->data[$model][$field][$key] = $value; *
} * @param string $path The dot separated path to insert $data into.
} * @param array $data The data to traverse/insert.
} else { * @param string $field The terminal field name, which is the top level key in $_FILES.
$this->data[$model][$key] = $fields; * @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 file

@ -44,7 +44,7 @@ class Dispatcher implements CakeEventListener {
* Event manager, used to handle dispatcher filters * Event manager, used to handle dispatcher filters
* *
* @var CakeEventMaanger * @var CakeEventMaanger
**/ */
protected $_eventManager; protected $_eventManager;
/** /**
@ -63,7 +63,7 @@ class Dispatcher implements CakeEventListener {
* creted. Attaches the default listeners and filters * creted. Attaches the default listeners and filters
* *
* @return CakeEventmanger * @return CakeEventmanger
**/ */
public function getEventManager() { public function getEventManager() {
if (!$this->_eventManager) { if (!$this->_eventManager) {
$this->_eventManager = new CakeEventManager(); $this->_eventManager = new CakeEventManager();
@ -77,7 +77,7 @@ class Dispatcher implements CakeEventListener {
* Returns the list of events this object listents to. * Returns the list of events this object listents to.
* *
* @return array * @return array
**/ */
public function implementedEvents() { public function implementedEvents() {
return array('Dispatcher.beforeDispatch' => 'parseParams'); return array('Dispatcher.beforeDispatch' => 'parseParams');
} }
@ -88,7 +88,8 @@ class Dispatcher implements CakeEventListener {
* *
* @param CakeEventManager $manager * @param CakeEventManager $manager
* @return void * @return void
**/ * @throws MissingDispatcherFilterException
*/
protected function _attachFilters($manager) { protected function _attachFilters($manager) {
$filters = Configure::read('Dispatcher.filters'); $filters = Configure::read('Dispatcher.filters');
if (empty($filters)) { if (empty($filters)) {

View file

@ -1,19 +1,15 @@
<?php <?php
/** /**
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* *
* Licensed under The MIT License * Licensed under The MIT License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project * @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Routing * @since CakePHP(tm) v 2.2
* @since CakePHP(tm) v 2.2 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/ */
App::uses('DispatcherFilter', 'Routing'); App::uses('DispatcherFilter', 'Routing');
@ -31,7 +27,7 @@ class CacheDispatcher extends DispatcherFilter {
* This filter should run before the request gets parsed by router * This filter should run before the request gets parsed by router
* *
* @var int * @var int
**/ */
public $priority = 9; public $priority = 9;
/** /**

View file

@ -1014,7 +1014,8 @@ class Router {
public static function normalize($url = '/') { public static function normalize($url = '/') {
if (is_array($url)) { if (is_array($url)) {
$url = Router::url($url); $url = Router::url($url);
} elseif (preg_match('/^[a-z\-]+:\/\//', $url)) { }
if (preg_match('/^[a-z\-]+:\/\//', $url)) {
return $url; return $url;
} }
$request = Router::getRequest(); $request = Router::getRequest();

View file

@ -410,7 +410,7 @@ class FileEngineTest extends CakeTestCase {
$this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups')); $this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups'));
} }
/** /**
* Tests that deleteing from a groups-enabled config is possible * Tests that deleteing from a groups-enabled config is possible
* *
* @return void * @return void

View file

@ -220,7 +220,6 @@ class RegisEngineTest extends CakeTestCase {
$this->assertEquals(3, $result); $this->assertEquals(3, $result);
} }
/** /**
* test clearing redis. * test clearing redis.
* *

View file

@ -163,7 +163,6 @@ class FormAuthenticateTest extends CakeTestCase {
), App::RESET); ), App::RESET);
CakePlugin::load('TestPlugin'); CakePlugin::load('TestPlugin');
$ts = date('Y-m-d H:i:s');
$PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser'); $PluginModel = ClassRegistry::init('TestPlugin.TestPluginAuthUser');
$user['id'] = 1; $user['id'] = 1;
$user['username'] = 'gwoo'; $user['username'] = 'gwoo';
@ -185,7 +184,7 @@ class FormAuthenticateTest extends CakeTestCase {
'username' => 'gwoo', 'username' => 'gwoo',
'created' => '2007-03-17 01:16:23' 'created' => '2007-03-17 01:16:23'
); );
$this->assertTrue($result['updated'] >= $ts); $this->assertEquals(self::date(), $result['updated']);
unset($result['updated']); unset($result['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
CakePlugin::unload(); CakePlugin::unload();

View file

@ -868,4 +868,22 @@ HTMLBLOC;
$this->assertNotRegExp('/Message-ID:/', $result); $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 file

@ -45,7 +45,7 @@ class MysqlTest extends CakeTestCase {
public $fixtures = array( public $fixtures = array(
'core.apple', 'core.article', 'core.articles_tag', 'core.attachment', 'core.comment', '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.sample', 'core.tag', 'core.user', 'core.post', 'core.author', 'core.data_test',
'core.binary_test' 'core.binary_test', 'app.address'
); );
/** /**
@ -3579,4 +3579,38 @@ class MysqlTest extends CakeTestCase {
->with("TRUNCATE TABLE `$schema`.`tbl_articles`"); ->with("TRUNCATE TABLE `$schema`.`tbl_articles`");
$this->Dbo->truncate('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 file

@ -909,4 +909,37 @@ class PostgresTest extends CakeTestCase {
$this->Dbo->truncate('articles'); $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 file

@ -383,4 +383,37 @@ class SqliteTest extends CakeTestCase {
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid'); $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 file

@ -35,6 +35,8 @@ class MockDataSource extends DataSource {
class DboTestSource extends DboSource { class DboTestSource extends DboSource {
public static $nested = true;
public function connect($config = array()) { public function connect($config = array()) {
$this->connected = true; $this->connected = true;
} }
@ -51,6 +53,10 @@ class DboTestSource extends DboSource {
$this->_connection = $conn; $this->_connection = $conn;
} }
public function supportNestedTransaction() {
return $this->nestedTransaction && self::$nested;
}
} }
/** /**
@ -834,6 +840,79 @@ class DboSourceTest extends CakeTestCase {
$this->assertEquals($expected, $log['log'][0]); $this->assertEquals($expected, $log['log'][0]);
} }
/**
* 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 * Test build statement with some fields missing
* *

View file

@ -1866,7 +1866,6 @@ class ModelIntegrationTest extends BaseModelTest {
'doomed' => true 'doomed' => true
)))); ))));
$ts = date('Y-m-d H:i:s');
$TestModel->save(); $TestModel->save();
$TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC'; $TestModel->hasAndBelongsToMany['SomethingElse']['order'] = 'SomethingElse.id ASC';
@ -1920,7 +1919,7 @@ class ModelIntegrationTest extends BaseModelTest {
) )
) )
); );
$this->assertTrue($result['Something']['updated'] >= $ts); $this->assertEquals(self::date(), $result['Something']['updated']);
unset($result['Something']['updated']); unset($result['Something']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
} }

View file

@ -1613,7 +1613,6 @@ class ModelWriteTest extends BaseModelTest {
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$ts = date('Y-m-d H:i:s');
$TestModel->id = 2; $TestModel->id = 2;
$data = array('Tag' => array('Tag' => array(2))); $data = array('Tag' => array('Tag' => array(2)));
$TestModel->save($data); $TestModel->save($data);
@ -1627,7 +1626,7 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Second Article Body', 'body' => 'Second Article Body',
'published' => 'Y', 'published' => 'Y',
'created' => '2007-03-18 10:41:23', 'created' => '2007-03-18 10:41:23',
'updated' => $ts 'updated' => self::date()
), ),
'Tag' => array( 'Tag' => array(
array( array(
@ -2561,29 +2560,28 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$ts = date('Y-m-d H:i:s');
$TestModel->id = 1; $TestModel->id = 1;
$data = array( $data = array(
'JoinA' => array( 'JoinA' => array(
'id' => '1', 'id' => '1',
'name' => 'New name for Join A 1', 'name' => 'New name for Join A 1',
'updated' => $ts 'updated' => self::date()
), ),
'JoinB' => array( 'JoinB' => array(
array( array(
'id' => 1, 'id' => 1,
'join_b_id' => 2, 'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2', 'other' => 'New data for Join A 1 Join B 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)), )),
'JoinC' => array( 'JoinC' => array(
array( array(
'id' => 1, 'id' => 1,
'join_c_id' => 2, 'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2', 'other' => 'New data for Join A 1 Join C 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
))); )));
$TestModel->set($data); $TestModel->set($data);
@ -2596,7 +2594,7 @@ class ModelWriteTest extends BaseModelTest {
'name' => 'New name for Join A 1', 'name' => 'New name for Join A 1',
'body' => 'Join A 1 Body', 'body' => 'Join A 1 Body',
'created' => '2008-01-03 10:54:23', 'created' => '2008-01-03 10:54:23',
'updated' => $ts 'updated' => self::date()
), ),
'JoinB' => array( 'JoinB' => array(
0 => array( 0 => array(
@ -2609,8 +2607,8 @@ class ModelWriteTest extends BaseModelTest {
'join_a_id' => 1, 'join_a_id' => 1,
'join_b_id' => 2, 'join_b_id' => 2,
'other' => 'New data for Join A 1 Join B 2', 'other' => 'New data for Join A 1 Join B 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
))), ))),
'JoinC' => array( 'JoinC' => array(
0 => array( 0 => array(
@ -2623,8 +2621,8 @@ class ModelWriteTest extends BaseModelTest {
'join_a_id' => 1, 'join_a_id' => 1,
'join_c_id' => 2, 'join_c_id' => 2,
'other' => 'New data for Join A 1 Join C 2', 'other' => 'New data for Join A 1 Join C 2',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)))); ))));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -2642,7 +2640,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array( $TestModel->saveAll(array(
'Post' => array( 'Post' => array(
@ -2669,10 +2666,10 @@ class ModelWriteTest extends BaseModelTest {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Author']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['created']);
$this->assertTrue($result[3]['Author']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[3]['Author']['created'], $result[3]['Author']['updated']); unset($result[3]['Author']['created'], $result[3]['Author']['updated']);
$this->assertEquals($expected, $result[3]); $this->assertEquals($expected, $result[3]);
@ -2684,7 +2681,6 @@ class ModelWriteTest extends BaseModelTest {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$TestModel->saveAll(array( $TestModel->saveAll(array(
array( array(
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
@ -2718,16 +2714,15 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Second multi-record post', 'body' => 'Second multi-record post',
'published' => 'N' 'published' => 'N'
))); )));
$this->assertTrue($result[0]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['created']);
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['created']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
unset($result[0]['Post']['created'], $result[0]['Post']['updated']); unset($result[0]['Post']['created'], $result[0]['Post']['updated']);
unset($result[1]['Post']['created'], $result[1]['Post']['updated']); unset($result[1]['Post']['created'], $result[1]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
$TestModel = new Comment(); $TestModel = new Comment();
$ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAll(array( $result = $TestModel->saveAll(array(
'Comment' => array( 'Comment' => array(
'article_id' => 2, 'article_id' => 2,
@ -2748,8 +2743,8 @@ class ModelWriteTest extends BaseModelTest {
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y' 'published' => 'Y'
); );
$this->assertTrue($result[6]['Comment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['created']);
$this->assertTrue($result[6]['Comment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']); unset($result[6]['Comment']['created'], $result[6]['Comment']['updated']);
$this->assertEquals($expected, $result[6]['Comment']); $this->assertEquals($expected, $result[6]['Comment']);
@ -2758,8 +2753,8 @@ class ModelWriteTest extends BaseModelTest {
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz' 'attachment' => 'some_file.tgz'
); );
$this->assertTrue($result[6]['Attachment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']); unset($result[6]['Attachment']['created'], $result[6]['Attachment']['updated']);
$this->assertEquals($expected, $result[6]['Attachment']); $this->assertEquals($expected, $result[6]['Attachment']);
} }
@ -4056,7 +4051,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data)); $this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -4098,8 +4092,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$expected[] = array( $expected[] = array(
@ -4109,8 +4103,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fifth Post', 'title' => 'New Fifth Post',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4125,7 +4119,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => ''), array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post') array('author_id' => 1, 'title' => 'New Sixth Post')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveAll($data)); $this->assertFalse($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -4167,8 +4160,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'New Fourth Post', 'title' => 'New Fourth Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
$expected[] = array( $expected[] = array(
@ -4178,8 +4171,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Third Post', 'title' => 'Third Post',
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
)); ));
} }
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4264,7 +4257,6 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => 2 'author_id' => 2
)); ));
$ts = date('Y-m-d H:i:s');
$this->assertTrue($TestModel->saveAll($data)); $this->assertTrue($TestModel->saveAll($data));
$result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC')); $result = $TestModel->find('all', array('recursive' => -1, 'order' => 'Post.id ASC'));
@ -4305,10 +4297,10 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Fourth post body', 'body' => 'Fourth post body',
'published' => 'N' 'published' => 'N'
))); )));
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']); unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -4399,10 +4391,10 @@ class ModelWriteTest extends BaseModelTest {
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
unset( unset(
$result[0]['Post']['updated'], $result[1]['Post']['updated'], $result[0]['Post']['updated'], $result[1]['Post']['updated'],
$result[3]['Post']['updated'], $result[3]['Post']['created'] $result[3]['Post']['updated'], $result[3]['Post']['created']
@ -4731,7 +4723,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
$TestModel->saveAssociated(array( $TestModel->saveAssociated(array(
'Post' => array( 'Post' => array(
@ -4758,10 +4749,10 @@ class ModelWriteTest extends BaseModelTest {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90', 'password' => '5f4dcc3b5aa765d61d8327deb882cf90',
'test' => 'working' 'test' => 'working'
)); ));
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Author']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['created']);
$this->assertTrue($result[3]['Author']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Author']['updated']);
unset( unset(
$result[3]['Post']['updated'], $result[3]['Post']['created'], $result[3]['Post']['updated'], $result[3]['Post']['created'],
$result[3]['Author']['updated'], $result[3]['Author']['created'] $result[3]['Author']['updated'], $result[3]['Author']['created']
@ -4769,10 +4760,7 @@ class ModelWriteTest extends BaseModelTest {
$this->assertEquals($expected, $result[3]); $this->assertEquals($expected, $result[3]);
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
$ts = date('Y-m-d H:i:s');
$TestModel = new Comment(); $TestModel = new Comment();
$ts = date('Y-m-d H:i:s');
$result = $TestModel->saveAssociated(array( $result = $TestModel->saveAssociated(array(
'Comment' => array( 'Comment' => array(
'article_id' => 2, 'article_id' => 2,
@ -4793,8 +4781,8 @@ class ModelWriteTest extends BaseModelTest {
'comment' => 'New comment with attachment', 'comment' => 'New comment with attachment',
'published' => 'Y' 'published' => 'Y'
); );
$this->assertTrue($result[6]['Comment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['updated']);
$this->assertTrue($result[6]['Comment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Comment']['created']);
unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']); unset($result[6]['Comment']['updated'], $result[6]['Comment']['created']);
$this->assertEquals($expected, $result[6]['Comment']); $this->assertEquals($expected, $result[6]['Comment']);
@ -4803,8 +4791,8 @@ class ModelWriteTest extends BaseModelTest {
'comment_id' => '7', 'comment_id' => '7',
'attachment' => 'some_file.tgz' 'attachment' => 'some_file.tgz'
); );
$this->assertTrue($result[6]['Attachment']['updated'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['updated']);
$this->assertTrue($result[6]['Attachment']['created'] >= $ts); $this->assertEquals(self::date(), $result[6]['Attachment']['created']);
unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']); unset($result[6]['Attachment']['updated'], $result[6]['Attachment']['created']);
$this->assertEquals($expected, $result[6]['Attachment']); $this->assertEquals($expected, $result[6]['Attachment']);
} }
@ -4823,7 +4811,6 @@ class ModelWriteTest extends BaseModelTest {
// SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass // SQLite seems to reset the PK counter when that happens, so we need this to make the tests pass
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$TestModel->saveMany(array( $TestModel->saveMany(array(
array( array(
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
@ -4860,10 +4847,10 @@ class ModelWriteTest extends BaseModelTest {
) )
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[0]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['created']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[1]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['created']);
unset($result[0]['Post']['updated'], $result[0]['Post']['created']); unset($result[0]['Post']['updated'], $result[0]['Post']['created']);
unset($result[1]['Post']['updated'], $result[1]['Post']['created']); unset($result[1]['Post']['updated'], $result[1]['Post']['created']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -5414,7 +5401,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => 'New Fifth Post'), array('author_id' => 1, 'title' => 'New Fifth Post'),
array('author_id' => 1, 'title' => '') array('author_id' => 1, 'title' => '')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data)); $this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -5467,10 +5453,10 @@ class ModelWriteTest extends BaseModelTest {
'published' => 'N', 'published' => 'N',
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[4]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['created']);
$this->assertTrue($result[4]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']); unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -5485,7 +5471,6 @@ class ModelWriteTest extends BaseModelTest {
array('author_id' => 1, 'title' => ''), array('author_id' => 1, 'title' => ''),
array('author_id' => 1, 'title' => 'New Sixth Post') array('author_id' => 1, 'title' => 'New Sixth Post')
); );
$ts = date('Y-m-d H:i:s');
$this->assertFalse($TestModel->saveMany($data)); $this->assertFalse($TestModel->saveMany($data));
$result = $TestModel->find('all', array('recursive' => -1)); $result = $TestModel->find('all', array('recursive' => -1));
@ -5537,10 +5522,10 @@ class ModelWriteTest extends BaseModelTest {
'body' => 'Third Post Body', 'body' => 'Third Post Body',
'published' => 'N' 'published' => 'N'
)); ));
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
$this->assertTrue($result[4]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['created']);
$this->assertTrue($result[4]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[4]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
unset($result[4]['Post']['created'], $result[4]['Post']['updated']); unset($result[4]['Post']['created'], $result[4]['Post']['updated']);
} }
@ -5609,7 +5594,6 @@ class ModelWriteTest extends BaseModelTest {
$this->loadFixtures('Post', 'Author', 'Comment', 'Attachment'); $this->loadFixtures('Post', 'Author', 'Comment', 'Attachment');
$TestModel = new Post(); $TestModel = new Post();
$ts = date('Y-m-d H:i:s');
$data = array( $data = array(
array( array(
'id' => '1', 'id' => '1',
@ -5672,10 +5656,10 @@ class ModelWriteTest extends BaseModelTest {
) )
); );
$this->assertTrue($result[0]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[0]['Post']['updated']);
$this->assertTrue($result[1]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[1]['Post']['updated']);
$this->assertTrue($result[3]['Post']['created'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['created']);
$this->assertTrue($result[3]['Post']['updated'] >= $ts); $this->assertEquals(self::date(), $result[3]['Post']['updated']);
unset($result[0]['Post']['updated'], $result[1]['Post']['updated']); unset($result[0]['Post']['updated'], $result[1]['Post']['updated']);
unset($result[3]['Post']['created'], $result[3]['Post']['updated']); unset($result[3]['Post']['created'], $result[3]['Post']['updated']);
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
@ -6372,7 +6356,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
// test belongsTo // test belongsTo
$fieldList = array( $fieldList = array(
@ -6398,15 +6381,15 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Post without body', 'title' => 'Post without body',
'body' => null, 'body' => null,
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts, 'updated' => self::date(),
), ),
'Author' => array ( 'Author' => array (
'id' => '5', 'id' => '5',
'user' => 'bob', 'user' => 'bob',
'password' => null, 'password' => null,
'created' => $ts, 'created' => self::date(),
'updated' => $ts, 'updated' => self::date(),
'test' => 'working', 'test' => 'working',
), ),
); );
@ -6418,7 +6401,6 @@ class ModelWriteTest extends BaseModelTest {
// test multirecord // test multirecord
$this->db->truncate($TestModel); $this->db->truncate($TestModel);
$ts = date('Y-m-d H:i:s');
$fieldList = array('title', 'author_id'); $fieldList = array('title', 'author_id');
$TestModel->saveAll(array( $TestModel->saveAll(array(
array( array(
@ -6444,8 +6426,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Multi-record post 1', 'title' => 'Multi-record post 1',
'body' => '', 'body' => '',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
) )
), ),
array( array(
@ -6455,8 +6437,8 @@ class ModelWriteTest extends BaseModelTest {
'title' => 'Multi-record post 2', 'title' => 'Multi-record post 2',
'body' => '', 'body' => '',
'published' => 'N', 'published' => 'N',
'created' => $ts, 'created' => self::date(),
'updated' => $ts 'updated' => self::date()
) )
) )
); );
@ -6544,7 +6526,6 @@ class ModelWriteTest extends BaseModelTest {
$result = $TestModel->find('all'); $result = $TestModel->find('all');
$this->assertEquals(3, count($result)); $this->assertEquals(3, count($result));
$this->assertFalse(isset($result[3])); $this->assertFalse(isset($result[3]));
$ts = date('Y-m-d H:i:s');
// test belongsTo // test belongsTo
$fieldList = array( $fieldList = array(

View file

@ -30,10 +30,6 @@ class CakeRequestTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->_server = $_SERVER;
$this->_get = $_GET;
$this->_post = $_POST;
$this->_files = $_FILES;
$this->_app = Configure::read('App'); $this->_app = Configure::read('App');
$this->_case = null; $this->_case = null;
if (isset($_GET['case'])) { if (isset($_GET['case'])) {
@ -51,10 +47,6 @@ class CakeRequestTest extends CakeTestCase {
*/ */
public function tearDown() { public function tearDown() {
parent::tearDown(); parent::tearDown();
$_SERVER = $this->_server;
$_GET = $this->_get;
$_POST = $this->_post;
$_FILES = $this->_files;
if (!empty($this->_case)) { if (!empty($this->_case)) {
$_GET['case'] = $this->_case; $_GET['case'] = $this->_case;
} }
@ -217,94 +209,106 @@ class CakeRequestTest extends CakeTestCase {
* *
* @return void * @return void
*/ */
public function testFILESParsing() { public function testFilesParsing() {
$_FILES = array('data' => array('name' => array( $_FILES = array(
'File' => array( 'data' => array(
array('data' => 'cake_sqlserver_patch.patch'), 'name' => array(
array('data' => 'controller.diff'), 'File' => array(
array('data' => ''), array('data' => 'cake_sqlserver_patch.patch'),
array('data' => ''), 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' => 'jquery-1.2.1.js'), 'tmp_name' => array(
), 'File' => array(
'type' => array( array('data' => '/private/var/tmp/phpy05Ywj'),
'File' => array( array('data' => '/private/var/tmp/php7MBztY'),
array('data' => ''), array('data' => ''),
array('data' => ''), array('data' => ''),
array('data' => ''), ),
array('data' => ''), 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
), ),
'Post' => array('attachment' => 'application/x-javascript'), 'error' => array(
), 'File' => array(
'tmp_name' => array( array('data' => 0),
'File' => array( array('data' => 0),
array('data' => '/private/var/tmp/phpy05Ywj'), array('data' => 4),
array('data' => '/private/var/tmp/php7MBztY'), array('data' => 4)
array('data' => ''), ),
array('data' => ''), 'Post' => array('attachment' => 0)
), ),
'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'), 'size' => array(
), 'File' => array(
'error' => array( array('data' => 6271),
'File' => array( array('data' => 350),
array('data' => 0), array('data' => 0),
array('data' => 0), array('data' => 0),
array('data' => 4), ),
array('data' => 4) 'Post' => array('attachment' => 80469)
), ),
'Post' => array('attachment' => 0) )
), );
'size' => array(
'File' => array(
array('data' => 6271),
array('data' => 350),
array('data' => 0),
array('data' => 0),
),
'Post' => array('attachment' => 80469)
),
));
$request = new CakeRequest('some/path'); $request = new CakeRequest('some/path');
$expected = array( $expected = array(
'File' => array( 'File' => array(
array('data' => array(
'name' => 'cake_sqlserver_patch.patch',
'type' => '',
'tmp_name' => '/private/var/tmp/phpy05Ywj',
'error' => 0,
'size' => 6271,
)),
array( array(
'data' => array( 'data' => array(
'name' => 'controller.diff', 'name' => 'cake_sqlserver_patch.patch',
'type' => '', 'type' => '',
'tmp_name' => '/private/var/tmp/php7MBztY', 'tmp_name' => '/private/var/tmp/phpy05Ywj',
'error' => 0, 'error' => 0,
'size' => 350, 'size' => 6271,
)), )
array('data' => array( ),
'name' => '', array(
'type' => '', 'data' => array(
'tmp_name' => '', 'name' => 'controller.diff',
'error' => 4, 'type' => '',
'size' => 0, 'tmp_name' => '/private/var/tmp/php7MBztY',
)), 'error' => 0,
array('data' => array( 'size' => 350,
'name' => '', )
'type' => '', ),
'tmp_name' => '', array(
'error' => 4, 'data' => array(
'size' => 0, 'name' => '',
)), 'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
)
),
array(
'data' => array(
'name' => '',
'type' => '',
'tmp_name' => '',
'error' => 4,
'size' => 0,
)
),
), ),
'Post' => array('attachment' => array( 'Post' => array(
'name' => 'jquery-1.2.1.js', 'attachment' => array(
'type' => 'application/x-javascript', 'name' => 'jquery-1.2.1.js',
'tmp_name' => '/private/var/tmp/phpEwlrIo', 'type' => 'application/x-javascript',
'error' => 0, 'tmp_name' => '/private/var/tmp/phpEwlrIo',
'size' => 80469, 'error' => 0,
)) 'size' => 80469,
)
)
); );
$this->assertEquals($expected, $request->data); $this->assertEquals($expected, $request->data);
@ -343,12 +347,12 @@ class CakeRequestTest extends CakeTestCase {
1 => array( 1 => array(
'birth_cert' => '/private/var/tmp/phpbsUWfH', 'birth_cert' => '/private/var/tmp/phpbsUWfH',
'passport' => '/private/var/tmp/php7f5zLt', 'passport' => '/private/var/tmp/php7f5zLt',
'drivers_license' => '/private/var/tmp/phpMXpZgT', 'drivers_license' => '/private/var/tmp/phpMXpZgT',
), ),
2 => array( 2 => array(
'birth_cert' => '/private/var/tmp/php5kHZt0', 'birth_cert' => '/private/var/tmp/php5kHZt0',
'passport' => '/private/var/tmp/phpnYkOuM', 'passport' => '/private/var/tmp/phpnYkOuM',
'drivers_license' => '/private/var/tmp/php9Rq0P3', 'drivers_license' => '/private/var/tmp/php9Rq0P3',
) )
) )
), ),
@ -357,12 +361,12 @@ class CakeRequestTest extends CakeTestCase {
1 => array( 1 => array(
'birth_cert' => 0, 'birth_cert' => 0,
'passport' => 0, 'passport' => 0,
'drivers_license' => 0, 'drivers_license' => 0,
), ),
2 => array( 2 => array(
'birth_cert' => 0, 'birth_cert' => 0,
'passport' => 0, 'passport' => 0,
'drivers_license' => 0, 'drivers_license' => 0,
) )
) )
), ),
@ -371,12 +375,12 @@ class CakeRequestTest extends CakeTestCase {
1 => array( 1 => array(
'birth_cert' => 123, 'birth_cert' => 123,
'passport' => 458, 'passport' => 458,
'drivers_license' => 875, 'drivers_license' => 875,
), ),
2 => array( 2 => array(
'birth_cert' => 876, 'birth_cert' => 876,
'passport' => 976, 'passport' => 976,
'drivers_license' => 9783, 'drivers_license' => 9783,
) )
) )
) )

View file

@ -48,7 +48,7 @@ class TestDispatcher extends Dispatcher {
* Controller instance, made publicly available for testing * Controller instance, made publicly available for testing
* *
* @var Controller * @var Controller
**/ */
public $controller; public $controller;
/** /**
@ -68,7 +68,7 @@ class TestDispatcher extends Dispatcher {
* *
* @param CakeEvent * @param CakeEvent
* @return void * @return void
**/ */
public function filterTest($event) { public function filterTest($event) {
$event->data['request']->params['eventName'] = $event->name(); $event->data['request']->params['eventName'] = $event->name();
} }
@ -78,7 +78,7 @@ class TestDispatcher extends Dispatcher {
* *
* @param CakeEvent * @param CakeEvent
* @return void * @return void
**/ */
public function filterTest2($event) { public function filterTest2($event) {
$event->stopPropagation(); $event->stopPropagation();
return $event->data['response']; return $event->data['response'];
@ -783,7 +783,6 @@ class DispatcherTest extends CakeTestCase {
$Dispatcher->dispatch($url, $response, array('return' => 1)); $Dispatcher->dispatch($url, $response, array('return' => 1));
} }
/** /**
* testDispatch method * testDispatch method
* *
@ -1194,7 +1193,7 @@ class DispatcherTest extends CakeTestCase {
* Tests that it is possible to attach filter classes to the dispatch cycle * Tests that it is possible to attach filter classes to the dispatch cycle
* *
* @return void * @return void
**/ */
public function testDispatcherFilterSuscriber() { public function testDispatcherFilterSuscriber() {
App::build(array( App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS), 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
@ -1234,7 +1233,7 @@ class DispatcherTest extends CakeTestCase {
* *
* @expectedException MissingDispatcherFilterException * @expectedException MissingDispatcherFilterException
* @return void * @return void
**/ */
public function testDispatcherFilterSuscriberMissing() { public function testDispatcherFilterSuscriberMissing() {
App::build(array( App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS) 'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
@ -1250,12 +1249,11 @@ class DispatcherTest extends CakeTestCase {
$dispatcher->dispatch($request, $response); $dispatcher->dispatch($request, $response);
} }
/** /**
* Tests it is possible to attach single callables as filters * Tests it is possible to attach single callables as filters
* *
* @return void * @return void
**/ */
public function testDispatcherFilterCallable() { public function testDispatcherFilterCallable() {
App::build(array( App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS) 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
@ -1513,7 +1511,6 @@ class DispatcherTest extends CakeTestCase {
$this->assertEquals('404', $response->statusCode()); $this->assertEquals('404', $response->statusCode());
} }
/** /**
* Data provider for cached actions. * Data provider for cached actions.
* *

View file

@ -1,14 +1,10 @@
<?php <?php
/** /**
* RouterTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* *
* Licensed under The Open Group Test Suite License * Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice. * Redistributions of files must retain the above copyright notice.
* *
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests * @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
@ -85,7 +81,7 @@ class AssetDispatcherTest extends CakeTestCase {
* file dispatching * file dispatching
* *
* @return void * @return void
**/ */
public function testNotModified() { public function testNotModified() {
$filter = new AssetDispatcher(); $filter = new AssetDispatcher();
Configure::write('Asset.filter', array( Configure::write('Asset.filter', array(

View file

@ -76,6 +76,29 @@ class CakeTestSuiteTest extends CakeTestCase {
$suite->addTestDirectoryRecursive($Folder->pwd()); $suite->addTestDirectoryRecursive($Folder->pwd());
$Folder->delete();
}
/**
* testAddTestDirectoryRecursiveWithNonPhp
*
* @return void
*/
public function testAddTestDirectoryRecursiveWithNonPhp() {
$this->skipIf(!is_writeable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
$Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
touch($Folder->path . DS . 'BackupTest.php~');
touch($Folder->path . DS . 'SomeNotesTest.txt');
touch($Folder->path . DS . 'NotHiddenTest.php');
$suite = $this->getMock('CakeTestSuite', array('addTestFile'));
$suite
->expects($this->exactly(1))
->method('addTestFile');
$suite->addTestDirectoryRecursive($Folder->pwd());
$Folder->delete(); $Folder->delete();
} }
} }

View file

@ -108,6 +108,7 @@ class InflectorTest extends CakeTestCase {
$this->assertEquals(Inflector::singularize('cafes'), 'cafe'); $this->assertEquals(Inflector::singularize('cafes'), 'cafe');
$this->assertEquals(Inflector::singularize('roofs'), 'roof'); $this->assertEquals(Inflector::singularize('roofs'), 'roof');
$this->assertEquals(Inflector::singularize('foes'), 'foe'); $this->assertEquals(Inflector::singularize('foes'), 'foe');
$this->assertEquals(Inflector::singularize('databases'), 'database');
$this->assertEquals(Inflector::singularize(''), ''); $this->assertEquals(Inflector::singularize(''), '');
} }

View file

@ -4801,82 +4801,10 @@ class FormHelperTest extends CakeTestCase {
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false)); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => false));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => '')); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('value' => ''));
$expected = array(
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
@ -4930,53 +4858,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result); $this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => '')); $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
$expected = array( $result = $this->Form->dateTime('Contact.date', 'DMY', '12', array('minuteInterval' => 5, 'value' => ''));
array('select' => array('name' => 'data[Contact][date][day]', 'id' => 'ContactDateDay')),
$daysRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][month]', 'id' => 'ContactDateMonth')),
$monthsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
'-',
array('select' => array('name' => 'data[Contact][date][year]', 'id' => 'ContactDateYear')),
$yearsRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
array('select' => array('name' => 'data[Contact][date][hour]', 'id' => 'ContactDateHour')),
$hoursRegex,
array('option' => array('value' => '')),
'/option',
'*/select',
':',
array('select' => array('name' => 'data[Contact][date][min]', 'id' => 'ContactDateMin')),
$minutesRegex,
array('option' => array('value' => '')),
'/option',
array('option' => array('value' => '00')),
'00',
'/option',
array('option' => array('value' => '05')),
'05',
'/option',
array('option' => array('value' => '10')),
'10',
'/option',
'*/select',
' ',
array('select' => array('name' => 'data[Contact][date][meridian]', 'id' => 'ContactDateMeridian')),
$meridianRegex,
array('option' => array('value' => '')),
'/option',
'*/select'
);
$this->assertTags($result, $expected);
$this->assertNotRegExp('/<option[^<>]+value=""[^<>]+selected="selected"[^>]*>/', $result);
$this->Form->request->data['Contact']['data'] = null; $this->Form->request->data['Contact']['data'] = null;
$result = $this->Form->dateTime('Contact.date', 'DMY', '12'); $result = $this->Form->dateTime('Contact.date', 'DMY', '12');

View file

@ -1263,33 +1263,6 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, null); $result = $this->Html->nestedList($list, null);
$expected = array(
'<ul',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ul', '<li', 'Item 2.1', '/li', '/ul',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ul',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ul',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ul',
'/li',
'/ul',
'/li',
'<li', 'Item 5',
'<ul',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ul',
'/li',
'/ul'
);
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array(), array(), 'ol'); $result = $this->Html->nestedList($list, array(), array(), 'ol');
@ -1323,33 +1296,6 @@ class HtmlHelperTest extends CakeTestCase {
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, 'ol'); $result = $this->Html->nestedList($list, 'ol');
$expected = array(
'<ol',
'<li', 'Item 1', '/li',
'<li', 'Item 2',
'<ol', '<li', 'Item 2.1', '/li', '/ol',
'/li',
'<li', 'Item 3', '/li',
'<li', 'Item 4',
'<ol',
'<li', 'Item 4.1', '/li',
'<li', 'Item 4.2', '/li',
'<li', 'Item 4.3',
'<ol',
'<li', 'Item 4.3.1', '/li',
'<li', 'Item 4.3.2', '/li',
'/ol',
'/li',
'/ol',
'/li',
'<li', 'Item 5',
'<ol',
'<li', 'Item 5.1', '/li',
'<li', 'Item 5.2', '/li',
'/ol',
'/li',
'/ol'
);
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Html->nestedList($list, array('class' => 'list')); $result = $this->Html->nestedList($list, array('class' => 'list'));

View file

@ -155,6 +155,16 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
} }
} }
/**
* See CakeTestSuiteDispatcher::date()
*
* @param string $format format to be used.
* @return string
*/
public static function date($format = 'Y-m-d H:i:s') {
return CakeTestSuiteDispatcher::date($format);
}
// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP // @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
/** /**

View file

@ -37,7 +37,9 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
list($dirs, $files) = $Folder->read(true, true, true); list($dirs, $files) = $Folder->read(true, true, true);
foreach ($files as $file) { foreach ($files as $file) {
$this->addTestFile($file); if (substr($file, -4) === '.php') {
$this->addTestFile($file);
}
} }
} }
@ -52,7 +54,9 @@ class CakeTestSuite extends PHPUnit_Framework_TestSuite {
$files = $Folder->tree(null, true, 'files'); $files = $Folder->tree(null, true, 'files');
foreach ($files as $file) { foreach ($files as $file) {
$this->addTestFile($file); if (substr($file, -4) === '.php') {
$this->addTestFile($file);
}
} }
} }

View file

@ -247,6 +247,7 @@ class CakeTestSuiteDispatcher {
restore_error_handler(); restore_error_handler();
try { try {
self::time();
$command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs); $command = new CakeTestSuiteCommand('CakeTestLoader', $commandArgs);
$result = $command->run($options); $result = $command->run($options);
} catch (MissingConnectionException $exception) { } catch (MissingConnectionException $exception) {
@ -257,4 +258,29 @@ class CakeTestSuiteDispatcher {
} }
} }
/**
* Sets a static timestamp
*
* @param boolean $reset to set new static timestamp.
* @return integer timestamp
*/
public static function time($reset = false) {
static $now;
if ($reset || !$now) {
$now = time();
}
return $now;
}
/**
* Returns formatted date string using static time
* This method is being used as formatter for created, modified and updated fields in Model::save()
*
* @param string $format format to be used.
* @return string formatted date
*/
public static function date($format) {
return date($format, self::time());
}
} }

View file

@ -53,5 +53,18 @@ class CakeTestModel extends Model {
} }
return $queryData; return $queryData;
} }
/**
* Overriding save() to set CakeTestSuiteDispatcher::date() as formatter for created, modified and updated fields
*
* @param array $data
* @param mixed $validate
* @param array $fieldList
*/
public function save($data = null, $validate = true, $fieldList = array()) {
$db = $this->getDataSource();
$db->columns['datetime']['formatter'] = 'CakeTestSuiteDispatcher::date';
return parent::save($data, $validate, $fieldList);
}
} }

View file

@ -33,12 +33,24 @@ class CakeHtmlReporter extends CakeBaseReporter {
*/ */
public function paintHeader() { public function paintHeader() {
$this->_headerSent = true; $this->_headerSent = true;
$this->sendContentType();
$this->sendNoCacheHeaders(); $this->sendNoCacheHeaders();
$this->paintDocumentStart(); $this->paintDocumentStart();
$this->paintTestMenu(); $this->paintTestMenu();
echo "<ul class='tests'>\n"; echo "<ul class='tests'>\n";
} }
/**
* Set the content-type header so it is in the correct encoding.
*
* @return void
*/
public function sendContentType() {
if (!headers_sent()) {
header('Content-Type: text/html; charset=' . Configure::read('App.encoding'));
}
}
/** /**
* Paints the document start content contained in header.php * Paints the document start content contained in header.php
* *

View file

@ -124,7 +124,7 @@ class Inflector {
'/(drive)s$/i' => '\1', '/(drive)s$/i' => '\1',
'/([^fo])ves$/i' => '\1fe', '/([^fo])ves$/i' => '\1fe',
'/(^analy)ses$/i' => '\1sis', '/(^analy)ses$/i' => '\1sis',
'/(analy|ba|diagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', '/(analy|diagno|^ba|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
'/([ti])a$/i' => '\1um', '/([ti])a$/i' => '\1um',
'/(p)eople$/i' => '\1\2erson', '/(p)eople$/i' => '\1\2erson',
'/(m)en$/i' => '\1an', '/(m)en$/i' => '\1an',

View file

@ -50,7 +50,9 @@ class HelperCollection extends ObjectCollection implements CakeEventListener {
* *
* @param string $helper The helper name to be loaded * @param string $helper The helper name to be loaded
* @return boolean wheter the helper could be loaded or not * @return boolean wheter the helper could be loaded or not
**/ * @throws MissingHelperException When a helper could not be found.
* App helpers are searched, and then plugin helpers.
*/
public function __isset($helper) { public function __isset($helper) {
if (parent::__isset($helper)) { if (parent::__isset($helper)) {
return true; return true;