mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge branch 'local/svn/1.2.x.x' into 1.2
This commit is contained in:
commit
8f8251adf4
16 changed files with 406 additions and 132 deletions
|
@ -852,9 +852,16 @@ class HttpSocket extends CakeSocket {
|
|||
|
||||
$cookies = array();
|
||||
foreach ((array)$header['Set-Cookie'] as $cookie) {
|
||||
$parts = preg_split('/(?<![^;]");[ \t]*/', $cookie);
|
||||
if (strpos($cookie, '";"') !== false) {
|
||||
$cookie = str_replace('";"', "{__cookie_replace__}", $cookie);
|
||||
$parts = str_replace("{__cookie_replace__}", '";"', preg_split('/\;/', $cookie));
|
||||
} else {
|
||||
$parts = preg_split('/\;[ \t]*/', $cookie);
|
||||
}
|
||||
|
||||
list($name, $value) = explode('=', array_shift($parts), 2);
|
||||
$cookies[$name] = compact('value');
|
||||
|
||||
foreach ($parts as $part) {
|
||||
if (strpos($part, '=') !== false) {
|
||||
list($key, $value) = explode('=', $part);
|
||||
|
|
|
@ -48,7 +48,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
var $runtime = array();
|
||||
/**
|
||||
* Initiate behavior for the model using specified settings.
|
||||
*
|
||||
*
|
||||
* Available settings:
|
||||
*
|
||||
* - recursive: (boolean, optional) set to true to allow containable to automatically
|
||||
|
@ -313,7 +313,7 @@ class ContainableBehavior extends ModelBehavior {
|
|||
$option = 'conditions';
|
||||
$val = $Model->{$name}->alias.'.'.$key;
|
||||
}
|
||||
$children[$option] = isset($children[$option]) ? array_merge((array) $children[$option], (array) $val) : $val;
|
||||
$children[$option] = is_array($val) ? $val : array($val);
|
||||
$newChildren = null;
|
||||
if (!empty($name) && !empty($children[$key])) {
|
||||
$newChildren = $children[$key];
|
||||
|
|
|
@ -211,9 +211,10 @@ class DboMssql extends DboSource {
|
|||
return $cache;
|
||||
}
|
||||
|
||||
$fields = false;
|
||||
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $this->fullTableName($model, false) . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $this->fullTableName($model, false) . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $this->fullTableName($model, false) . "'", false);
|
||||
$table = $this->fullTableName($model, false);
|
||||
$cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table . "'", false);
|
||||
|
||||
$fields = false;
|
||||
foreach ($cols as $column) {
|
||||
$field = $column[0]['Field'];
|
||||
$fields[$field] = array(
|
||||
|
@ -295,7 +296,8 @@ class DboMssql extends DboSource {
|
|||
$fields = parent::fields($model, $alias, $fields, false);
|
||||
$count = count($fields);
|
||||
|
||||
if ($count >= 1 && $fields[0] != '*' && strpos($fields[0], 'COUNT(*)') === false) {
|
||||
if ($count >= 1 && strpos($fields[0], 'COUNT(*)') === false) {
|
||||
$result = array();
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
$prepend = '';
|
||||
|
||||
|
@ -306,6 +308,19 @@ class DboMssql extends DboSource {
|
|||
$fieldAlias = count($this->__fieldMappings);
|
||||
|
||||
if (!preg_match('/\s+AS\s+/i', $fields[$i])) {
|
||||
if (substr($fields[$i], -1) == '*') {
|
||||
if (strpos($fields[$i], '.') !== false && $fields[$i] != $alias . '.*') {
|
||||
$build = explode('.', $fields[$i]);
|
||||
$AssociatedModel = $model->{$build[0]};
|
||||
} else {
|
||||
$AssociatedModel = $model;
|
||||
}
|
||||
|
||||
$_fields = $this->fields($AssociatedModel, $AssociatedModel->alias, array_keys($AssociatedModel->schema()));
|
||||
$result = array_merge($result, $_fields);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($fields[$i], '.') === false) {
|
||||
$this->__fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i];
|
||||
$fieldName = $this->name($alias . '.' . $fields[$i]);
|
||||
|
@ -321,10 +336,12 @@ class DboMssql extends DboSource {
|
|||
}
|
||||
$fields[$i] = "{$fieldName} AS {$fieldAlias}";
|
||||
}
|
||||
$fields[$i] = $prepend . $fields[$i];
|
||||
$result[] = $prepend . $fields[$i];
|
||||
}
|
||||
return $result;
|
||||
} else {
|
||||
return $fields;
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
/**
|
||||
* Generates and executes an SQL INSERT statement for given model, fields, and values.
|
||||
|
@ -373,6 +390,9 @@ class DboMssql extends DboSource {
|
|||
if (isset($fields[$model->primaryKey])) {
|
||||
unset($fields[$model->primaryKey]);
|
||||
}
|
||||
if (empty($fields)) {
|
||||
return true;
|
||||
}
|
||||
return parent::update($model, array_keys($fields), array_values($fields), $conditions);
|
||||
}
|
||||
/**
|
||||
|
@ -460,8 +480,8 @@ class DboMssql extends DboSource {
|
|||
}
|
||||
return $col;
|
||||
}
|
||||
$col = str_replace(')', '', $real);
|
||||
$limit = null;
|
||||
$col = str_replace(')', '', $real);
|
||||
$limit = null;
|
||||
if (strpos($col, '(') !== false) {
|
||||
list($col, $limit) = explode('(', $col);
|
||||
}
|
||||
|
@ -659,21 +679,15 @@ class DboMssql extends DboSource {
|
|||
* Generate a database-native column schema string
|
||||
*
|
||||
* @param array $column An array structured like the following: array('name'=>'value', 'type'=>'value'[, options]),
|
||||
* where options can be 'default', 'length', or 'key'.
|
||||
* where options can be 'default', 'length', or 'key'.
|
||||
* @return string
|
||||
*/
|
||||
function buildColumn($column) {
|
||||
$result = preg_replace('/(int|integer)\([0-9]+\)/i', '$1', parent::buildColumn($column));
|
||||
$null = (
|
||||
(isset($column['null']) && $column['null'] == true) ||
|
||||
(array_key_exists('default', $column) && $column['default'] === null) ||
|
||||
(array_keys($column) == array('type', 'name'))
|
||||
);
|
||||
$primaryKey = (isset($column['key']) && $column['key'] == 'primary');
|
||||
$stringKey = ($primaryKey && $column['type'] != 'integer');
|
||||
|
||||
if ($null && !$primaryKey) {
|
||||
$result .= " NULL";
|
||||
if (strpos($result, 'DEFAULT NULL') !== false) {
|
||||
$result = str_replace('DEFAULT NULL', 'NULL', $result);
|
||||
} else if (array_keys($column) == array('type', 'name')) {
|
||||
$result .= ' NULL';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -723,7 +737,6 @@ class DboMssql extends DboSource {
|
|||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -465,11 +465,12 @@ class DboOracle extends DboSource {
|
|||
* @access public
|
||||
*/
|
||||
function describe(&$model) {
|
||||
$table = $model->fullTableName($model, false);
|
||||
|
||||
if (!empty($model->sequence)) {
|
||||
$this->_sequenceMap[$model->table] = $model->sequence;
|
||||
$this->_sequenceMap[$table] = $model->sequence;
|
||||
} elseif (!empty($model->table)) {
|
||||
$this->_sequenceMap[$model->table] = $model->table . '_seq';
|
||||
$this->_sequenceMap[$table] = $model->table . '_seq';
|
||||
}
|
||||
|
||||
$cache = parent::describe($model);
|
||||
|
@ -477,12 +478,14 @@ class DboOracle extends DboSource {
|
|||
if ($cache != null) {
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH FROM all_tab_columns WHERE table_name = \'';
|
||||
$sql .= strtoupper($this->fullTableName($model)) . '\'';
|
||||
|
||||
if (!$this->execute($sql)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$fields = array();
|
||||
|
||||
for ($i = 0; $row = $this->fetchRow(); $i++) {
|
||||
|
|
|
@ -1405,6 +1405,7 @@ class DboSource extends DataSource {
|
|||
function _prepareUpdateFields(&$model, $fields, $quoteValues = true, $alias = false) {
|
||||
$quotedAlias = $this->startQuote . $model->alias . $this->endQuote;
|
||||
|
||||
$updates = array();
|
||||
foreach ($fields as $field => $value) {
|
||||
if ($alias && strpos($field, '.') === false) {
|
||||
$quoted = $model->escapeField($field);
|
||||
|
@ -2387,11 +2388,12 @@ class DboSource extends DataSource {
|
|||
if (!empty($value['unique'])) {
|
||||
$out .= 'UNIQUE ';
|
||||
}
|
||||
$name = $this->startQuote . $name . $this->endQuote;
|
||||
}
|
||||
if (is_array($value['column'])) {
|
||||
$out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
|
||||
$out .= 'KEY ' . $name . ' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
|
||||
} else {
|
||||
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
|
||||
$out .= 'KEY ' . $name . ' (' . $this->name($value['column']) . ')';
|
||||
}
|
||||
$join[] = $out;
|
||||
}
|
||||
|
|
|
@ -572,6 +572,15 @@ class JavascriptHelper extends AppHelper {
|
|||
* Generates a JavaScript object in JavaScript Object Notation (JSON)
|
||||
* from an array
|
||||
*
|
||||
* ### Options
|
||||
*
|
||||
* - block - Wraps the return value in a script tag if true. Default is false
|
||||
* - prefix - Prepends the string to the returned data. Default is ''
|
||||
* - postfix - Appends the string to the returned data. Default is ''
|
||||
* - stringKeys - A list of array keys to be treated as a string.
|
||||
* - quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true.
|
||||
* - q - The type of quote to use. Default is "'"
|
||||
*
|
||||
* @param array $data Data to be converted
|
||||
* @param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q
|
||||
* @param string $prefix DEPRECATED, use $options['prefix'] instead. Prepends the string to the returned data
|
||||
|
|
|
@ -201,6 +201,7 @@ class XmlNode extends Object {
|
|||
}
|
||||
|
||||
$tagOpts = $this->__tagOptions($name);
|
||||
|
||||
if ($tagOpts === false) {
|
||||
return;
|
||||
}
|
||||
|
@ -221,7 +222,6 @@ class XmlNode extends Object {
|
|||
$attributes = array();
|
||||
$children = array();
|
||||
$chldObjs = array();
|
||||
$document =& $this->document();
|
||||
|
||||
if (is_object($object)) {
|
||||
$chldObjs = get_object_vars($object);
|
||||
|
@ -239,7 +239,12 @@ class XmlNode extends Object {
|
|||
$node->createTextNode($chldObjs[$tagOpts['value']]);
|
||||
unset($chldObjs[$tagOpts['value']]);
|
||||
}
|
||||
unset($chldObjs['_name_']);
|
||||
|
||||
$n = $name;
|
||||
if (!empty($chldObjs['_name_'])) {
|
||||
$n = null;
|
||||
unset($chldObjs['_name_']);
|
||||
}
|
||||
$c = 0;
|
||||
|
||||
foreach ($chldObjs as $key => $val) {
|
||||
|
@ -247,14 +252,11 @@ class XmlNode extends Object {
|
|||
$attributes[$key] = $val;
|
||||
} else {
|
||||
if (!isset($tagOpts['children']) || $tagOpts['children'] === array() || (is_array($tagOpts['children']) && in_array($key, $tagOpts['children']))) {
|
||||
$n = $key;
|
||||
|
||||
if (is_numeric($n)) {
|
||||
$n = $name;
|
||||
if (!is_numeric($key)) {
|
||||
$n = $key;
|
||||
}
|
||||
if (is_array($val)) {
|
||||
foreach ($val as $i => $obj2) {
|
||||
$n2 = $i;
|
||||
foreach ($val as $n2 => $obj2) {
|
||||
if (is_numeric($n2)) {
|
||||
$n2 = $n;
|
||||
}
|
||||
|
@ -262,6 +264,7 @@ class XmlNode extends Object {
|
|||
}
|
||||
} else {
|
||||
if (is_object($val)) {
|
||||
|
||||
$node->normalize($val, $n, $options);
|
||||
} elseif ($options['format'] == 'tags' && $this->__tagOptions($key) !== false) {
|
||||
$tmp =& $node->createElement($key);
|
||||
|
@ -630,7 +633,6 @@ class XmlNode extends Object {
|
|||
if ($options['whitespace']) {
|
||||
$d .= "\n";
|
||||
}
|
||||
|
||||
$count = count($this->children);
|
||||
$cDepth = $depth + 1;
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
|
|
|
@ -60,9 +60,9 @@ class CakeTestFixtureTestFixture extends CakeTestFixture {
|
|||
* @var array
|
||||
*/
|
||||
var $records = array(
|
||||
array('name' => 'Gandalf'),
|
||||
array('name' => 'Captain Picard'),
|
||||
array('name' => 'Chewbacca')
|
||||
array('name' => 'Gandalf', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Captain Picard', 'created' => '2009-04-28 19:20:00'),
|
||||
array('name' => 'Chewbacca', 'created' => '2009-04-28 19:20:00')
|
||||
);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -1982,70 +1982,76 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->User->find('all', array('contain' => array(
|
||||
'ArticleFeatured' => array(
|
||||
'title', 'order' => 'title DESC',
|
||||
'Featured' => array(
|
||||
'category_id',
|
||||
'Category' => 'name'
|
||||
)
|
||||
)
|
||||
)));
|
||||
$expected = array(
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
||||
),
|
||||
'ArticleFeatured' => array(
|
||||
array(
|
||||
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
||||
'Featured' => array()
|
||||
),
|
||||
array(
|
||||
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
||||
'Featured' => array(
|
||||
'category_id' => 1, 'id' => 1,
|
||||
'Category' => array(
|
||||
'name' => 'Category 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
||||
),
|
||||
'ArticleFeatured' => array()
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
||||
),
|
||||
'ArticleFeatured' => array(
|
||||
array(
|
||||
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
||||
'Featured' => array(
|
||||
'category_id' => 1, 'id' => 2,
|
||||
'Category' => array(
|
||||
'name' => 'Category 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
||||
),
|
||||
'ArticleFeatured' => array()
|
||||
)
|
||||
$orders = array(
|
||||
'title DESC', 'title DESC, published DESC',
|
||||
array('title' => 'DESC'), array('title' => 'DESC', 'published' => 'DESC'),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
foreach ($orders as $order) {
|
||||
$result = $this->User->find('all', array('contain' => array(
|
||||
'ArticleFeatured' => array(
|
||||
'title', 'order' => $order,
|
||||
'Featured' => array(
|
||||
'category_id',
|
||||
'Category' => 'name'
|
||||
)
|
||||
)
|
||||
)));
|
||||
$expected = array(
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 1, 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
|
||||
),
|
||||
'ArticleFeatured' => array(
|
||||
array(
|
||||
'title' => 'Third Article', 'id' => 3, 'user_id' => 1,
|
||||
'Featured' => array()
|
||||
),
|
||||
array(
|
||||
'title' => 'First Article', 'id' => 1, 'user_id' => 1,
|
||||
'Featured' => array(
|
||||
'category_id' => 1, 'id' => 1,
|
||||
'Category' => array(
|
||||
'name' => 'Category 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 2, 'user' => 'nate', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:18:23', 'updated' => '2007-03-17 01:20:31'
|
||||
),
|
||||
'ArticleFeatured' => array()
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 3, 'user' => 'larry', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:20:23', 'updated' => '2007-03-17 01:22:31'
|
||||
),
|
||||
'ArticleFeatured' => array(
|
||||
array(
|
||||
'title' => 'Second Article', 'id' => 2, 'user_id' => 3,
|
||||
'Featured' => array(
|
||||
'category_id' => 1, 'id' => 2,
|
||||
'Category' => array(
|
||||
'name' => 'Category 1'
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'User' => array(
|
||||
'id' => 4, 'user' => 'garrett', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99',
|
||||
'created' => '2007-03-17 01:22:23', 'updated' => '2007-03-17 01:24:31'
|
||||
),
|
||||
'ArticleFeatured' => array()
|
||||
)
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* testFindThirdLevelNonReset method
|
||||
|
@ -3225,7 +3231,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
|
||||
$options = array(
|
||||
'conditions' => array(
|
||||
'Comment.comment !=' => 'Crazy',
|
||||
'Comment.published' => 'Y',
|
||||
),
|
||||
'contain' => 'User',
|
||||
|
@ -3236,7 +3241,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
|
||||
$dummyResult = $this->Article->Comment->find('all', array(
|
||||
'conditions' => array(
|
||||
'Comment.comment !=' => 'Silly',
|
||||
'User.user' => 'mariano'
|
||||
),
|
||||
'fields' => array('User.password'),
|
||||
|
@ -3320,7 +3324,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
|
||||
$initialOptions = array(
|
||||
'conditions' => array(
|
||||
'Comment.comment' => '!= Crazy',
|
||||
'Comment.published' => 'Y',
|
||||
),
|
||||
'contain' => 'User',
|
||||
|
@ -3331,7 +3334,6 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
|
||||
$findOptions = array(
|
||||
'conditions' => array(
|
||||
'Comment.comment !=' => 'Silly',
|
||||
'User.user' => 'mariano',
|
||||
),
|
||||
'fields' => array('User.password'),
|
||||
|
@ -3409,7 +3411,8 @@ class ContainableBehaviorTest extends CakeTestCase {
|
|||
'joinTable' => 'articles_tags',
|
||||
'foreignKey' => 'article_id',
|
||||
'associationForeignKey' => 'tag_id',
|
||||
'conditions' => 'LENGTH(ShortTag.tag) <= 3'
|
||||
// LENGHT function mysql-only, using LIKE does almost the same
|
||||
'conditions' => 'ShortTag.tag LIKE "???"'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
|
|
@ -427,15 +427,18 @@ class TranslateBehaviorTest extends CakeTestCase {
|
|||
$expected = array(1 => 'Titel #1', 2 => 'Titel #2', 3 => 'Titel #3');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$debug = Configure::read('debug');
|
||||
Configure::write('debug', 0);
|
||||
// MSSQL trigger an error and stops the page even if the debug = 0
|
||||
if ($this->db->config['driver'] != 'mssql') {
|
||||
$debug = Configure::read('debug');
|
||||
Configure::write('debug', 0);
|
||||
|
||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
|
||||
$this->assertEqual($result, array());
|
||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => false));
|
||||
$this->assertEqual($result, array());
|
||||
|
||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
|
||||
$this->assertEqual($result, array());
|
||||
Configure::write('debug', $debug);
|
||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'after'));
|
||||
$this->assertEqual($result, array());
|
||||
Configure::write('debug', $debug);
|
||||
}
|
||||
|
||||
$result = $TestModel->find('list', array('recursive' => 1, 'callbacks' => 'before'));
|
||||
$expected = array(1 => null, 2 => null, 3 => null);
|
||||
|
|
|
@ -43,6 +43,13 @@ class DboMssqlTestDb extends DboMssql {
|
|||
* @access public
|
||||
*/
|
||||
var $simulated = array();
|
||||
/**
|
||||
* simalate property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $simulate = true;
|
||||
/**
|
||||
* fetchAllResultsStack
|
||||
*
|
||||
|
@ -58,8 +65,12 @@ class DboMssqlTestDb extends DboMssql {
|
|||
* @return void
|
||||
*/
|
||||
function _execute($sql) {
|
||||
$this->simulated[] = $sql;
|
||||
return null;
|
||||
if ($this->simulate) {
|
||||
$this->simulated[] = $sql;
|
||||
return null;
|
||||
} else {
|
||||
return parent::_execute($sql);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* fetchAll method
|
||||
|
@ -104,6 +115,15 @@ class DboMssqlTestDb extends DboMssql {
|
|||
function getPrimaryKey($model) {
|
||||
return parent::_getPrimaryKey($model);
|
||||
}
|
||||
/**
|
||||
* clearFieldMappings method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function clearFieldMappings() {
|
||||
$this->__fieldMappings = array();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* MssqlTestModel class
|
||||
|
@ -152,6 +172,17 @@ class MssqlTestModel extends Model {
|
|||
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
);
|
||||
/**
|
||||
* belongsTo property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $belongsTo = array(
|
||||
'MssqlClientTestModel' => array(
|
||||
'foreignKey' => 'client_id'
|
||||
)
|
||||
);
|
||||
/**
|
||||
* find method
|
||||
*
|
||||
|
@ -189,6 +220,41 @@ class MssqlTestModel extends Model {
|
|||
$this->_schema = $schema;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* MssqlClientTestModel class
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.tests.cases.libs.model.datasources
|
||||
*/
|
||||
class MssqlClientTestModel extends Model {
|
||||
/**
|
||||
* name property
|
||||
*
|
||||
* @var string 'MssqlAssociatedTestModel'
|
||||
* @access public
|
||||
*/
|
||||
var $name = 'MssqlClientTestModel';
|
||||
/**
|
||||
* useTable property
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $useTable = false;
|
||||
/**
|
||||
* _schema property
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_schema = array(
|
||||
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary'),
|
||||
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
||||
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
||||
'created' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
||||
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* DboMssqlTest class
|
||||
*
|
||||
|
@ -203,6 +269,20 @@ class DboMssqlTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
var $db = null;
|
||||
/**
|
||||
* autoFixtures property
|
||||
*
|
||||
* @var bool false
|
||||
* @access public
|
||||
*/
|
||||
var $autoFixtures = false;
|
||||
/**
|
||||
* fixtures property
|
||||
*
|
||||
* @var array
|
||||
* @access public
|
||||
*/
|
||||
var $fixtures = array('core.category');
|
||||
/**
|
||||
* Skip if cannot connect to mssql
|
||||
*
|
||||
|
@ -212,6 +292,26 @@ class DboMssqlTest extends CakeTestCase {
|
|||
$this->_initDb();
|
||||
$this->skipUnless($this->db->config['driver'] == 'mssql', '%s SQL Server connection not available');
|
||||
}
|
||||
/**
|
||||
* Make sure all fixtures tables are being created
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function start() {
|
||||
$this->db->simulate = false;
|
||||
parent::start();
|
||||
$this->db->simulate = true;
|
||||
}
|
||||
/**
|
||||
* Make sure all fixtures tables are being dropped
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function end() {
|
||||
$this->db->simulate = false;
|
||||
parent::end();
|
||||
$this->db->simulate = true;
|
||||
}
|
||||
/**
|
||||
* Sets up a Dbo class instance for testing
|
||||
*
|
||||
|
@ -238,8 +338,22 @@ class DboMssqlTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
function testQuoting() {
|
||||
$result = $this->db->fields($this->model);
|
||||
$expected = array(
|
||||
$expected = "1.2";
|
||||
$result = $this->db->value(1.2, 'float');
|
||||
$this->assertIdentical($expected, $result);
|
||||
|
||||
$expected = "'1,2'";
|
||||
$result = $this->db->value('1,2', 'float');
|
||||
$this->assertIdentical($expected, $result);
|
||||
}
|
||||
/**
|
||||
* testFields method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testFields() {
|
||||
$fields = array(
|
||||
'[MssqlTestModel].[id] AS [MssqlTestModel__0]',
|
||||
'[MssqlTestModel].[client_id] AS [MssqlTestModel__1]',
|
||||
'[MssqlTestModel].[name] AS [MssqlTestModel__2]',
|
||||
|
@ -259,15 +373,32 @@ class DboMssqlTest extends CakeTestCase {
|
|||
'[MssqlTestModel].[created] AS [MssqlTestModel__16]',
|
||||
'CONVERT(VARCHAR(20), [MssqlTestModel].[updated], 20) AS [MssqlTestModel__17]'
|
||||
);
|
||||
|
||||
$result = $this->db->fields($this->model);
|
||||
$expected = $fields;
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = "1.2";
|
||||
$result = $this->db->value(1.2, 'float');
|
||||
$this->assertIdentical($expected, $result);
|
||||
$this->db->clearFieldMappings();
|
||||
$result = $this->db->fields($this->model, null, 'MssqlTestModel.*');
|
||||
$expected = $fields;
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$expected = "'1,2'";
|
||||
$result = $this->db->value('1,2', 'float');
|
||||
$this->assertIdentical($expected, $result);
|
||||
$this->db->clearFieldMappings();
|
||||
$result = $this->db->fields($this->model, null, array('*', 'AnotherModel.id', 'AnotherModel.name'));
|
||||
$expected = array_merge($fields, array(
|
||||
'[AnotherModel].[id] AS [AnotherModel__18]',
|
||||
'[AnotherModel].[name] AS [AnotherModel__19]'));
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->db->clearFieldMappings();
|
||||
$result = $this->db->fields($this->model, null, array('*', 'MssqlClientTestModel.*'));
|
||||
$expected = array_merge($fields, array(
|
||||
'[MssqlClientTestModel].[id] AS [MssqlClientTestModel__18]',
|
||||
'[MssqlClientTestModel].[name] AS [MssqlClientTestModel__19]',
|
||||
'[MssqlClientTestModel].[email] AS [MssqlClientTestModel__20]',
|
||||
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[created], 20) AS [MssqlClientTestModel__21]',
|
||||
'CONVERT(VARCHAR(20), [MssqlClientTestModel].[updated], 20) AS [MssqlClientTestModel__22]'));
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testDistinctFields method
|
||||
|
@ -330,6 +461,64 @@ class DboMssqlTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testBuildColumn
|
||||
*
|
||||
* @return unknown_type
|
||||
* @access public
|
||||
*/
|
||||
function testBuildColumn() {
|
||||
$column = array('name' => 'id', 'type' => 'integer', 'null' => '', 'default' => '', 'length' => '8', 'key' => 'primary');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[id] int IDENTITY (1, 1) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int DEFAULT 0 NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'client_id', 'type' => 'integer', 'null' => true);
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
// 'name' => 'type' format for columns
|
||||
$column = array('type' => 'integer', 'name' => 'client_id');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[client_id] int NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('type' => 'string', 'name' => 'name');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => '', 'default' => '', 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => null, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NOT NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => null, 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) NULL';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
|
||||
$result = $this->db->buildColumn($column);
|
||||
$expected = '[name] varchar(255) DEFAULT \'\'';
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testUpdateAllSyntax method
|
||||
*
|
||||
|
@ -353,6 +542,7 @@ class DboMssqlTest extends CakeTestCase {
|
|||
* @access public
|
||||
*/
|
||||
function testGetPrimaryKey() {
|
||||
// When param is a model
|
||||
$result = $this->db->getPrimaryKey($this->model);
|
||||
$this->assertEqual($result, 'id');
|
||||
|
||||
|
@ -361,6 +551,12 @@ class DboMssqlTest extends CakeTestCase {
|
|||
$this->model->setSchema($schema);
|
||||
$result = $this->db->getPrimaryKey($this->model);
|
||||
$this->assertNull($result);
|
||||
|
||||
// When param is a table name
|
||||
$this->db->simulate = false;
|
||||
$this->loadFixtures('Category');
|
||||
$result = $this->db->getPrimaryKey('categories');
|
||||
$this->assertEqual($result, 'id');
|
||||
}
|
||||
/**
|
||||
* testInsertMulti
|
||||
|
|
|
@ -1211,6 +1211,8 @@ class DboSourceTest extends CakeTestCase {
|
|||
|
||||
$this->testDb =& new DboTest($this->__config);
|
||||
$this->testDb->cacheSources = false;
|
||||
$this->testDb->startQuote = '`';
|
||||
$this->testDb->endQuote = '`';
|
||||
Configure::write('debug', 1);
|
||||
$this->debug = Configure::read('debug');
|
||||
$this->Model =& new TestModel();
|
||||
|
@ -1235,6 +1237,7 @@ class DboSourceTest extends CakeTestCase {
|
|||
function testFieldDoubleEscaping() {
|
||||
$config = array_merge($this->__config, array('driver' => 'test'));
|
||||
$test =& ConnectionManager::create('quoteTest', $config);
|
||||
$test->simulated = array();
|
||||
|
||||
$this->Model =& new Article2(array('alias' => 'Article', 'ds' => 'quoteTest'));
|
||||
$this->Model->setDataSource('quoteTest');
|
||||
|
|
|
@ -149,12 +149,8 @@ class ModelWriteTest extends BaseModelTest {
|
|||
* @return void
|
||||
*/
|
||||
function testAutoSaveUuid() {
|
||||
// SQLite does not support non-integer primary keys, and SQL Server
|
||||
// is still having problems with custom PK's
|
||||
$this->skipIf(
|
||||
$this->db->config['driver'] == 'sqlite'
|
||||
|| $this->db->config['driver'] == 'mssql'
|
||||
);
|
||||
// SQLite does not support non-integer primary keys
|
||||
$this->skipIf($this->db->config['driver'] == 'sqlite');
|
||||
|
||||
$this->loadFixtures('Uuid');
|
||||
$TestModel =& new Uuid();
|
||||
|
|
|
@ -202,7 +202,7 @@ class XmlHelperTest extends CakeTestCase {
|
|||
$result = $this->Xml->serialize($data, array('format' => 'tags'));
|
||||
$expected = '<service_day><service_time><service_time_price><dollar>1</dollar><cents>2</cents></service_time_price></service_time></service_day>';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
|
||||
$data = array(
|
||||
'Pages' => array('id' => 2, 'url' => 'http://www.url.com/rb/153/?id=bbbb&t=access')
|
||||
);
|
||||
|
@ -210,6 +210,24 @@ class XmlHelperTest extends CakeTestCase {
|
|||
$expected = '<pages id="2" url="http://www.url.com/rb/153/?id=bbbb&t=access" />';
|
||||
$this->assertIdentical($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testSerializeOnMultiDimensionalArray method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSerializeOnMultiDimensionalArray() {
|
||||
$data = array(
|
||||
'Statuses' => array(
|
||||
array('Status' => array('id' => 1)),
|
||||
array('Status' => array('id' => 2))
|
||||
)
|
||||
);
|
||||
$result = $this->Xml->serialize($data, array('format' => 'tags'));
|
||||
$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
|
||||
$this->assertIdentical($result, $expected);
|
||||
|
||||
}
|
||||
/**
|
||||
* testHeader method
|
||||
*
|
||||
|
|
|
@ -98,6 +98,25 @@ class XmlTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* testSerializeOnMultiDimensionalArray method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testSerializeOnMultiDimensionalArray() {
|
||||
$data = array(
|
||||
'Statuses' => array(
|
||||
array('Status' => array('id' => 1)),
|
||||
array('Status' => array('id' => 2))
|
||||
)
|
||||
);
|
||||
$result =& new Xml($data, array('format' => 'tags'));
|
||||
$expected = '<statuses><status><id>1</id></status><status><id>2</id></status></statuses>';
|
||||
$this->assertIdentical($result->toString(), $expected);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* test serialization of boolean and null values. false = 0, true = 1, null = ''
|
||||
*
|
||||
|
@ -118,7 +137,7 @@ class XmlTest extends CakeTestCase {
|
|||
$result = $xml->toString(false);
|
||||
$expected = '<data example="" />';
|
||||
$this->assertEqual($result, $expected, 'Boolean values incorrectly handled. %s');
|
||||
|
||||
|
||||
$xml =& new Xml(array('data' => array('example' => 0)));
|
||||
$result = $xml->toString(false);
|
||||
$expected = '<data example="0" />';
|
||||
|
|
2
cake/tests/fixtures/uuid_tree_fixture.php
vendored
2
cake/tests/fixtures/uuid_tree_fixture.php
vendored
|
@ -46,7 +46,7 @@ class UuidTreeFixture extends CakeTestFixture {
|
|||
var $fields = array(
|
||||
'id' => array('type' => 'string', 'length' => 36, 'key' => 'primary'),
|
||||
'name' => array('type' => 'string','null' => false),
|
||||
'parent_id' => array('type' => 'string', 'length' => 36),
|
||||
'parent_id' => array('type' => 'string', 'length' => 36, 'null' => true),
|
||||
'lft' => array('type' => 'integer','null' => false),
|
||||
'rght' => array('type' => 'integer','null' => false)
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue