Merge remote-tracking branch 'origin/2.0' into 2.0-class-loading

This commit is contained in:
Jose Lorenzo Rodriguez 2011-02-27 22:50:53 -04:30
commit ba694c45c9
21 changed files with 626 additions and 624 deletions

View file

@ -317,8 +317,8 @@ class ProjectTask extends Shell {
$path = (empty($this->configPath)) ? CONFIGS : $this->configPath;
$File = new File($path . 'core.php');
$contents = $File->read();
if (preg_match('%([/\s]*Configure::write\(\'Routing.prefixes\',[\s\'a-z,\)\(]*\);)%', $contents, $match)) {
$result = str_replace($match[0], "\t" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
if (preg_match('%(\s*[/]*Configure::write\(\'Routing.prefixes\',[\s\'a-z,\)\(]*\);)%', $contents, $match)) {
$result = str_replace($match[0], "\n" . 'Configure::write(\'Routing.prefixes\', array(\''.$name.'\'));', $contents);
if ($File->write($result)) {
Configure::write('Routing.prefixes', array($name));
return true;

View file

@ -64,7 +64,7 @@ class AclNode extends AppModel {
* @return array Node found in database
*/
public function node($ref = null) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
$db = $this->getDataSource();
$type = $this->alias;
$result = null;

View file

@ -92,7 +92,7 @@ class TranslateBehavior extends ModelBehavior {
if (empty($locale)) {
return $query;
}
$db = ConnectionManager::getDataSource($model->useDbConfig);
$db = $model->getDataSource();
$RuntimeModel = $this->translateModel($model);
if (!empty($RuntimeModel->tablePrefix)) {
$tablePrefix = $RuntimeModel->tablePrefix;
@ -100,12 +100,16 @@ class TranslateBehavior extends ModelBehavior {
$tablePrefix = $db->config['prefix'];
}
if ($tablePrefix == $db->config['prefix']) {
$tablePrefix = null;
}
if (is_string($query['fields']) && 'COUNT(*) AS '.$db->name('count') == $query['fields']) {
$query['fields'] = 'COUNT(DISTINCT('.$db->name($model->alias . '.' . $model->primaryKey) . ')) ' . $db->alias . 'count';
$query['joins'][] = array(
'type' => 'INNER',
'alias' => $RuntimeModel->alias,
'table' => $db->name($tablePrefix . $RuntimeModel->useTable),
'table' => $db->fullTableName($tablePrefix . $RuntimeModel->useTable),
'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier($RuntimeModel->alias.'.foreign_key'),
$RuntimeModel->alias.'.model' => $model->name,
@ -151,7 +155,7 @@ class TranslateBehavior extends ModelBehavior {
$query['joins'][] = array(
'type' => 'LEFT',
'alias' => 'I18n__'.$field.'__'.$_locale,
'table' => $db->name($tablePrefix . $RuntimeModel->useTable),
'table' => $db->fullTableName($tablePrefix . $RuntimeModel->useTable),
'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}__{$_locale}.foreign_key"),
'I18n__'.$field.'__'.$_locale.'.model' => $model->name,
@ -168,7 +172,7 @@ class TranslateBehavior extends ModelBehavior {
$query['joins'][] = array(
'type' => 'LEFT',
'alias' => 'I18n__'.$field,
'table' => $db->name($tablePrefix . $RuntimeModel->useTable),
'table' => $db->fullTableName($tablePrefix . $RuntimeModel->useTable),
'conditions' => array(
$model->alias . '.' . $model->primaryKey => $db->identifier("I18n__{$field}.foreign_key"),
'I18n__'.$field.'.model' => $model->name,

View file

@ -248,7 +248,7 @@ class CakeSchema extends Object {
}
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
$db = $Object->getDataSource();
if (is_object($Object) && $Object->useTable !== false) {
$fulltable = $table = $db->fullTableName($Object, false);
if ($prefix && strpos($table, $prefix) !== 0) {
@ -583,7 +583,7 @@ class CakeSchema extends Object {
* @return array Formatted columns
*/
public function __columns(&$Obj) {
$db = ConnectionManager::getDataSource($Obj->useDbConfig);
$db = $Obj->getDataSource();
$fields = $Obj->schema(true);
$columns = $props = array();

View file

@ -32,112 +32,6 @@ class DataSource extends Object {
*/
public $connected = false;
/**
* Print full query debug info?
*
* @var boolean
* @access public
*/
public $fullDebug = false;
/**
* Error description of last query
*
* @var unknown_type
* @access public
*/
public $error = null;
/**
* String to hold how many rows were affected by the last SQL operation.
*
* @var string
* @access public
*/
public $affected = null;
/**
* Number of rows in current resultset
*
* @var int
* @access public
*/
public $numRows = null;
/**
* Time the last query took
*
* @var int
* @access public
*/
public $took = null;
/**
* The starting character that this DataSource uses for quoted identifiers.
*
* @var string
* @access public
*/
public $startQuote = null;
/**
* The ending character that this DataSource uses for quoted identifiers.
*
* @var string
* @access public
*/
public $endQuote = null;
/**
* Result
*
* @var array
* @access protected
*/
protected $_result = null;
/**
* Queries count.
*
* @var int
* @access protected
*/
protected $_queriesCnt = 0;
/**
* Total duration of all queries.
*
* @var unknown_type
* @access protected
*/
protected $_queriesTime = null;
/**
* Log of queries executed by this DataSource
*
* @var unknown_type
* @access protected
*/
protected $_queriesLog = array();
/**
* Maximum number of items in query log
*
* This is to prevent query log taking over too much memory.
*
* @var int Maximum number of queries in the queries log.
* @access protected
*/
protected $_queriesLogMax = 200;
/**
* Caches serialzed results of executed queries
*
* @var array Maximum number of queries in the queries log.
* @access protected
*/
protected $_queryCache = array();
/**
* The default configuration of a specific DataSource
*
@ -162,14 +56,6 @@ class DataSource extends Object {
*/
protected $_sources = null;
/**
* A reference to the physical connection of this DataSource
*
* @var array
* @access public
*/
public $connection = null;
/**
* The DataSource configuration
*
@ -178,14 +64,6 @@ class DataSource extends Object {
*/
public $config = array();
/**
* The DataSource configuration key name
*
* @var string
* @access public
*/
public $configKeyName = null;
/**
* Whether or not this DataSource is in the middle of a transaction
*
@ -238,21 +116,7 @@ class DataSource extends Object {
Cache::write($key, $data, '_cake_model_');
}
$this->_sources = $sources;
return $sources;
}
/**
* Convenience method for DboSource::listSources(). Returns source names in lowercase.
*
* @param boolean $reset Whether or not the source list should be reset.
* @return array Array of sources available in this datasource
*/
public function sources($reset = false) {
if ($reset === true) {
$this->_sources = null;
}
return array_map('strtolower', $this->listSources());
return $this->_sources = $sources;
}
/**
@ -261,7 +125,7 @@ class DataSource extends Object {
* @param Model $model
* @return array Array of Metadata for the $model
*/
public function describe($model) {
public function describe(Model $model) {
if ($this->cacheSources === false) {
return null;
}
@ -326,7 +190,7 @@ class DataSource extends Object {
* @param array $values An Array of values to save.
* @return boolean success
*/
public function create($model, $fields = null, $values = null) {
public function create(Model $model, $fields = null, $values = null) {
return false;
}
@ -339,7 +203,7 @@ class DataSource extends Object {
* @param array $queryData An array of query data used to find the data you want
* @return mixed
*/
public function read($model, $queryData = array()) {
public function read(Model $model, $queryData = array()) {
return false;
}
@ -353,7 +217,7 @@ class DataSource extends Object {
* @param array $values Array of values to be update $fields to.
* @return boolean Success
*/
public function update($model, $fields = null, $values = null) {
public function update(Model $model, $fields = null, $values = null) {
return false;
}
@ -365,7 +229,7 @@ class DataSource extends Object {
* @param Model $model The model class having record(s) deleted
* @param mixed $id Primary key of the model
*/
public function delete($model, $id = null) {
public function delete(Model $model, $id = null) {
if ($id == null) {
$id = $model->id;
}
@ -412,20 +276,6 @@ class DataSource extends Object {
return true;
}
/**
* Returns true if the DataSource supports the given interface (method)
*
* @param string $interface The name of the interface (method)
* @return boolean True on success
*/
public function isInterfaceSupported($interface) {
static $methods = false;
if ($methods === false) {
$methods = array_map('strtolower', get_class_methods($this));
}
return in_array(strtolower($interface), $methods);
}
/**
* Sets the configuration for the DataSource.
* Merges the $config information with the _baseConfig and the existing $config property.
@ -479,7 +329,7 @@ class DataSource extends Object {
* @access public
* @todo Remove and refactor $assocData, ensure uses of the method have the param removed too.
*/
function insertQueryData($query, $data, $association, $assocData, &$model, &$linkModel, $stack) {
function insertQueryData($query, $data, $association, $assocData, Model $model, Model $linkModel, $stack) {
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
foreach ($keys as $key) {
@ -559,7 +409,7 @@ class DataSource extends Object {
* @param string $key Key name to make
* @return string Key name for model.
*/
public function resolveKey($model, $key) {
public function resolveKey(Model $model, $key) {
return $model->alias . $key;
}
@ -570,8 +420,7 @@ class DataSource extends Object {
*/
public function __destruct() {
if ($this->_transactionStarted) {
$null = null;
$this->rollback($null);
$this->rollback();
}
if ($this->connected) {
$this->close();

View file

@ -184,7 +184,7 @@ class Mysql extends DboSource {
if ($cache != null) {
return $cache;
}
$result = $this->_execute('SHOW TABLES FROM ' . $this->config['database']);
$result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
if (!$result) {
$result->closeCursor();
@ -211,21 +211,19 @@ class Mysql extends DboSource {
$this->map = array();
$numFields = $results->columnCount();
$index = 0;
$j = 0;
while ($j < $numFields) {
$column = $results->getColumnMeta($j);
if (!empty($column['native_type'])) {
$type = $column['native_type'];
} else {
while ($numFields-- > 0) {
$column = $results->getColumnMeta($index);
if (empty($column['native_type'])) {
$type = ($column['len'] == 1) ? 'boolean' : 'string';
} else {
$type = $column['native_type'];
}
if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
$this->map[$index++] = array($column['table'], $column['name'], $type);
} else {
$this->map[$index++] = array(0, $column['name'], $type);
}
$j++;
}
}
@ -240,16 +238,15 @@ class Mysql extends DboSource {
foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col];
if ($type == 'boolean' && !is_null($row[$col])) {
if ($type === 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
}
}
return $resultRow;
} else {
}
$this->_result->closeCursor();
return false;
}
}
/**
* Gets the database encoding
@ -307,7 +304,7 @@ class Mysql extends DboSource {
foreach ($cols as $column) {
$fields[$column->Field] = array(
'type' => $this->column($column->Type),
'null' => ($column->Null == 'YES' ? true : false),
'null' => ($column->Null === 'YES' ? true : false),
'default' => $column->Default,
'length' => $this->length($column->Type),
);
@ -412,7 +409,7 @@ class Mysql extends DboSource {
* @param string $enc Database encoding
*/
function setEncoding($enc) {
return $this->_execute('SET NAMES ' . $enc) != false;
return $this->_execute('SET NAMES ' . $enc) !== false;
}
/**
@ -502,7 +499,7 @@ class Mysql extends DboSource {
}
$colList = array_merge($colList, $this->_alterIndexes($curTable, $indexes));
$colList = array_merge($colList, $this->_alterTableParameters($curTable, $tableParameters));
$out .= "\t" . join(",\n\t", $colList) . ";\n\n";
$out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
}
}
return $out;
@ -519,7 +516,7 @@ class Mysql extends DboSource {
function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
if (!$table || $table === $curTable) {
$out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
}
}
@ -645,19 +642,19 @@ class Mysql extends DboSource {
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
if (strpos($col, 'char') !== false || $col === 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
if (strpos($col, 'blob') !== false || $col === 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {

File diff suppressed because it is too large Load diff

View file

@ -466,14 +466,16 @@ class Model extends Object {
$this->Behaviors = new BehaviorCollection();
if ($this->useTable !== false) {
if ($this->useTable === null) {
$this->useTable = Inflector::tableize($this->name);
}
$this->setSource($this->useTable);
if ($this->displayField == null) {
unset($this->displayField);
}
$this->table = $this->useTable;
$this->tableToModel[$this->table] = $this->alias;
} elseif ($this->table === false) {
$this->table = Inflector::tableize($this->name);
}
@ -797,7 +799,7 @@ class Model extends Object {
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if ($db->isInterfaceSupported('listSources')) {
if (method_exists($db, 'listSources')) {
$sources = $db->listSources();
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
throw new MissingTableException(array(
@ -979,7 +981,7 @@ class Model extends Object {
if (!is_array($this->_schema) || $field === true) {
$db = $this->getDataSource();
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
if ($db->isInterfaceSupported('describe') && $this->useTable !== false) {
if (method_exists($db, 'describe') && $this->useTable !== false) {
$this->_schema = $db->describe($this, $field);
} elseif ($this->useTable === false) {
$this->_schema = array();
@ -1880,7 +1882,7 @@ class Model extends Object {
if (!$filters || !$this->exists()) {
return false;
}
$db = ConnectionManager::getDataSource($this->useDbConfig);
$db = $this->getDataSource();
$this->_deleteDependent($id, $cascade);
$this->_deleteLinks($id);
@ -2071,7 +2073,7 @@ class Model extends Object {
/**
* Queries the datasource and returns a result set array.
*
* Also used to perform new-notation finds, where the first argument is type of find operation to perform
* Also used to perform notation finds, where the first argument is type of find operation to perform
* (all / first / count / neighbors / list / threaded ),
* second parameter options for finding ( indexed array, including: 'conditions', 'limit',
* 'recursive', 'page', 'fields', 'offset', 'order')
@ -2107,43 +2109,31 @@ class Model extends Object {
*
* Behaviors and find types can also define custom finder keys which are passed into find().
*
* Specifying 'fields' for new-notation 'list':
* Specifying 'fields' for notation 'list':
*
* - If no fields are specified, then 'id' is used for key and 'model->displayField' is used for value.
* - If a single field is specified, 'id' is used for key and specified field is used for value.
* - If three fields are specified, they are used (in order) for key, value and group.
* - Otherwise, first and second fields are used for key and value.
*
* @param array $conditions SQL conditions array, or type of find operation (all / first / count /
* neighbors / list / threaded)
* @param mixed $fields Either a single string of a field name, or an array of field names, or
* options for matching
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
* @param integer $recursive The number of levels deep to fetch associated records
* @param string $type Type of find operation (all / first / count / neighbors / list / threaded)
* @param array $query Option fields (conditions / fields / joins / limit / offset / order / page / group / callbacks)
* @return array Array of records
* @access public
* @link http://book.cakephp.org/view/1018/find
*/
function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
if (!is_string($conditions) || (is_string($conditions) && !array_key_exists($conditions, $this->_findMethods))) {
$type = 'first';
$query = array_merge(compact('conditions', 'fields', 'order', 'recursive'), array('limit' => 1));
} else {
list($type, $query) = array($conditions, $fields);
}
public function find($type = 'first', $query = array()) {
$this->findQueryType = $type;
$this->id = $this->getID();
$query = array_merge(
array(
'conditions' => null, 'fields' => null, 'joins' => array(), 'limit' => null,
'offset' => null, 'order' => null, 'page' => null, 'group' => null, 'callbacks' => true
'offset' => null, 'order' => null, 'page' => 1, 'group' => null, 'callbacks' => true
),
(array)$query
);
if ($type != 'all') {
if ($type !== 'all') {
if ($this->_findMethods[$type] === true) {
$query = $this->{'_find' . ucfirst($type)}('before', $query);
}
@ -2181,15 +2171,11 @@ class Model extends Object {
}
}
if (!$db = $this->getDataSource()) {
return false;
}
$results = $db->read($this, $query);
$results = $this->getDataSource()->read($this, $query);
$this->resetAssociations();
if ($query['callbacks'] === true || $query['callbacks'] === 'after') {
$results = $this->__filterResults($results);
$results = $this->_filterResults($results);
}
$this->findQueryType = null;
@ -2210,14 +2196,13 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return array
* @access protected
* @see Model::find()
*/
function _findFirst($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findFirst($state, $query, $results = array()) {
if ($state === 'before') {
$query['limit'] = 1;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (empty($results[0])) {
return false;
}
@ -2232,11 +2217,10 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return int The number of records found, or false
* @access protected
* @see Model::find()
*/
function _findCount($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findCount($state, $query, $results = array()) {
if ($state === 'before') {
$db = $this->getDataSource();
if (empty($query['fields'])) {
$query['fields'] = $db->calculate($this, 'count');
@ -2247,7 +2231,7 @@ class Model extends Object {
}
$query['order'] = false;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (isset($results[0][0]['count'])) {
return intval($results[0][0]['count']);
} elseif (isset($results[0][$this->alias]['count'])) {
@ -2264,11 +2248,10 @@ class Model extends Object {
* @param array $query
* @param array $data
* @return array Key/value pairs of primary keys/display field values of all records found
* @access protected
* @see Model::find()
*/
function _findList($state, $query, $results = array()) {
if ($state == 'before') {
protected function _findList($state, $query, $results = array()) {
if ($state === 'before') {
if (empty($query['fields'])) {
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", "{$this->alias}.{$this->displayField}");
$list = array("{n}.{$this->alias}.{$this->primaryKey}", "{n}.{$this->alias}.{$this->displayField}", null);
@ -2277,14 +2260,14 @@ class Model extends Object {
$query['fields'] = String::tokenize($query['fields']);
}
if (count($query['fields']) == 1) {
if (count($query['fields']) === 1) {
if (strpos($query['fields'][0], '.') === false) {
$query['fields'][0] = $this->alias . '.' . $query['fields'][0];
}
$list = array("{n}.{$this->alias}.{$this->primaryKey}", '{n}.' . $query['fields'][0], null);
$query['fields'] = array("{$this->alias}.{$this->primaryKey}", $query['fields'][0]);
} elseif (count($query['fields']) == 3) {
} elseif (count($query['fields']) === 3) {
for ($i = 0; $i < 3; $i++) {
if (strpos($query['fields'][$i], '.') === false) {
$query['fields'][$i] = $this->alias . '.' . $query['fields'][$i];
@ -2307,7 +2290,7 @@ class Model extends Object {
}
list($query['list']['keyPath'], $query['list']['valuePath'], $query['list']['groupPath']) = $list;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
if (empty($results)) {
return array();
}
@ -2326,7 +2309,7 @@ class Model extends Object {
* @return array
*/
protected function _findNeighbors($state, $query, $results = array()) {
if ($state == 'before') {
if ($state === 'before') {
extract($query);
$conditions = (array)$conditions;
if (isset($field) && isset($value)) {
@ -2343,7 +2326,7 @@ class Model extends Object {
$query['field'] = $field;
$query['value'] = $value;
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
extract($query);
unset($query['conditions'][$field . ' <']);
$return = array();
@ -2362,9 +2345,9 @@ class Model extends Object {
if (!array_key_exists('prev', $return)) {
$return['prev'] = $return2[0];
}
if (count($return2) == 2) {
if (count($return2) === 2) {
$return['next'] = $return2[1];
} elseif (count($return2) == 1 && !$return['prev']) {
} elseif (count($return2) === 1 && !$return['prev']) {
$return['next'] = $return2[0];
} else {
$return['next'] = null;
@ -2383,9 +2366,9 @@ class Model extends Object {
* @return array Threaded results
*/
protected function _findThreaded($state, $query, $results = array()) {
if ($state == 'before') {
if ($state === 'before') {
return $query;
} elseif ($state == 'after') {
} elseif ($state === 'after') {
$return = $idMap = array();
$ids = Set::extract($results, '{n}.' . $this->alias . '.' . $this->primaryKey);
@ -2425,9 +2408,8 @@ class Model extends Object {
* @param array Results to filter
* @param boolean $primary If this is the primary model results (results from model where the find operation was performed)
* @return array Set of filtered results
* @access private
*/
function __filterResults($results, $primary = true) {
protected function _filterResults($results, $primary = true) {
$return = $this->Behaviors->trigger(
'afterFind',
array(&$this, $results, $primary),

View file

@ -203,7 +203,7 @@ class CakeRequest implements ArrayAccess {
$base = $this->base;
if (strpos($uri, $base) === 0) {
if (strlen($base) > 0 && strpos($uri, $base) === 0) {
$uri = substr($uri, strlen($base));
}
if (strpos($uri, '?') !== false) {

View file

@ -89,13 +89,9 @@ class MediaView extends View {
* @return mixed
*/
function render() {
$name = $download = $extension = $id = $modified = $path = $size = $cache = $mimeType = $compress = null;
$name = $download = $extension = $id = $modified = $path = $cache = $mimeType = $compress = null;
extract($this->viewVars, EXTR_OVERWRITE);
if ($size) {
$id = $id . '_' . $size;
}
if (is_dir($path)) {
$path = $path . $id;
} else {
@ -109,15 +105,12 @@ class MediaView extends View {
throw new NotFoundException('The requested file was not found');
}
if (is_null($name)) {
$name = $id;
}
if (is_array($mimeType)) {
$this->response->type($mimeType);
}
if (isset($extension) && $this->response->type($extension) && $this->_isActive()) {
if (isset($extension) && $this->_isActive()) {
$extension = strtolower($extension);
$chunkSize = 8192;
$buffer = '';
$fileSize = @filesize($path);
@ -131,6 +124,9 @@ class MediaView extends View {
} else {
$modified = time();
}
if ($this->response->type($extension) === false) {
$download = true;
}
if ($cache) {
$this->response->cache($modified, $cache);
@ -155,7 +151,10 @@ class MediaView extends View {
if (!empty($contentType)) {
$this->response->type($contentType);
}
$this->response->download($name . '.' . $extension);
if (is_null($name)) {
$name = $id;
}
$this->response->download($name);
$this->response->header(array('Accept-Ranges' => 'bytes'));
$httpRange = env('HTTP_RANGE');
@ -176,7 +175,6 @@ class MediaView extends View {
$this->response->header('Content-Length', $fileSize);
}
} else {
$this->response->type($extension);
$this->response->header(array(
'Content-Length' => $fileSize
));

View file

@ -26,7 +26,7 @@ if ($noLogs):
$logs = array();
foreach ($sources as $source):
$db =& ConnectionManager::getDataSource($source);
if (!$db->isInterfaceSupported('getLog')):
if (!method_exists($db, 'getLog')):
continue;
endif;
$logs[$source] = $db->getLog();

View file

@ -98,7 +98,7 @@ TEXT;
if (php_sapi_name() == 'cli') {
$template = $text;
}
if ($showHtml === null) {
if ($showHtml === null && $template !== $text) {
$showHtml = true;
}
$var = print_r($var, true);

View file

@ -684,7 +684,7 @@ class BasicsTest extends CakeTestCase {
$this->assertPattern($pattern, $result);
ob_start();
debug('<div>this-is-a-test</div>');
debug('<div>this-is-a-test</div>', true);
$result = ob_get_clean();
$pattern = '/(.+?tests(\/|\\\)cases(\/|\\\)basics\.test\.php|';
$pattern .= preg_quote(substr(__FILE__, 1), '/') . ')';
@ -762,7 +762,7 @@ class BasicsTest extends CakeTestCase {
* @return void
*/
public function testStripslashesDeepSybase() {
$this->skipUnless(ini_get('magic_quotes_sybase') === '1', '%s magic_quotes_sybase is off');
$this->skipUnless(ini_get('magic_quotes_sybase') === '1', 'magic_quotes_sybase is off');
$this->assertEqual(stripslashes_deep("tes\'t"), "tes\'t");

View file

@ -1273,6 +1273,31 @@ class CakeRequestTestCase extends CakeTestCase {
'webroot' => '/site/',
),
),
array(
'Apache - w/rewrite, document root set to webroot, request root, no PATH_INFO/REQUEST_URI',
array(
'App' => array(
'base' => false,
'baseUrl' => false,
'dir' => 'app',
'webroot' => 'webroot'
),
'SERVER' => array(
'SERVER_NAME' => 'localhost',
'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
'SCRIPT_NAME' => '/index.php',
'PHP_SELF' => '/index.php',
'PATH_INFO' => null,
'REQUEST_URI' => null,
),
),
array(
'url' => '',
'base' => '',
'webroot' => '/',
),
),
);
}

View file

@ -290,7 +290,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->save(array($modelClass => array('name' => 'testAddOrphan', $parentField => null)));
$result = $this->Tree->find(null, array('name', $parentField), $modelClass . '.' . $leftField . ' desc');
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
$expected = array($modelClass => array('name' => 'testAddOrphan', $parentField => null));
$this->assertEqual($result, $expected);
@ -309,7 +309,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$initialCount = $this->Tree->find('count');
$this->Tree->create();
@ -369,7 +369,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->save(array('name' => 'testAddNotIndexed', $parentField => null));
$result = $this->Tree->find(null, array('name', $parentField), $modelClass . '.' . $leftField . ' desc');
$result = $this->Tree->find('first', array('fields' => array('name', $parentField), 'order' => $modelClass . '.' . $leftField . ' desc'));
$expected = array($modelClass => array('name' => 'testAddNotIndexed', $parentField => null));
$this->assertEqual($result, $expected);
@ -389,10 +389,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
$direct = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -416,10 +416,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->whitelist = array($parentField, 'name', 'description');
$this->Tree->saveField($parentField, $parent_id);
@ -463,10 +463,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1.1'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
$parent_id = $parent[$modelClass]['id'];
$data= $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
@ -492,10 +492,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1.2'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
$parent_id = $parent[$modelClass]['id'];
$data= $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data= $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
@ -521,10 +521,10 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$expects = $this->Tree->find('all');
$before = $this->Tree->read(null, $data[$modelClass]['id']);
@ -608,7 +608,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->moveUp($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -630,7 +630,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveUp($data[$modelClass]['id']);
@ -653,7 +653,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveUp($data[$modelClass]['id'], 2);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -684,7 +684,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveUp($data[$modelClass]['id'], true);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -715,7 +715,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -737,7 +737,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2')));
$this->Tree->moveDown($data[$modelClass]['id']);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -759,7 +759,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveDown($data[$modelClass]['id'], true);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -790,7 +790,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->moveDown($data[$modelClass]['id'], 2);
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -821,7 +821,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 10);
$data = $this->Tree->find(array($modelClass . '.name' => '1.5'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.5')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->saveField('name', 'renamed');
$parent = $this->Tree->findByName('1. Root', array('id'));
@ -851,7 +851,7 @@ class NumberTreeTest extends CakeTestCase {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->initialize(1, 1);
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->save(array($parentField => null));
@ -1079,7 +1079,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id= $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -1110,7 +1110,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->childCount(null, true);
@ -1131,7 +1131,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
$this->Tree->id= $data[$modelClass]['id'];
$result = $this->Tree->getParentNode(null, array('name'));
@ -1150,7 +1150,7 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.2'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1.2.2')));
$this->Tree->id= $data[$modelClass]['id'];
$result = $this->Tree->getPath(null, array('name'));
@ -1173,7 +1173,7 @@ class NumberTreeTest extends CakeTestCase {
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id= $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
@ -1205,13 +1205,13 @@ class NumberTreeTest extends CakeTestCase {
$this->Tree->initialize(3, 3);
$nodes = $this->Tree->find('list', array('order' => $leftField));
$data = $this->Tree->find(array($modelClass . '.name' => '1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$data = $this->Tree->find(array($modelClass . '.name' => '1.2.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.2.1')));
$this->Tree->moveDown($data[$modelClass]['id']);
$data = $this->Tree->find(array($modelClass . '.name' => '1.3.2.2'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.3.2.2')));
$this->Tree->moveDown($data[$modelClass]['id']);
$unsortedNodes = $this->Tree->find('list', array('order' => $leftField));
@ -1678,10 +1678,10 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->saveField($parentField, $parent_id);
$direct = $this->Tree->children($parent_id, true, array('name', $leftField, $rightField));
@ -1704,10 +1704,10 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->initialize(2, 2);
$this->Tree->id = null;
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$parent = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$parent_id = $parent[$modelClass]['id'];
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
$data = $this->Tree->find('first', array('fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1.1')));
$this->Tree->id = $data[$modelClass]['id'];
$this->Tree->whitelist = array($parentField, 'name', 'description');
$this->Tree->saveField($parentField, $parent_id);
@ -1796,7 +1796,7 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree = new $modelClass();
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
@ -1827,7 +1827,7 @@ class UuidTreeTest extends CakeTestCase {
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$data = $this->Tree->find('first', array('conditions' => array($modelClass . '.name' => '1. Root')));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));

View file

@ -591,22 +591,33 @@ class CakeSchemaTest extends CakeTestCase {
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
$this->assertTrue(empty($read['tables']));
$SchemaPost = ClassRegistry::init('SchemaPost');
$SchemaPost->table = 'sts';
$SchemaPost->tablePrefix = 'po';
$read = $this->Schema->read(array(
'connection' => 'test',
'name' => 'TestApp',
'models' => array('SchemaPost')
));
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s');
$read = $this->Schema->read(array(
'connection' => 'test',
'name' => 'TestApp',
'models' => array('SchemaComment', 'SchemaTag', 'SchemaPost')
));
$this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing %s');
$this->assertFalse(isset($read['tables']['missing']['posts_tags']), 'Join table marked as missing');
}
/**
* testSchemaReadWithOddTablePrefix method
*
* @access public
* @return void
*/
function testSchemaReadWithOddTablePrefix() {
$config = ConnectionManager::getDataSource('test')->config;
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
$SchemaPost = ClassRegistry::init('SchemaPost');
$SchemaPost->tablePrefix = 'po';
$SchemaPost->useTable = 'sts';
$read = $this->Schema->read(array(
'connection' => 'test',
'name' => 'TestApp',
'models' => array('SchemaPost')
));
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix');
}
/**
@ -615,6 +626,9 @@ class CakeSchemaTest extends CakeTestCase {
* @return void
*/
function testSchemaReadWithTablePrefix() {
$config = ConnectionManager::getDataSource('test')->config;
$this->skipIf(!empty($config['prefix']), 'This test can not be executed with datasource prefix set');
$model = new SchemaPrefixAuthUser();
$Schema = new CakeSchema();

View file

@ -458,6 +458,7 @@ class DboMysqlTest extends CakeTestCase {
*/
function testAlterSchemaIndexes() {
$this->Dbo->cacheSources = $this->Dbo->testing = false;
$table = $this->Dbo->fullTableName('altertest');
$schema1 = new CakeSchema(array(
'name' => 'AlterTest1',
@ -494,7 +495,7 @@ class DboMysqlTest extends CakeTestCase {
)));
$result = $this->Dbo->alterSchema($schema2->compare($schema1));
$this->assertContains('ALTER TABLE `altertest`', $result);
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('ADD KEY name_idx (`name`),', $result);
$this->assertContains('ADD KEY group_idx (`group1`),', $result);
$this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result);
@ -521,7 +522,7 @@ class DboMysqlTest extends CakeTestCase {
)));
$result = $this->Dbo->alterSchema($schema3->compare($schema2));
$this->assertContains('ALTER TABLE `altertest`', $result);
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP PRIMARY KEY,', $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
@ -540,7 +541,7 @@ class DboMysqlTest extends CakeTestCase {
// Drop the indexes
$result = $this->Dbo->alterSchema($schema1->compare($schema3));
$this->assertContains('ALTER TABLE `altertest`', $result);
$this->assertContains("ALTER TABLE $table", $result);
$this->assertContains('DROP KEY name_idx,', $result);
$this->assertContains('DROP KEY group_idx,', $result);
$this->assertContains('DROP KEY compound_idx,', $result);
@ -611,7 +612,7 @@ class DboMysqlTest extends CakeTestCase {
$this->assertContains('COLLATE=utf8_general_ci', $result);
$this->Dbo->rawQuery($result);
$result = $this->Dbo->listDetailedSources('altertest');
$result = $this->Dbo->listDetailedSources($this->Dbo->fullTableName('altertest', false));
$this->assertEqual($result['Collation'], 'utf8_general_ci');
$this->assertEqual($result['Engine'], 'InnoDB');
$this->assertEqual($result['charset'], 'utf8');
@ -662,18 +663,20 @@ class DboMysqlTest extends CakeTestCase {
function testReadTableParameters() {
$this->Dbo->cacheSources = $this->Dbo->testing = false;
$tableName = 'tinyint_' . uniqid();
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
$result = $this->Dbo->readTableParameters($tableName);
$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
$table = $this->Dbo->fullTableName($tableName);
$this->Dbo->rawQuery('CREATE TABLE ' . $table . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;');
$result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false));
$this->Dbo->rawQuery('DROP TABLE ' . $table);
$expected = array(
'charset' => 'utf8',
'collate' => 'utf8_unicode_ci',
'engine' => 'InnoDB');
$this->assertEqual($result, $expected);
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
$result = $this->Dbo->readTableParameters($tableName);
$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
$table = $this->Dbo->fullTableName($tableName);
$this->Dbo->rawQuery('CREATE TABLE ' . $table . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;');
$result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false));
$this->Dbo->rawQuery('DROP TABLE ' . $table);
$expected = array(
'charset' => 'cp1250',
'collate' => 'cp1250_general_ci',
@ -762,7 +765,7 @@ class DboMysqlTest extends CakeTestCase {
$this->Dbo->execute($this->Dbo->createSchema($schema));
$model = new CakeTestModel(array('table' => 'testdescribes', 'name' => 'Testdescribes'));
$result = $this->Dbo->describe($model);
$result = $model->getDataSource()->describe($model);
$this->Dbo->execute($this->Dbo->dropSchema($schema));
$this->assertEqual($result['stringy']['collate'], 'cp1250_general_ci');
@ -779,7 +782,7 @@ class DboMysqlTest extends CakeTestCase {
$queryResult = $this->getMock('PDOStatement');
$db->expects($this->once())
->method('_execute')
->with('SHOW TABLES FROM cake')
->with('SHOW TABLES FROM `cake`')
->will($this->returnValue($queryResult));
$queryResult->expects($this->at(0))
->method('fetch')
@ -807,7 +810,8 @@ class DboMysqlTest extends CakeTestCase {
$this->assertEquals(array(), $result, 'Should be empty when table does not exist.');
$result = $this->Dbo->listDetailedSources();
$this->assertTrue(isset($result['apples']), 'Key should exist');
$tableName = $this->Dbo->fullTableName('apples', false);
$this->assertTrue(isset($result[$tableName]), 'Key should exist');
}
/**
@ -1633,8 +1637,9 @@ class DboMysqlTest extends CakeTestCase {
$params = $this->_prepareAssociationQuery($this->Model, $queryData, $binding);
$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
$assocTable = $this->Dbo->fullTableName($this->Model->TestModel4TestModel7, false);
$this->assertPattern('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`' . $this->Dbo->fullTableName('test_model4_test_model7', false) . '`/', $result);
$this->assertPattern('/\s+FROM\s+`test_model7` AS `TestModel7`\s+JOIN\s+`' . $assocTable . '`/', $result);
$this->assertPattern('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+AND/', $result);
$this->assertPattern('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)/', $result);
$this->assertPattern('/WHERE\s+(?:\()?1 = 1(?:\))?\s*$/', $result);
@ -2869,14 +2874,15 @@ class DboMysqlTest extends CakeTestCase {
* @return void
*/
function testVirtualFields() {
$this->loadFixtures('Article', 'Comment');
$this->loadFixtures('Article', 'Comment', 'Tag');
$this->Dbo->virtualFieldSeparator = '__';
$Article = ClassRegistry::init('Article');
$commentsTable = $this->Dbo->fullTableName('comments', false);
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') .
' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id'
'comment_count' => 'SELECT COUNT(*) FROM ' . $commentsTable .
' WHERE Article.id = ' . $commentsTable . '.article_id'
);
$result = $this->Dbo->fields($Article);
$expected = array(
@ -2889,8 +2895,9 @@ class DboMysqlTest extends CakeTestCase {
'`Article`.`updated`',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
"(SELECT COUNT(*) FROM $commentsTable WHERE `Article`.`id` = `$commentsTable`.`article_id`) AS `Article__comment_count`"
);
$this->assertEqual($expected, $result);
$result = $this->Dbo->fields($Article, null, array('this_moment', 'title'));
@ -2919,7 +2926,7 @@ class DboMysqlTest extends CakeTestCase {
'`Article`.*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
"(SELECT COUNT(*) FROM $commentsTable WHERE `Article`.`id` = `$commentsTable`.`article_id`) AS `Article__comment_count`"
);
$this->assertEqual($expected, $result);
@ -2928,7 +2935,7 @@ class DboMysqlTest extends CakeTestCase {
'*',
'(NOW()) AS `Article__this_moment`',
'(1 + 1) AS `Article__two`',
'(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `Article__comment_count`'
"(SELECT COUNT(*) FROM $commentsTable WHERE `Article`.`id` = `$commentsTable`.`article_id`) AS `Article__comment_count`"
);
$this->assertEqual($expected, $result);
}
@ -2940,11 +2947,13 @@ class DboMysqlTest extends CakeTestCase {
*/
function testVirtualFieldsInConditions() {
$Article = ClassRegistry::init('Article');
$commentsTable = $this->Dbo->fullTableName('comments', false);
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') .
' WHERE Article.id = ' . $this->Dbo->fullTableName('comments') . '.article_id'
'comment_count' => 'SELECT COUNT(*) FROM ' . $commentsTable .
' WHERE Article.id = ' . $commentsTable . '.article_id'
);
$conditions = array('two' => 2);
$result = $this->Dbo->conditions($conditions, true, false, $Article);
@ -2957,7 +2966,7 @@ class DboMysqlTest extends CakeTestCase {
$this->assertEqual($expected, $result);
$conditions = array('comment_count >' => 5);
$expected = '(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) > 5';
$expected = "(SELECT COUNT(*) FROM $commentsTable WHERE `Article`.`id` = `$commentsTable`.`article_id`) > 5";
$result = $this->Dbo->conditions($conditions, true, false, $Article);
$this->assertEqual($expected, $result);
@ -2973,7 +2982,7 @@ class DboMysqlTest extends CakeTestCase {
* @return void
*/
function testConditionsWithComplexVirtualFields() {
$Article = ClassRegistry::init('Article');
$Article = ClassRegistry::init('Article', 'Comment', 'Tag');
$Article->virtualFields = array(
'distance' => 'ACOS(SIN(20 * PI() / 180)
* SIN(Article.latitude * PI() / 180)
@ -2997,11 +3006,12 @@ class DboMysqlTest extends CakeTestCase {
*/
function testVirtualFieldsInCalculate() {
$Article = ClassRegistry::init('Article');
$commentsTable = $this->Dbo->fullTableName('comments', false);
$Article->virtualFields = array(
'this_moment' => 'NOW()',
'two' => '1 + 1',
'comment_count' => 'SELECT COUNT(*) FROM ' . $this->Dbo->fullTableName('comments') .
' WHERE Article.id = ' . $this->Dbo->fullTableName('comments'). '.article_id'
'comment_count' => 'SELECT COUNT(*) FROM ' . $commentsTable .
' WHERE Article.id = ' . $commentsTable . '.article_id'
);
$result = $this->Dbo->calculate($Article, 'count', array('this_moment'));
@ -3009,7 +3019,7 @@ class DboMysqlTest extends CakeTestCase {
$this->assertEqual($expected, $result);
$result = $this->Dbo->calculate($Article, 'max', array('comment_count'));
$expected = 'MAX(SELECT COUNT(*) FROM comments WHERE `Article`.`id` = `comments`.`article_id`) AS `comment_count`';
$expected = "MAX(SELECT COUNT(*) FROM $commentsTable WHERE `Article`.`id` = `$commentsTable`.`article_id`) AS `comment_count`";
$this->assertEqual($expected, $result);
}

View file

@ -365,8 +365,8 @@ class AclNodeTest extends CakeTestCase {
* @return void
*/
function testNodeAliasParenting() {
$Aco = new DbAcoTest();
$db = ConnectionManager::getDataSource('test');
$Aco = ClassRegistry::init('DbAcoTest');
$db = $Aco->getDataSource();
$db->truncate($Aco);
$Aco->create(array('model' => null, 'foreign_key' => null, 'parent_id' => null, 'alias' => 'Application'));

View file

@ -3496,19 +3496,16 @@ class ModelReadTest extends BaseModelTest {
* @return void
*/
public function testFindNeighbors() {
$this->loadFixtures('User', 'Article');
$this->loadFixtures('User', 'Article', 'Comment', 'Tag', 'ArticlesTag', 'Attachment');
$TestModel = new Article();
$TestModel->id = 1;
$result = $TestModel->find('neighbors', array('fields' => array('id')));
$expected = array(
'prev' => null,
'next' => array(
'Article' => array('id' => 2),
'Comment' => array(),
'Tag' => array()
));
$this->assertEqual($result, $expected);
$this->assertNull($result['prev']);
$this->assertEqual($result['next']['Article'], array('id' => 2));
$this->assertEqual(count($result['next']['Comment']), 2);
$this->assertEqual(count($result['next']['Tag']), 2);
$TestModel->id = 2;
$TestModel->recursive = 0;
@ -3530,15 +3527,11 @@ class ModelReadTest extends BaseModelTest {
$TestModel->id = 3;
$TestModel->recursive = 1;
$result = $TestModel->find('neighbors', array('fields' => array('id')));
$expected = array(
'prev' => array(
'Article' => array('id' => 2),
'Comment' => array(),
'Tag' => array()
),
'next' => null
);
$this->assertEqual($result, $expected);
$this->assertNull($result['next']);
$this->assertEqual($result['prev']['Article'], array('id' => 2));
$this->assertEqual(count($result['prev']['Comment']), 2);
$this->assertEqual(count($result['prev']['Tag']), 2);
$TestModel->id = 1;
$result = $TestModel->find('neighbors', array('recursive' => -1));
@ -5094,7 +5087,7 @@ class ModelReadTest extends BaseModelTest {
$this->loadFixtures('Portfolio', 'Item', 'ItemsPortfolio', 'Syfile', 'Image');
$Portfolio = new Portfolio();
$result = $Portfolio->find(array('id' => 2), null, null, 3);
$result = $Portfolio->find('first', array('conditions' => array('id' => 2), 'recursive' => 3));
$expected = array(
'Portfolio' => array(
'id' => 2,
@ -5732,7 +5725,7 @@ class ModelReadTest extends BaseModelTest {
$fullDebug = $this->db->fullDebug;
$this->db->fullDebug = true;
$TestModel->recursive = 6;
$result = $TestModel->find(array('CategoryThread.id' => 7));
$result = $TestModel->find('first', array('conditions' => array('CategoryThread.id' => 7)));
$expected = array(
'CategoryThread' => array(
@ -6014,12 +6007,12 @@ class ModelReadTest extends BaseModelTest {
function testConditionalNumerics() {
$this->loadFixtures('NumericArticle');
$NumericArticle = new NumericArticle();
$data = array('title' => '12345abcde');
$result = $NumericArticle->find($data);
$data = array('conditions' => array('title' => '12345abcde'));
$result = $NumericArticle->find('first', $data);
$this->assertTrue(!empty($result));
$data = array('title' => '12345');
$result = $NumericArticle->find($data);
$data = array('conditions' => array('title' => '12345'));
$result = $NumericArticle->find('first', $data);
$this->assertTrue(empty($result));
}

View file

@ -105,7 +105,7 @@ class ModelWriteTest extends BaseModelTest {
$result = $Article->save($data);
$this->assertFalse(empty($result));
$testResult = $Article->find(array('Article.title' => 'Test Title'));
$testResult = $Article->find('first', array('conditions' => array('Article.title' => 'Test Title')));
$this->assertEqual($testResult['Article']['title'], $data['Article']['title']);
$this->assertEqual($testResult['Article']['created'], '2008-01-01 00:00:00');
@ -1019,17 +1019,17 @@ class ModelWriteTest extends BaseModelTest {
$Article = new Article();
$result = $Article->save(Xml::build('<article title="test xml" user_id="5" />'));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'test xml'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'test xml')));
$this->assertFalse(empty($results));
$result = $Article->save(Xml::build('<article><title>testing</title><user_id>6</user_id></article>'));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'testing'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'testing')));
$this->assertFalse(empty($results));
$result = $Article->save(Xml::build('<article><title>testing with DOMDocument</title><user_id>7</user_id></article>', array('return' => 'domdocument')));
$this->assertFalse(empty($result));
$results = $Article->find(array('Article.title' => 'testing with DOMDocument'));
$results = $Article->find('first', array('conditions' => array('Article.title' => 'testing with DOMDocument')));
$this->assertFalse(empty($results));
}
@ -1111,7 +1111,7 @@ class ModelWriteTest extends BaseModelTest {
$this->assertFalse(empty($result));
$TestModel->unbindModel(array('belongsTo' => array('User'), 'hasMany' => array('Comment')));
$result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1145,7 +1145,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1180,7 +1180,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id' => 2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1227,7 +1227,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1250,7 +1250,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1290,7 +1290,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1330,7 +1330,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1372,7 +1372,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -1414,7 +1414,7 @@ class ModelWriteTest extends BaseModelTest {
'belongsTo' => array('User'),
'hasMany' => array('Comment')
));
$result = $TestModel->find(array('Article.id'=>2), array('id', 'user_id', 'title', 'body'));
$result = $TestModel->find('first', array('fields' => array('id', 'user_id', 'title', 'body'), 'conditions' => array('Article.id' => 2)));
$expected = array(
'Article' => array(
'id' => '2',
@ -2987,10 +2987,6 @@ class ModelWriteTest extends BaseModelTest {
$db = ConnectionManager::create('mock_transaction', array(
'datasource' => 'MockTransactionDboSource',
));
$db->expects($this->at(2))
->method('isInterfaceSupported')
->with('describe')
->will($this->returnValue(true));
$db->expects($this->once())
->method('describe')
@ -3026,8 +3022,6 @@ class ModelWriteTest extends BaseModelTest {
$db->columns = $testDb->columns;
$db->expects($this->once())->method('rollback');
$db->expects($this->any())->method('isInterfaceSupported')
->will($this->returnValue(true));
$db->expects($this->any())->method('describe')
->will($this->returnValue(array(
'id' => array('type' => 'integer'),

View file

@ -80,7 +80,7 @@ class MediaViewTest extends CakeTestCase {
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(2))
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('css')
->will($this->returnArgument(0));
@ -94,7 +94,7 @@ class MediaViewTest extends CakeTestCase {
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->at(3))
$this->MediaView->response->expects($this->at(2))
->method('header')
->with(array(
'Content-Length' => 31
@ -110,6 +110,61 @@ class MediaViewTest extends CakeTestCase {
$this->assertTrue($result !== false);
}
/**
* testRenderWithUnknownFileType method
*
* @access public
* @return void
*/
function testRenderWithUnknownFileType() {
$this->MediaView->viewVars = array(
'path' => TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'config' . DS,
'id' => 'no_section.ini',
'extension' => 'ini',
);
$this->MediaView->expects($this->exactly(2))
->method('_isActive')
->will($this->returnValue(true));
$this->MediaView->response->expects($this->exactly(1))
->method('type')
->with('ini')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->at(1))
->method('header')
->with(array(
'Date' => gmdate('D, d M Y H:i:s', time()) . ' GMT',
'Expires' => '0',
'Cache-Control' => 'private, must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'no-cache'
));
$this->MediaView->response->expects($this->once())
->method('download')
->with('no_section.ini');
$this->MediaView->response->expects($this->at(3))
->method('header')
->with(array(
'Accept-Ranges' => 'bytes'
));
$this->MediaView->response->expects($this->at(4))
->method('header')
->with('Content-Length', 35);
$this->MediaView->response->expects($this->once())->method('send');
$this->MediaView->expects($this->once())->method('_clearBuffer');
$this->MediaView->expects($this->once())->method('_flushBuffer');
ob_start();
$result = $this->MediaView->render();
$output = ob_get_clean();
$this->assertEqual("some_key = some_value\nbool_key = 1\n", $output);
$this->assertTrue($result !== false);
}
/**
* testConnectionAborted method
*
@ -127,10 +182,8 @@ class MediaViewTest extends CakeTestCase {
->method('_isActive')
->will($this->returnValue(false));
$this->MediaView->response->expects($this->once())
->method('type')
->with('css')
->will($this->returnArgument(0));
$this->MediaView->response->expects($this->never())
->method('type');
$result = $this->MediaView->render();
$this->assertFalse($result);