Merge branch '1.2' into 1.2-merger

Conflicts:
	cake/libs/model/datasources/dbo/dbo_mysql.php
	cake/libs/model/datasources/dbo/dbo_mysqli.php
	cake/libs/view/helpers/text.php
	cake/libs/view/theme.php
This commit is contained in:
mark_story 2009-12-06 21:43:53 -05:00
commit 7259a1b920
16 changed files with 126 additions and 131 deletions

View file

@ -189,7 +189,7 @@ dl {
margin: 0em 0em;
width: 60%;
}
dl.altrow {
dl .altrow {
background: #f4f4f4;
}
dt {

View file

@ -190,7 +190,7 @@ dl {
margin: 0em 0em;
width: 60%;
}
dl.altrow {
dl .altrow {
background: #f4f4f4;
}
dt {

View file

@ -241,7 +241,7 @@ class ClassRegistry {
* Return object which corresponds to given key.
*
* @param string $key Key of object to look for
* @return mixed Object stored in registry
* @return mixed Object stored in registry or boolean false if the object does not exist.
* @access public
* @static
*/

View file

@ -947,11 +947,12 @@ class Controller extends Object {
$op = '';
}
$arrayOp = is_array($op);
foreach ($data as $model => $fields) {
foreach ($fields as $field => $value) {
$key = $model.'.'.$field;
$fieldOp = $op;
if (is_array($op)) {
if ($arrayOp) {
if (array_key_exists($key, $op)) {
$fieldOp = $op[$key];
} elseif (array_key_exists($field, $op)) {

View file

@ -140,15 +140,6 @@ class TreeBehavior extends ModelBehavior {
function beforeSave(&$Model) {
extract($this->settings[$Model->alias]);
if (isset($Model->data[$Model->alias][$Model->primaryKey])) {
if ($Model->data[$Model->alias][$Model->primaryKey]) {
if (!$Model->id) {
$Model->id = $Model->data[$Model->alias][$Model->primaryKey];
}
}
unset($Model->data[$Model->alias][$Model->primaryKey]);
}
$this->_addToWhitelist($Model, array($left, $right));
if (!$Model->id) {
if (array_key_exists($parent, $Model->data[$Model->alias]) && $Model->data[$Model->alias][$parent]) {

View file

@ -464,6 +464,53 @@ class DboMysqlBase extends DboSource {
}
return false;
}
/**
* Converts database-layer column types to basic types
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = $this->length($real);
if (strpos($col, '(') !== false) {
list($col, $vals) = explode('(', $col);
}
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
return 'float';
}
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
return 'text';
}
}
/**
@ -682,54 +729,6 @@ class DboMysql extends DboMysqlBase {
return null;
}
/**
* Converts database-layer column types to basic types
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = $this->length($real);
if (strpos($col, '(') !== false) {
list($col, $vals) = explode('(', $col);
}
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
return 'float';
}
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
return 'text';
}
/**
* Enter description here...
*

View file

@ -260,54 +260,6 @@ class DboMysqli extends DboMysqlBase {
return null;
}
/**
* Converts database-layer column types to basic types
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return string Abstract column type (i.e. "string")
*/
function column($real) {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
}
return $col;
}
$col = str_replace(')', '', $real);
$limit = $this->length($real);
if (strpos($col, '(') !== false) {
list($col, $vals) = explode('(', $col);
}
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {
return 'float';
}
if (strpos($col, 'enum') !== false) {
return "enum($vals)";
}
return 'text';
}
/**
* Enter description here...
*

View file

@ -2419,6 +2419,8 @@ class Model extends Overloadable {
/**
* Returns true if all fields pass validation.
*
* Will validate the currently set data. Use Model::set() or Model::create() to set the active data.
*
* @param string $options An optional array of custom options to be made available in the beforeValidate callback
* @return boolean True if there are no errors
* @access public
@ -2437,6 +2439,7 @@ class Model extends Overloadable {
*
* @param string $options An optional array of custom options to be made available in the beforeValidate callback
* @return array Array of invalid fields
* @see Model::validates()
* @access public
* @link http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
*/

View file

@ -282,8 +282,9 @@ class Router {
if ($named === true || $named === false) {
$options = array_merge(array('default' => $named, 'reset' => true, 'greedy' => $named), $options);
$named = array();
} else {
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options);
}
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options);
if ($options['reset'] == true || $_this->named['rules'] === false) {
$_this->named['rules'] = array();

View file

@ -593,7 +593,7 @@ class JavascriptHelper extends AppHelper {
* - 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 "'"
* - q - The type of quote to use. Default is '"'. This option only affects the keys, not the values.
*
* @param array $data Data to be converted
* @param array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q

View file

@ -332,15 +332,17 @@ class TextHelper extends AppHelper {
* @access public
*/
function toList($list, $and = 'and') {
$r = '';
$c = count($list) - 1;
$return = '';
$count = count($list) - 1;
$counter = 0;
foreach ($list as $i => $item) {
$r .= $item;
if ($c > 0 && $i < $c) {
$r .= ($i < $c - 1 ? ', ' : " {$and} ");
$return .= $item;
if ($count > 0 && $counter < $count) {
$return .= ($counter < $count - 1 ? ', ' : " {$and} ");
}
$counter++;
}
return $r;
return $return;
}
}
?>

View file

@ -114,7 +114,6 @@ class XmlNode extends Object {
$this->createTextNode($value);
}
}
/**
* Adds a namespace to the current node
*
@ -250,7 +249,7 @@ class XmlNode extends Object {
}
$n = $name;
if (!empty($chldObjs['_name_'])) {
if (isset($chldObjs['_name_'])) {
$n = null;
unset($chldObjs['_name_']);
}
@ -760,13 +759,13 @@ class XmlNode extends Object {
* if given the $recursive parameter.
*
* @param boolean $recursive Recursively delete elements.
* @access private
* @access protected
*/
function __killParent($recursive = true) {
function _killParent($recursive = true) {
unset($this->__parent, $this->_log);
if ($recursive && $this->hasChildren()) {
for ($i = 0; $i < count($this->children); $i++) {
$this->children[$i]->__killParent(true);
$this->children[$i]->_killParent(true);
}
}
}
@ -1135,6 +1134,7 @@ class Xml extends XmlNode {
if (is_resource($this->__parser)) {
xml_parser_free($this->__parser);
}
$this->_killParent(true);
}
/**

View file

@ -3106,6 +3106,19 @@ class ModelWriteTest extends BaseModelTest {
'attachment' => 'some_file.zip'
)));
$this->assertEqual($result, $expected);
$model->Attachment->bindModel(array('belongsTo' => array('Comment')), false);
$data = array(
'Comment' => array(
'comment' => 'Comment with attachment',
'article_id' => 1,
'user_id' => 1
),
'Attachment' => array(
'attachment' => 'some_file.zip'
));
$this->assertTrue($model->saveAll($data, array('validate' => 'first')));
}
/**

View file

@ -362,6 +362,9 @@ class TextHelperTest extends CakeTestCase {
$result = $this->Text->toList(array('Dusty', 'Lucky', 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
$result = $this->Text->toList(array( 1 => 'Dusty', 2 => 'Lucky', 3 => 'Ned'), 'y');
$this->assertEqual($result, 'Dusty, Lucky y Ned');
}
}
?>

View file

@ -149,11 +149,11 @@ class ThemeViewTest extends CakeTestCase {
*/
function setUp() {
Router::reload();
$this->Controller = new Controller();
$this->PostsController = new ThemePostsController();
$this->Controller =& new Controller();
$this->PostsController =& new ThemePostsController();
$this->PostsController->viewPath = 'posts';
$this->PostsController->index();
$this->ThemeView = new ThemeView($this->PostsController);
$this->ThemeView =& new ThemeView($this->PostsController);
}
/**
@ -166,6 +166,19 @@ class ThemeViewTest extends CakeTestCase {
unset($this->ThemeView);
unset($this->PostsController);
unset($this->Controller);
ClassRegistry::flush();
}
/**
* test that the theme view can be constructed without going into the registry
*
* @return void
*/
function testConstructionNoRegister() {
ClassRegistry::flush();
$controller = null;
$Theme =& new ThemeView($controller, false);
$ThemeTwo =& ClassRegistry::getObject('view');
$this->assertFalse($ThemeTwo);
}
/**

View file

@ -113,7 +113,6 @@ class XmlTest extends CakeTestCase {
$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);
}
/**
@ -263,7 +262,7 @@ class XmlTest extends CakeTestCase {
* @access public
* @return void
*/
function testArraySerialization() {
function testSerializationArray() {
$input = array(
array(
'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
@ -291,7 +290,7 @@ class XmlTest extends CakeTestCase {
* @access public
* @return void
*/
function testNestedArraySerialization() {
function testSerializationNestedArray() {
$input = array(
array(
'Project' => array('id' => 1, 'title' => null, 'client_id' => 1, 'show' => 1, 'is_spotlight' => null, 'style_id' => 0, 'job_type_id' => 1, 'industry_id' => 1, 'modified' => null, 'created' => null),
@ -337,9 +336,9 @@ class XmlTest extends CakeTestCase {
*/
function testArraySerializationWithRoot() {
$input = array(
array('Shirt' => array('id' => 1, 'color' => 'green')),
array('Shirt' => array('id' => 2, 'color' => 'blue')),
);
array('Shirt' => array('id' => 1, 'color' => 'green')),
array('Shirt' => array('id' => 2, 'color' => 'blue')),
);
$expected = '<collection><shirt id="1" color="green" />';
$expected .= '<shirt id="2" color="blue" /></collection>';
@ -714,6 +713,24 @@ class XmlTest extends CakeTestCase {
$this->assertEqual($expected, $result);
}
/**
* ensure that normalize does not add _name_ elements that come from Set::map sometimes.
*
* @return void
*/
function testNormalizeNotAdding_name_Element() {
$input = array(
'output' => array(
'Vouchers' => array(
array('Voucher' => array('id' => 1)),
array('Voucher' => array('id' => 2)),
),
)
);
$xml = new Xml($input, array('attributes' => false, 'format' => 'tags'));
$this->assertFalse(isset($xml->children[0]->children[0]->children[1]), 'Too many children %s');
$this->assertEqual($xml->children[0]->children[0]->children[0]->name, 'voucher');
}
/**
* testSimpleParsing method
*