Merge branch '1.2' into 1.2-merger

Conflicts:
	app/webroot/test.php
	cake/VERSION.txt
	cake/bootstrap.php
	cake/config/config.php
	cake/console/cake.php
	cake/console/libs/schema.php
	cake/console/templates/skel/webroot/test.php
	cake/libs/configure.php
	cake/tests/cases/console/libs/schema.test.php
	cake/tests/cases/libs/debugger.test.php
	cake/tests/cases/libs/model/model_write.test.php
	cake/tests/fixtures/aco_fixture.php
This commit is contained in:
mark_story 2009-09-16 01:23:49 -04:00
commit 5717e3b59c
32 changed files with 555 additions and 142 deletions

View file

@ -225,6 +225,11 @@
*/
//date_default_timezone_set('UTC');
/**
* If you are on PHP 5.3 uncomment this line and correct your server timezone
* to fix the date & time related errors.
*/
//date_default_timezone_set('UTC');
/**
*
* Cache Engine Configuration

View file

@ -24,14 +24,6 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* PHP 5.3 raises many notices in bootstrap.
*/
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
error_reporting(E_ALL & ~E_DEPRECATED);
set_time_limit(0);
ini_set('memory_limit','128M');
ini_set('display_errors', 1);

View file

@ -54,9 +54,8 @@ if (!function_exists('clone')) {
* Loads configuration files. Receives a set of configuration files
* to load.
* Example:
* <code>
* config('config1', 'config2');
* </code>
*
* `config('config1', 'config2');`
*
* @return boolean Success
*/
@ -84,9 +83,8 @@ if (!function_exists('clone')) {
* Loads component/components from LIBS. Takes optional number of parameters.
*
* Example:
* <code>
* uses('flay', 'time');
* </code>
*
* `uses('flay', 'time');`
*
* @param string $name Filename without the .php part
* @deprecated
@ -224,14 +222,12 @@ if (!function_exists('array_combine')) {
* Returns an array of all the given parameters.
*
* Example:
* <code>
* a('a', 'b')
* </code>
*
* `a('a', 'b')`
*
* Would return:
* <code>
* array('a', 'b')
* </code>
*
* `array('a', 'b')`
*
* @return array Array of given parameters
* @link http://book.cakephp.org/view/694/a
@ -245,14 +241,12 @@ if (!function_exists('array_combine')) {
* Constructs associative array from pairs of arguments.
*
* Example:
* <code>
* aa('a','b')
* </code>
*
* `aa('a','b')`
*
* Would return:
* <code>
* array('a'=>'b')
* </code>
*
* `array('a'=>'b')`
*
* @return array Associative array
* @link http://book.cakephp.org/view/695/aa
@ -531,10 +525,9 @@ if (!function_exists('file_put_contents')) {
/**
* Used to delete files in the cache directories, or clear contents of cache directories
*
* @param mixed $params As String name to be searched for deletion, if name is a directory all files in directory will be deleted.
* If array, names to be searched for deletion.
* If clearCache() without params, all files in app/tmp/cache/views will be deleted
*
* @param mixed $params As String name to be searched for deletion, if name is a directory all files in
* directory will be deleted. If array, names to be searched for deletion. If clearCache() without params,
* all files in app/tmp/cache/views will be deleted
* @param string $type Directory in tmp/cache defaults to view directory
* @param string $ext The file extension you are deleting
* @return true if files found and deleted false otherwise
@ -715,13 +708,14 @@ if (!function_exists('file_put_contents')) {
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_CTYPE 0
* LC_NUMERIC 1
* LC_TIME 2
* LC_COLLATE 3
* LC_MONETARY 4
* LC_MESSAGES 5
* LC_ALL 6
*
* - LC_ALL 0
* - LC_COLLATE 1
* - LC_CTYPE 2
* - LC_MONETARY 3
* - LC_NUMERIC 4
* - LC_TIME 5
* - LC_MESSAGES 6
*
* @param string $domain Domain
* @param string $msg Message to translate
@ -754,13 +748,14 @@ if (!function_exists('file_put_contents')) {
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_ALL 0
* LC_COLLATE 1
* LC_CTYPE 2
* LC_MONETARY 3
* LC_NUMERIC 4
* LC_TIME 5
* LC_MESSAGES 6
*
* - LC_ALL 0
* - LC_COLLATE 1
* - LC_CTYPE 2
* - LC_MONETARY 3
* - LC_NUMERIC 4
* - LC_TIME 5
* - LC_MESSAGES 6
*
* @param string $domain Domain
* @param string $singular Singular string to translate
@ -790,13 +785,14 @@ if (!function_exists('file_put_contents')) {
* Valid categories are: LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.
*
* Note that the category must be specified with a numeric value, instead of the constant name. The values are:
* LC_CTYPE 0
* LC_NUMERIC 1
* LC_TIME 2
* LC_COLLATE 3
* LC_MONETARY 4
* LC_MESSAGES 5
* LC_ALL 6
*
* - LC_ALL 0
* - LC_COLLATE 1
* - LC_CTYPE 2
* - LC_MONETARY 3
* - LC_NUMERIC 4
* - LC_TIME 5
* - LC_MESSAGES 6
*
* @param string $msg String to translate
* @param integer $category Category
@ -965,9 +961,8 @@ if (!function_exists('file_put_contents')) {
* Wraps ternary operations. If $condition is a non-empty value, $val1 is returned, otherwise $val2.
* Don't use for isset() conditions, or wrap your variable with @ operator:
* Example:
* <code>
* ife(isset($variable), @$variable, 'default');
* </code>
*
* `ife(isset($variable), @$variable, 'default');`
*
* @param mixed $condition Conditional expression
* @param mixed $val1 Value to return in case condition matches

View file

@ -19,5 +19,5 @@
* @since CakePHP(tm) v 1.1.11.4062
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
return $config['Cake.version'] = '1.3.0.0';
?>
return $config['Cake.version'] = '1.3.0';
?>

View file

@ -27,7 +27,6 @@
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
/**
* Shell dispatcher
*
@ -161,7 +160,7 @@ class ShellDispatcher {
function __initConstants() {
if (function_exists('ini_set')) {
ini_set('display_errors', '1');
ini_set('error_reporting', E_ALL);
ini_set('error_reporting', E_ALL & ~E_DEPRECATED);
ini_set('html_errors', false);
ini_set('implicit_flush', true);
ini_set('max_execution_time', 0);
@ -228,7 +227,7 @@ class ShellDispatcher {
require LIBS . 'folder.php';
}
foreach ($pluginPaths as $pluginPath) {
$Folder =& new Folder($pluginPath);
$Folder = new Folder($pluginPath);
list($plugins,) = $Folder->read(false, true);
foreach ((array)$plugins as $plugin) {
$path = $pluginPath . Inflector::underscore($plugin) . DS . 'vendors' . DS . 'shells' . DS;

View file

@ -8,20 +8,17 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs
* @since CakePHP(tm) v 1.2.0.5550
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('Core', 'File', false);
@ -208,6 +205,7 @@ class SchemaShell extends Shell {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$contents = "#" . $Schema->name . " sql generated on: " . date('Y-m-d H:i:s') . " : " . time() . "\n\n";
$contents .= $db->dropSchema($Schema) . "\n\n". $db->createSchema($Schema);
if ($write) {
if (strpos($write, '.sql') === false) {
$write .= '.sql';
@ -290,7 +288,7 @@ class SchemaShell extends Shell {
*
* @access private
*/
function __create($Schema, $table = null) {
function __create(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$drop = $create = array();
@ -334,11 +332,15 @@ class SchemaShell extends Shell {
*
* @access private
*/
function __update($Schema, $table = null) {
function __update(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$this->out(__('Comparing Database to Schema...', true));
$Old = $this->Schema->read();
$options = array();
if (isset($this->params['f'])) {
$options['models'] = false;
}
$Old = $this->Schema->read($options);
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
@ -372,7 +374,7 @@ class SchemaShell extends Shell {
*
* @access private
*/
function __run($contents, $event, $Schema) {
function __run($contents, $event, &$Schema) {
if (empty($contents)) {
$this->err(__('Sql could not be run', true));
return;
@ -380,7 +382,7 @@ class SchemaShell extends Shell {
Configure::write('debug', 2);
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$db->fullDebug = true;
foreach ($contents as $table => $sql) {
if (empty($sql)) {
$this->out(sprintf(__('%s is up to date.', true), $table));

View file

@ -225,6 +225,11 @@
*/
//date_default_timezone_set('UTC');
/**
* If you are on PHP 5.3 uncomment this line and correct your server timezone
* to fix the date & time related errors.
*/
//date_default_timezone_set('UTC');
/**
*
* Cache Engine Configuration

View file

@ -25,25 +25,15 @@
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
/**
* PHP 5.3 raises many notices in bootstrap.
*/
if (!defined('E_DEPRECATED')) {
define('E_DEPRECATED', 8192);
}
error_reporting(E_ALL & ~E_DEPRECATED);
set_time_limit(0);
ini_set('memory_limit','128M');
ini_set('display_errors', 1);
/**
* Use the DS to separate the directories in other defines
*/
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
/**
* These defines should only be edited if you have cake installed in
* a directory layout other than the way it is distributed.

View file

@ -725,10 +725,14 @@ class EmailComponent extends Object{
return false;
}
$httpHost = env('HTTP_HOST');
if (isset($this->smtpOptions['client'])) {
$host = $this->smtpOptions['client'];
} elseif (!empty($httpHost)) {
$host = $httpHost;
} else {
$host = env('HTTP_HOST');
$host = 'localhost';
}
if (!$this->__smtpSend("HELO {$host}", '250')) {

View file

@ -186,6 +186,7 @@ class CakeSchema extends Object {
* - 'connection' - the db connection to use
* - 'name' - name of the schema
* - 'models' - a list of models to use, or false to ignore models
*
* @param array $options schema object properties
* @return array Array indexed by name and tables
* @access public

View file

@ -275,6 +275,9 @@ class DboMssql extends DboSource {
if ($data === null) {
return 'NULL';
}
if (in_array($column, array('integer', 'float', 'binary')) && $data === '') {
return 'NULL';
}
if ($data === '') {
return "''";
}
@ -737,8 +740,8 @@ class DboMssql extends DboSource {
foreach ($indexes as $name => $value) {
if ($name == 'PRIMARY') {
$out = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
} else {
$join[] = 'PRIMARY KEY (' . $this->name($value['column']) . ')';
} else if (isset($value['unique']) && $value['unique']) {
$out = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE";
if (is_array($value['column'])) {
@ -747,8 +750,8 @@ class DboMssql extends DboSource {
$value['column'] = $this->name($value['column']);
}
$out .= "({$value['column']});";
$join[] = $out;
}
$join[] = $out;
}
return $join;
}

View file

@ -1563,7 +1563,7 @@ class DboSource extends DataSource {
'alias' => $assoc,
'type' => isset($assocData['type']) ? $assocData['type'] : 'LEFT',
'conditions' => trim($this->conditions(
$this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData),
$this->__mergeConditions($assocData['conditions'], $this->getConstraint($assocData['association'], $model, $model->{$assoc}, $assoc, $assocData)),
true, false, $model
))
));

View file

@ -1855,8 +1855,6 @@ class Model extends Overloadable {
* @access protected
*/
function _deleteLinks($id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
$with = $data['with'];
$records = $this->{$data['with']}->find('all', array(

View file

@ -799,6 +799,9 @@ class Router extends Object {
} else {
$params = end($_this->__params);
}
if (isset($params['prefix']) && strpos($params['action'], $params['prefix']) === 0) {
$params['action'] = substr($params['action'], strlen($params['prefix']) + 1);
}
}
$path = array('base' => null);

View file

@ -398,7 +398,7 @@ class Set extends Object {
$options = array_merge(array('flatten' => true), $options);
if (!isset($contexts[0])) {
$current = current($data);
if ((is_array($current) && count($data) <= 1) || !is_array($current)) {
if ((is_array($current) && count($data) <= 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
$contexts = array($data);
}
}
@ -1098,7 +1098,7 @@ class Set extends Object {
if (!is_null($key)) {
$id = $key;
}
if (is_array($r)) {
if (is_array($r) && count($r)) {
$stack = array_merge($stack, Set::__flatten($r, $id));
} else {
$stack[] = array('id' => $id, 'value' => $r);

View file

@ -421,11 +421,10 @@ class FormHelper extends AppHelper {
if (is_array($text) && is_numeric($error) && $error > 0) {
$error--;
}
if (is_array($text) && isset($text[$error])) {
$text = $text[$error];
} elseif (is_array($text)) {
if (is_array($text)) {
$options = array_merge($options, $text);
$text = null;
$text = isset($text[$error]) ? $text[$error] : null;
unset($options[$error]);
}
if ($text != null) {
@ -1647,15 +1646,16 @@ class FormHelper extends AppHelper {
}
$opt = implode($separator, $selects);
}
if (!empty($interval) && $interval > 1 && !empty($min)) {
$min = round($min * (1 / $interval)) * $interval;
}
$selectMinuteAttr['interval'] = $interval;
switch ($timeFormat) {
case '24':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty);
break;
case '12':
$selectMinuteAttr['interval'] = $interval;
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);

View file

@ -47,6 +47,67 @@ Mock::generatePartial(
Mock::generate('CakeSchema', 'MockSchemaCakeSchema');
/**
* Test for Schema database management
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class SchemaShellTestSchema extends CakeSchema {
/**
* name property
*
* @var string 'MyApp'
* @access public
*/
var $name = 'SchemaShellTest';
/**
* connection property
*
* @var string 'test_suite'
* @access public
*/
var $connection = 'test_suite';
/**
* comments property
*
* @var array
* @access public
*/
var $comments = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'post_id' => array('type' => 'integer', 'null' => false, 'default' => 0),
'user_id' => array('type' => 'integer', 'null' => false),
'title' => array('type' => 'string', 'null' => false, 'length' => 100),
'comment' => array('type' => 'text', 'null' => false, 'default' => null),
'published' => array('type' => 'string', 'null' => true, 'default' => 'N', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
/**
* posts property
*
* @var array
* @access public
*/
var $articles = array(
'id' => array('type' => 'integer', 'null' => false, 'default' => 0, 'key' => 'primary'),
'user_id' => array('type' => 'integer', 'null' => true, 'default' => ''),
'title' => array('type' => 'string', 'null' => false, 'default' => 'Title'),
'body' => array('type' => 'text', 'null' => true, 'default' => null),
'summary' => array('type' => 'text', 'null' => true),
'published' => array('type' => 'string', 'null' => true, 'default' => 'Y', 'length' => 1),
'created' => array('type' => 'datetime', 'null' => true, 'default' => null),
'updated' => array('type' => 'datetime', 'null' => true, 'default' => null),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => true)),
);
}
/**
* SchemaShellTest class
*
@ -87,7 +148,7 @@ class SchemaShellTest extends CakeTestCase {
$this->Shell->startup();
$this->assertTrue(isset($this->Shell->Schema));
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
$this->assertEqual($this->Shell->Schema->name, 'App');
$this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
$this->assertEqual($this->Shell->Schema->file, 'schema.php');
unset($this->Shell->Schema);
@ -99,7 +160,7 @@ class SchemaShellTest extends CakeTestCase {
$this->assertEqual($this->Shell->Schema->file, 'test_schema.php');
$this->assertEqual($this->Shell->Schema->connection, 'default');
$this->assertEqual($this->Shell->Schema->path, APP . 'config' . DS . 'schema');
unset($this->Shell->Schema);
$this->Shell->params = array(
'file' => 'other_file.php',
@ -107,7 +168,7 @@ class SchemaShellTest extends CakeTestCase {
'path' => '/test/path'
);
$this->Shell->startup();
$this->assertEqual($this->Shell->Schema->name, 'App');
$this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR);
$this->assertEqual($this->Shell->Schema->file, 'other_file.php');
$this->assertEqual($this->Shell->Schema->connection, 'test_suite');
$this->assertEqual($this->Shell->Schema->path, '/test/path');
@ -123,24 +184,9 @@ class SchemaShellTest extends CakeTestCase {
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
$this->Shell->params['file'] = 'i18n.php';
$this->Shell->expectOnce('_stop');
$this->Shell->expectOnce('out');
$this->Shell->expectAt(0, 'out', array(new PatternExpectation('/class i18nSchema extends CakeSchema/')));
$this->Shell->view();
}
/**
* test dumping a schema file.
*
* @return void
**/
function testDump() {
$this->Shell->params = array('name' => 'i18n');
$this->Shell->startup();
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
$this->Shell->expectAt(0, 'out', array(new PatternExpectation('/create table `i18n`/i')));
$this->Shell->dump();
}
/**
* test dump() with sql file generation
*
@ -244,16 +290,16 @@ class SchemaShellTest extends CakeTestCase {
$this->Shell->params = array(
'connection' => 'test_suite',
'name' => 'i18n',
'path' => APP . 'config' . DS . 'schema'
'path' => APP . 'config' . DS . 'sql'
);
$this->Shell->args = array('create');
$this->Shell->startup();
$this->Shell->setReturnValue('in', 'y');
$this->Shell->run();
$db =& ConnectionManager::getDataSource('test_suite');
$sources = $db->listSources();
$this->assertTrue(in_array('i18n', $sources));
$this->assertTrue(in_array($db->config['prefix'] . 'i18n', $sources));
}
/**
@ -265,7 +311,7 @@ class SchemaShellTest extends CakeTestCase {
$this->Shell->params = array(
'connection' => 'test_suite',
'name' => 'DbAcl',
'path' => APP . 'config' . DS . 'schema'
'path' => APP . 'config' . DS . 'sql'
);
$this->Shell->args = array('create', 'acos');
$this->Shell->startup();
@ -274,10 +320,34 @@ class SchemaShellTest extends CakeTestCase {
$db =& ConnectionManager::getDataSource('test_suite');
$sources = $db->listSources();
$this->assertTrue(in_array('acos', $sources));
$this->assertFalse(in_array('aros', $sources));
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
$this->assertFalse(in_array($db->config['prefix'] . 'aros', $sources));
$this->assertFalse(in_array('aros_acos', $sources));
}
/**
* test run update with a table arg.
*
* @return void
**/
function testRunUpdateWithTable() {
$this->Shell->params = array(
'name' => 'SchemaShellTest',
'connection' => 'test_suite',
'f' => true
);
$this->Shell->args = array('update', 'articles');
$this->Shell->startup();
$this->Shell->setReturnValue('in', 'y');
$this->Shell->run();
$article =& new Model(array('name' => 'Article', 'ds' => 'test_suite'));
$fields = $article->schema();
$this->assertTrue(isset($fields['summary']));
$this->_fixtures['core.article']->drop($this->db);
$this->_fixtures['core.article']->create($this->db);
}
}
?>

View file

@ -505,10 +505,9 @@ TEXTBLOC;
$response = $this->Controller->EmailTest->smtpSend('HELO', '250');
$this->assertPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
$this->Controller->EmailTest->smtpError = null;
$this->Controller->EmailTest->reset();
$response = $this->Controller->EmailTest->smtpSend('HELO somehostname', '250');
$this->assertNoPattern('/501 Syntax: HELO hostname/', $this->Controller->EmailTest->smtpError);
}
/**

View file

@ -1174,12 +1174,12 @@ class NumberTreeTest extends CakeTestCase {
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$this->Tree->id= $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
$this->assertEqual($direct, $expects);
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
$expects = array(
array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
@ -1790,7 +1790,7 @@ class UuidTreeTest extends NumberTreeTest {
$this->Tree->initialize(2, 2);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
@ -1816,19 +1816,20 @@ class UuidTreeTest extends NumberTreeTest {
function testNoAmbiguousColumn() {
extract($this->settings);
$this->Tree =& new $modelClass();
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
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'));
$this->Tree->id= $data[$modelClass]['id'];
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField), null, null, null, 1);
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
$this->Tree->id = $data[$modelClass]['id'];
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)));
$this->assertEqual($direct, $expects);
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField), null, null, null, 1);
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField));
$expects = array(
array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)),

View file

@ -367,6 +367,18 @@ class DboMssqlTest extends CakeTestCase {
$expected = "'1,2'";
$result = $this->db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'integer');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'float');
$this->assertIdentical($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'binary');
$this->assertIdentical($expected, $result);
}
/**
* testFields method
@ -544,6 +556,33 @@ class DboMssqlTest extends CakeTestCase {
$expected = '[name] varchar(255) DEFAULT \'\'';
$this->assertEqual($result, $expected);
}
/**
* testBuildIndex method
*
* @return void
* @access public
*/
function testBuildIndex() {
$indexes = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'client_id' => array('column' => 'client_id', 'unique' => 1)
);
$result = $this->db->buildIndex($indexes, 'items');
$expected = array(
'PRIMARY KEY ([id])',
'ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id]);'
);
$this->assertEqual($result, $expected);
$indexes = array('client_id' => array('column' => 'client_id'));
$result = $this->db->buildIndex($indexes, 'items');
$this->assertEqual($result, array());
$indexes = array('client_id' => array('column' => array('client_id', 'period_id'), 'unique' => 1));
$result = $this->db->buildIndex($indexes, 'items');
$expected = array('ALTER TABLE items ADD CONSTRAINT client_id UNIQUE([client_id], [period_id]);');
$this->assertEqual($result, $expected);
}
/**
* testUpdateAllSyntax method
*

View file

@ -73,7 +73,7 @@ class BaseModelTest extends CakeTestCase {
'core.counter_cache_user_nonstandard_primary_key',
'core.counter_cache_post_nonstandard_primary_key', 'core.uuidportfolio',
'core.uuiditems_uuidportfolio', 'core.uuiditems_uuidportfolio_numericid', 'core.fruit',
'core.fruits_uuid_tag', 'core.uuid_tag'
'core.fruits_uuid_tag', 'core.uuid_tag', 'core.product_update_all', 'core.group_update_all'
);
/**

View file

@ -26,8 +26,6 @@
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once dirname(__FILE__) . DS . 'model.test.php';
require_once dirname(__FILE__) . DS . 'model_write.test.php';
/**
* ModelWriteTest
*
@ -3938,6 +3936,167 @@ class ModelWriteTest extends BaseModelTest {
);
$this->assertEqual($TestModel->Comment->validationErrors, $expected);
}
/**
* TestFindAllWithoutForeignKey
*
* @link http://code.cakephp.org/tickets/view/69
* @access public
* @return void
*/
function testFindAllForeignKey() {
$this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll');
$ProductUpdateAll =& new ProductUpdateAll();
$conditions = array('Group.name' => 'group one');
$ProductUpdateAll->bindModel(array(
'belongsTo' => array(
'Group' => array('className' => 'GroupUpdateAll')
)
));
$ProductUpdateAll->belongsTo = array(
'Group' => array('className' => 'GroupUpdateAll', 'foreignKey' => 'group_id')
);
$results = $ProductUpdateAll->find('all', compact('conditions'));
$this->assertTrue(!empty($results));
$ProductUpdateAll->bindModel(array('belongsTo'=>array('Group')));
$ProductUpdateAll->belongsTo = array(
'Group' => array(
'className' => 'GroupUpdateAll',
'foreignKey' => false,
'conditions' => 'ProductUpdateAll.groupcode = Group.code'
));
$resultsFkFalse = $ProductUpdateAll->find('all', compact('conditions'));
$this->assertTrue(!empty($resultsFkFalse));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'product one',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'product two',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
)
);
$this->assertEqual($results, $expected);
$this->assertEqual($resultsFkFalse, $expected);
}
/**
* testProductUpdateAllWithForeignKey
*
* @link http://code.cakephp.org/tickets/view/69
* @access public
* @return void
*/
function testProductUpdateAll() {
$this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll');
$ProductUpdateAll =& new ProductUpdateAll();
$conditions = array('Group.name' => 'group one');
$ProductUpdateAll->bindModel(array('belongsTo' => array(
'Group' => array('className' => 'GroupUpdateAll')))
);
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$results = $ProductUpdateAll->find('all', array(
'conditions' => array('ProductUpdateAll.name' => 'new product')
));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$this->assertEqual($results, $expected);
}
/**
* testProductUpdateAllWithoutForeignKey
*
* @link http://code.cakephp.org/tickets/view/69
* @access public
* @return void
*/
function testProductUpdateAllWithoutForeignKey() {
$this->loadFixtures('ProductUpdateAll', 'GroupUpdateAll');
$ProductUpdateAll =& new ProductUpdateAll();
$conditions = array('Group.name' => 'group one');
$ProductUpdateAll->bindModel(array('belongsTo' => array(
'Group' => array('className' => 'GroupUpdateAll')
)));
$ProductUpdateAll->belongsTo = array(
'Group' => array(
'className' => 'GroupUpdateAll',
'foreignKey' => false,
'conditions' => 'ProductUpdateAll.groupcode = Group.code'
)
);
$ProductUpdateAll->updateAll(array('name' => "'new product'"), $conditions);
$resultsFkFalse = $ProductUpdateAll->find('all', array('conditions' => array('ProductUpdateAll.name'=>'new product')));
$expected = array(
'0' => array(
'ProductUpdateAll' => array(
'id' => 1,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)
),
'1' => array(
'ProductUpdateAll' => array(
'id' => 2,
'name' => 'new product',
'groupcode' => 120,
'group_id' => 1),
'Group' => array(
'id' => 1,
'name' => 'group one',
'code' => 120)));
$this->assertEqual($resultsFkFalse, $expected);
}
}

View file

@ -3389,4 +3389,16 @@ class UuidTagNoWith extends CakeTestModel {
);
}
class ProductUpdateAll extends CakeTestModel {
var $name = 'ProductUpdateAll';
var $useTable = 'product_update_all';
}
class GroupUpdateAll extends CakeTestModel {
var $name = 'GroupUpdateAll';
var $useTable = 'group_update_all';
}
?>

View file

@ -706,6 +706,20 @@ class RouterTest extends CakeTestCase {
));
$expected = '/admin/shows/show_tickets/edit/6';
$this->assertEqual($result, $expected);
Router::reload();
Router::setRequestInfo(array(
array('pass' => array(), 'action' => 'admin_index', 'plugin' => null, 'controller' => 'posts', 'prefix' => 'admin', 'admin' => true, 'url' => array('url' => 'admin/posts')),
array('base' => '', 'here' => '/admin/posts', 'webroot' => '/')
));
Router::connect('/admin/posts/*', array('controller' => 'posts', 'action' => 'index', 'admin' => true));
Router::parse('/');
$result = Router::url(array('all'));
$expected = '/admin/posts/all';
$this->assertEqual($result, $expected);
}
/**

View file

@ -345,6 +345,21 @@ class SetTest extends CakeTestCase {
);
$a = Set::sort($a, '{n}.Person.name', 'ASC');
$this->assertIdentical($a, $b);
$names = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$result = Set::sort($names, '{n}.employees.0.name', 'asc', 1);
$expected = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$this->assertEqual($result, $expected);
}
/**
@ -1003,6 +1018,24 @@ class SetTest extends CakeTestCase {
$expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647'));
$r = Set::extract('/file/.[type=application/zip]', $f);
$this->assertEqual($r, $expected);
$hasMany = array(
'Node' => array(
'id' => 1,
'name' => 'First',
'state' => 50
),
'ParentNode' => array(
0 => array(
'id' => 2,
'name' => 'Second',
'state' => 60,
)
)
);
$result = Set::extract('/ParentNode/name', $hasMany);
$expected = array('Second');
$this->assertEqual($result, $expected);
}
/**

View file

@ -2331,14 +2331,14 @@ class FormHelperTest extends CakeTestCase {
}
/**
* testFieldError method
* testError method
*
* Test field error generation
*
* @access public
* @return void
*/
function testFieldError() {
function testError() {
$this->Form->validationErrors['Model']['field'] = 1;
$result = $this->Form->error('Model.field');
$this->assertTags($result, array('div' => array('class' => 'error-message'), 'Error in field Field', '/div'));
@ -2365,6 +2365,15 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->error('Model.field', "<strong>Badness!</strong>", array('wrap' => false, 'escape' => false));
$this->assertEqual($result, '<strong>Badness!</strong>');
$this->Form->validationErrors['Model']['field'] = "email";
$result = $this->Form->error('Model.field', array('class' => 'field-error', 'email' => 'No good!'));
$expected = array(
'div' => array('class' => 'field-error'),
'No good!',
'/div'
);
$this->assertTags($result, $expected);
}
/**
@ -3782,6 +3791,18 @@ class FormHelperTest extends CakeTestCase {
':',
);
$this->assertTags($result, $expected);
$result = $this->Form->input('published', array(
'timeFormat' => 24,
'interval' => 5,
'selected' => strtotime('2009-09-03 13:37:00'),
'type' => 'datetime'
));
$this->assertPattern('/<option[^<>]+value="2009"[^<>]+selected="selected"[^>]*>2009<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="09"[^<>]+selected="selected"[^>]*>September<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="03"[^<>]+selected="selected"[^>]*>3<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="13"[^<>]+selected="selected"[^>]*>13<\/option>/', $result);
$this->assertPattern('/<option[^<>]+value="35"[^<>]+selected="selected"[^>]*>35<\/option>/', $result);
}
/**

View file

@ -49,9 +49,9 @@ class AcoFixture extends CakeTestFixture {
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

View file

@ -50,8 +50,8 @@ class AcoTwoFixture extends CakeTestFixture {
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true, 'default' => 0),
'model' => array('type' => 'string', 'default' => ''),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

View file

@ -51,7 +51,7 @@ class AroFixture extends CakeTestFixture {
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

View file

@ -51,7 +51,7 @@ class AroTwoFixture extends CakeTestFixture {
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'parent_id' => array('type' => 'integer', 'length' => 10, 'null' => true),
'model' => array('type' => 'string', 'default' => ''),
'model' => array('type' => 'string', 'null' => true),
'foreign_key' => array('type' => 'integer', 'length' => 10, 'null' => true),
'alias' => array('type' => 'string', 'default' => ''),
'lft' => array('type' => 'integer', 'length' => 10, 'null' => true),

View file

@ -0,0 +1,31 @@
<?php
class GroupUpdateAllFixture extends CakeTestFixture {
var $name = 'GroupUpdateAll';
var $table = 'group_update_all';
var $fields = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'name' => array('type'=>'string', 'null' => false, 'length' => 29),
'code' => array('type'=>'integer', 'null' => false, 'length' => 4),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $records = array(
array(
'id' => 1,
'name' => 'group one',
'code' => 120),
array(
'id' => 2,
'name' => 'group two',
'code' => 125),
array(
'id' => 3,
'name' => 'group three',
'code' => 130),
array(
'id' => 4,
'name' => 'group four',
'code' => 135)
);
}
?>

View file

@ -0,0 +1,37 @@
<?php
class ProductUpdateAllFixture extends CakeTestFixture {
var $name = 'ProductUpdateAll';
var $table = 'product_update_all';
var $fields = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'),
'name' => array('type'=>'string', 'null' => false, 'length' => 29),
'groupcode' => array('type'=>'integer', 'null' => false, 'length' => 4),
'group_id' => array('type'=>'integer', 'null' => false, 'length' => 8),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
var $records = array(
array(
'id' => 1,
'name' => 'product one',
'groupcode' => 120,
'group_id' => 1
),
array(
'id' => 2,
'name' => 'product two',
'groupcode' => 120,
'group_id' => 1),
array(
'id' => 3,
'name' => 'product three',
'groupcode' => 125,
'group_id' => 2),
array(
'id' => 4,
'name' => 'product four',
'groupcode' => 135,
'group_id' => 4)
);
}
?>