making changes to all the model group to run. Currently I get 8/8 test cases complete: 1486 passes, 22 fails and 3 exceptions.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7439 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-08-07 15:36:26 +00:00
parent 99e3b11a61
commit 76f7d6dc43
10 changed files with 111 additions and 124 deletions

View file

@ -116,7 +116,6 @@ class ClassRegistry {
if (is_array($settings)) {
$plugin = null;
$settings = array_merge($defaults, $settings);
extract($settings, EXTR_OVERWRITE);
if (strpos($class, '.') !== false) {
@ -128,9 +127,9 @@ class ClassRegistry {
$alias = $class;
}
if ($_this->_duplicate($alias, $class) && $count == 1) {
if ($model =& $_this->_duplicate($alias, $class)) {
$_this->map($alias, $class);
return $_this->getObject($alias);
return $model;
}
if ($type === 'Model') {
@ -236,7 +235,6 @@ class ClassRegistry {
function &getObject($key) {
$_this =& ClassRegistry::getInstance();
$key = Inflector::underscore($key);
if (isset($_this->__objects[$key])) {
return $_this->__objects[$key];
} else {
@ -282,18 +280,17 @@ class ClassRegistry {
function _duplicate($alias, $class) {
$_this =& ClassRegistry::getInstance();
$duplicate = false;
if ($_this->isKeySet($alias)) {
$model = $_this->getObject($alias);
if (is_a($model, $class)) {
$duplicate = true;
$model =& $_this->getObject($alias);
if ($model->name === $class) {
$duplicate =& $model;
}
unset($model);
}
return $duplicate;
}
/**
* Add a key name pair to the registry to map name to class in the regisrty.
* Add a key name pair to the registry to map name to class in the registry.
*
* @param string $key Key to include in map
* @param string $name Key that is being mapped

View file

@ -98,12 +98,13 @@ class ConnectionManager extends Object {
function &getDataSource($name) {
$_this =& ConnectionManager::getInstance();
if (in_array($name, array_keys($_this->_dataSources))) {
return $_this->_dataSources[$name];
if (!empty($_this->_dataSources[$name])) {
$return =& $_this->_dataSources[$name];
return $return;
}
$connections = $_this->enumConnectionObjects();
if (in_array($name, array_keys($connections))) {
if (!empty($connections[$name])) {
$conn = $connections[$name];
$class = $conn['classname'];
$_this->loadDataSource($name);
@ -114,7 +115,8 @@ class ConnectionManager extends Object {
return null;
}
return $_this->_dataSources[$name];
$return =& $_this->_dataSources[$name];
return $return;
}
/**
* Gets the list of available DataSource connections
@ -164,7 +166,7 @@ class ConnectionManager extends Object {
$conn = $connections[$connName];
}
if (isset($conn['parent']) && !empty($conn['parent'])) {
if (!empty($conn['parent'])) {
$_this->loadDataSource($conn['parent']);
}
@ -225,7 +227,8 @@ class ConnectionManager extends Object {
$_this->config->{$name} = $config;
$_this->_connectionsEnum[$name] = $_this->__getDriver($config);
return $_this->getDataSource($name);
$return =& $_this->getDataSource($name);
return $return;
}
/**
* Returns the file, class name, and parent for the given driver.
@ -262,5 +265,4 @@ class ConnectionManager extends Object {
}
}
}
?>

View file

@ -193,7 +193,8 @@ class DataSource extends Object {
if ($this->cacheSources === false) {
return null;
}
if ($this->_sources != null) {
if ($this->_sources !== null) {
return $this->_sources;
}
@ -213,9 +214,11 @@ class DataSource extends Object {
*
* @return array
*/
function sources() {
$return = array_map('strtolower', $this->listSources());
return $return;
function sources($reset = false) {
if ($reset === true) {
$this->_sources = null;
}
return array_map('strtolower', $this->listSources());
}
/**
* Returns a Model description (metadata) or null if none found.

View file

@ -511,7 +511,7 @@ class DboSource extends DataSource {
} else {
$out = ("<small>[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]</small>");
}
e(sprintf("<p style = \"text-align:left\"><b>Query:</b> %s %s</p>", $sql, $out));
pr(sprintf("<p style = \"text-align:left\"><b>Query:</b> %s %s</p>", $sql, $out));
}
}
/**
@ -2412,5 +2412,4 @@ class DboSource extends DataSource {
return 'string';
}
}
?>

View file

@ -2012,7 +2012,7 @@ class Model extends Overloadable {
$root = $return[0][$this->alias]['parent_id'];
foreach ($return as $key => $value) {
if ($value[$this->alias]['parent_id'] != $root) {
unset ($return[$key]);
unset($return[$key]);
}
}
}

View file

@ -197,8 +197,8 @@ class AclBehaviorTestCase extends CakeTestCase {
function startTest() {
Configure::write('Acl.database', 'test_suite');
$this->Aco = new Aco();
$this->Aro = new Aro();
$this->Aco =& new Aco();
$this->Aro =& new Aro();
}
/**

View file

@ -1169,6 +1169,7 @@ class DboSourceTest extends CakeTestCase {
}
$this->testDb =& new DboTest($this->__config);
$this->testDb->cacheSources = false;
Configure::write('debug', 1);
$this->debug = Configure::read('debug');
$this->Model =& new TestModel();
@ -3489,17 +3490,17 @@ class DboSourceTest extends CakeTestCase {
$Apple =& ClassRegistry::init('Apple');
$Article =& ClassRegistry::init('Article');
$result = $this->db->rawQuery('SELECT color, name FROM ' . $this->testDb->fullTableName('apples'));
$result = $this->testDb->rawQuery('SELECT color, name FROM ' . $this->testDb->fullTableName('apples'));
$this->assertTrue(!empty($result));
$result = $this->db->fetchRow($result);
$result = $this->testDb->fetchRow($result);
$expected = array($this->testDb->fullTableName('apples', false) => array(
'color' => 'Red 1',
'name' => 'Red Apple 1'
));
$this->assertEqual($result, $expected);
$result = $this->db->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$result = $this->testDb->fetchAll('SELECT name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$expected = array(
array($this->testDb->fullTableName('apples', false) => array('name' => 'Red Apple 1')),
array($this->testDb->fullTableName('apples', false) => array('name' => 'Bright Red Apple')),
@ -3511,7 +3512,7 @@ class DboSourceTest extends CakeTestCase {
);
$this->assertEqual($result, $expected);
$result = $this->db->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$result = $this->testDb->field($this->testDb->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->testDb->fullTableName('apples') . ' ORDER BY id');
$expected = array(
'color' => 'Red 1',
'name' => 'Red Apple 1'
@ -3519,7 +3520,7 @@ class DboSourceTest extends CakeTestCase {
$this->assertEqual($result, $expected);
$Apple->unbindModel(array(), false);
$result = $this->db->read($Apple, array(
$result = $this->testDb->read($Apple, array(
'fields' => array($Apple->escapeField('name')),
'conditions' => null,
'recursive' => -1
@ -3535,7 +3536,7 @@ class DboSourceTest extends CakeTestCase {
);
$this->assertEqual($result, $expected);
$result = $this->db->read($Article, array(
$result = $this->testDb->read($Article, array(
'fields' => array('id', 'user_id', 'title'),
'conditions' => null,
'recursive' => 1
@ -3629,6 +3630,6 @@ class DboSourceTest extends CakeTestCase {
$this->testDb->error = $oldError;
Configure::write('debug', $oldDebug);
}
}
}
?>

View file

@ -5556,5 +5556,4 @@ class ModelTest extends CakeTestCase {
ClassRegistry::flush();
}
}
?>

View file

@ -318,28 +318,6 @@ class SchemaDatatype extends CakeTestModel {
*/
var $useTable = 'datatypes';
}
/**
* PostsTag class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class PostsTag extends CakeTestModel {
/**
* name property
*
* @var string 'PostsTag'
* @access public
*/
var $name = 'PostsTag';
/**
* useTable property
*
* @var string 'posts_tags'
* @access public
*/
var $useTable = 'posts_tags';
}
/**
* Testdescribe class
*
@ -417,7 +395,6 @@ class CakeSchemaTest extends CakeTestCase {
* @return void
*/
function testSchemaWrite() {
$write = $this->Schema->write(array('name' => 'MyOtherApp', 'tables' => $this->Schema->tables, 'path' => TMP . 'tests'));
$file = file_get_contents(TMP . 'tests' . DS .'schema.php');
$this->assertEqual($write, $file);
@ -475,6 +452,8 @@ class CakeSchemaTest extends CakeTestCase {
*/
function testSchemaCreateTable() {
$db =& ConnectionManager::getDataSource('test_suite');
$db->cacheSources = false;
$db->query('CREATE TABLE ' . $db->fullTableName('testdescribes') . ' (id int(11) AUTO_INCREMENT, int_null int(10) unsigned NULL, int_not_null int(10) unsigned NOT NULL, primary key(id));');
$Schema =& new CakeSchema(array('connection' => 'test_suite'));

View file

@ -371,6 +371,7 @@ class CakeTestCase extends UnitTestCase {
*/
function start() {
if (isset($this->_fixtures) && isset($this->db)) {
Configure::write('Cache.disable', true);
$cacheSources = $this->db->cacheSources;
$this->db->cacheSources = false;
$sources = $this->db->listSources();
@ -395,6 +396,12 @@ class CakeTestCase extends UnitTestCase {
foreach (array_reverse($this->_fixtures) as $fixture) {
$fixture->drop($this->db);
}
$this->db->sources(true);
Configure::write('Cache.disable', false);
}
if (class_exists('ClassRegistry')) {
ClassRegistry::flush();
}
}
/**