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,9 +2012,9 @@ 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]);
}
}
}
}
}
return $return;
@ -2678,4 +2678,4 @@ class Model extends Overloadable {
if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
Overloadable::overload('Model');
}
?>
?>

View file

@ -38,31 +38,31 @@ App::import('Core', 'db_acl');
class AclPerson extends CakeTestModel {
/**
* name property
*
* @var string
*
* @var string
* @access public
*/
var $name = 'AclPerson';
/**
* useTable property
*
* @var string
*
* @var string
* @access public
*/
var $useTable = 'people';
/**
* actsAs property
*
*
* @var array
* @access public
*/
*/
var $actsAs = array('Acl' => 'requester');
/**
* belongsTo property
*
*
* @var array
* @access public
*/
*/
var $belongsTo = array(
'Mother' => array(
'className' => 'AclPerson',
@ -71,10 +71,10 @@ class AclPerson extends CakeTestModel {
);
/**
* hasMany property
*
*
* @var array
* @access public
*/
*/
var $hasMany = array(
'Child' => array(
'className' => 'AclPerson',
@ -86,7 +86,7 @@ class AclPerson extends CakeTestModel {
* ParentNode
*
* @return void
**/
**/
function parentNode() {
if (!$this->id && empty($this->data)) {
return null;
@ -94,14 +94,14 @@ class AclPerson extends CakeTestModel {
$data = $this->data;
if (empty($this->data)) {
$data = $this->read();
}
}
if (!$data['AclPerson']['mother_id']) {
return null;
} else {
return array('AclPerson' => array('id' => $data['AclPerson']['mother_id']));
}
}
}
}
/**
@ -113,30 +113,30 @@ class AclPerson extends CakeTestModel {
class AclUser extends CakeTestModel {
/**
* name property
*
* @var string
*
* @var string
* @access public
*/
var $name = 'User';
/**
* useTable property
*
* @var string
*
* @var string
* @access public
*/
var $useTable = 'users';
/**
* actsAs property
*
*
* @var array
* @access public
*/
*/
var $actsAs = array('Acl');
/**
* parentNode
*
* parentNode
*
* @access public
*/
*/
function parentNode() {
return null;
}
@ -151,30 +151,30 @@ class AclUser extends CakeTestModel {
class AclPost extends CakeTestModel {
/**
* name property
*
* @var string
*
* @var string
* @access public
*/
var $name = 'Post';
/**
* useTable property
*
* @var string
*
* @var string
* @access public
*/
var $useTable = 'posts';
/**
* actsAs property
*
*
* @var array
* @access public
*/
*/
var $actsAs = array('Acl' => 'controlled');
/**
* parentNode
*
* parentNode
*
* @access public
*/
*/
function parentNode() {
return null;
}
@ -196,11 +196,11 @@ 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();
}
/**
* Test Setup of AclBehavior
*
@ -211,13 +211,13 @@ class AclBehaviorTestCase extends CakeTestCase {
$this->assertTrue(isset($User->Behaviors->Acl->settings['User']));
$this->assertEqual($User->Behaviors->Acl->settings['User']['type'], 'requester');
$this->assertTrue(is_object($User->Aro));
$Post =& new AclPost();
$this->assertTrue(isset($Post->Behaviors->Acl->settings['Post']));
$this->assertEqual($Post->Behaviors->Acl->settings['Post']['type'], 'controlled');
$this->assertTrue(is_object($Post->Aco));
}
/**
* test After Save
*
@ -230,15 +230,15 @@ class AclBehaviorTestCase extends CakeTestCase {
'author_id' => 1,
'title' => 'Acl Post',
'body' => 'post body',
'published' => 1
),
'published' => 1
),
);
$Post->save($data);
$result = $this->Aco->find('first', array('conditions' => array('Aco.model' => 'Post', 'Aco.foreign_key' => $Post->id)));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aco']['model'], 'Post');
$this->assertEqual($result['Aco']['foreign_key'], $Post->id);
$aroData = array(
'Aro' => array(
'model' => 'AclPerson',
@ -247,7 +247,7 @@ class AclBehaviorTestCase extends CakeTestCase {
)
);
$this->Aro->save($aroData);
$Person =& new AclPerson();
$data = array(
'AclPerson' => array(
@ -255,18 +255,18 @@ class AclBehaviorTestCase extends CakeTestCase {
'mother_id' => 2,
'father_id' => 3,
),
);
);
$Person->save($data);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $Person->id)));
$this->assertTrue(is_array($result));
$this->assertEqual($result['Aro']['parent_id'], 5);
$node = $Person->node(array('model' => 'AclPerson', 'foreign_key' => 8));
$this->assertEqual(sizeof($node), 2);
$this->assertEqual($node[0]['Aro']['parent_id'], 5);
$this->assertEqual($node[1]['Aro']['parent_id'], null);
}
/**
* Test After Delete
*
@ -280,7 +280,7 @@ class AclBehaviorTestCase extends CakeTestCase {
'parent_id' => null
)
);
$this->Aro->save($aroData);
$this->Aro->save($aroData);
$Person =& new AclPerson();
$data = array(
'AclPerson' => array(
@ -288,38 +288,38 @@ class AclBehaviorTestCase extends CakeTestCase {
'mother_id' => 2,
'father_id' => 3,
),
);
$Person->save($data);
);
$Person->save($data);
$id = $Person->id;
$node = $Person->node();
$this->assertEqual(sizeof($node), 2);
$this->assertEqual($node[0]['Aro']['parent_id'], 5);
$this->assertEqual($node[1]['Aro']['parent_id'], null);
$Person->delete($id);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
$this->assertTrue(empty($result));
$this->assertTrue(empty($result));
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
$this->assertFalse(empty($result));
$data = array(
'AclPerson' => array(
'name' => 'Trent',
'mother_id' => 2,
'father_id' => 3,
),
);
);
$Person->save($data);
$id = $Person->id;
$Person->delete(2);
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => $id)));
$this->assertTrue(empty($result));
$this->assertTrue(empty($result));
$result = $this->Aro->find('first', array('conditions' => array('Aro.model' => 'AclPerson', 'Aro.foreign_key' => 2)));
$this->assertTrue(empty($result));
}
/**
* Test Node()
*
@ -335,13 +335,13 @@ class AclBehaviorTestCase extends CakeTestCase {
)
);
$this->Aro->save($aroData);
$Person->id = 2;
$result = $Person->node();
$this->assertTrue(is_array($result));
$this->assertEqual(sizeof($result), 1);
}
/**
* tear down test
*
@ -351,6 +351,6 @@ class AclBehaviorTestCase extends CakeTestCase {
ClassRegistry::flush();
unset($this->Aro, $this->Aco);
}
}
?>
?>

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,42 +318,20 @@ 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
*
* This class is defined purely to inherit the cacheSources variable otherwise testSchemaCreatTable will fail if
* This class is defined purely to inherit the cacheSources variable otherwise testSchemaCreatTable will fail if
* listSources has already been called and its source cache populated - I.e. if the test is run within a group
*
*
* @uses CakeTestModel
* @package
* @package
* @subpackage cake.tests.cases.libs.model
*/
class Testdescribe extends CakeTestModel {
/**
* name property
*
*
* @var string 'Testdescribe'
* @access public
*/
@ -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'));
@ -499,4 +478,4 @@ class CakeSchemaTest extends CakeTestCase {
unset($this->Schema);
}
}
?>
?>

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();
}
}
/**
@ -730,4 +737,4 @@ class CakeTestCase extends UnitTestCase {
}
}
}
?>
?>