diff --git a/cake/libs/class_registry.php b/cake/libs/class_registry.php index 8fdd4656b..3e2ced4b6 100644 --- a/cake/libs/class_registry.php +++ b/cake/libs/class_registry.php @@ -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 diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 87375bacb..5ac2d0eb5 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -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 { } } } - ?> \ No newline at end of file diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index cd04395da..38c66ca57 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -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. diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index a68757cc1..2744f1f08 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -511,7 +511,7 @@ class DboSource extends DataSource { } else { $out = ("[Aff:{$this->affected} Num:{$this->numRows} Took:{$this->took}ms]"); } - e(sprintf("
Query: %s %s
", $sql, $out)); + pr(sprintf("Query: %s %s
", $sql, $out)); } } /** @@ -2412,5 +2412,4 @@ class DboSource extends DataSource { return 'string'; } } - -?> +?> \ No newline at end of file diff --git a/cake/libs/model/model.php b/cake/libs/model/model.php index c4a17ec7b..6977bf597 100644 --- a/cake/libs/model/model.php +++ b/cake/libs/model/model.php @@ -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'); } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/behaviors/acl.test.php b/cake/tests/cases/libs/model/behaviors/acl.test.php index fdb360af0..3b9f298b1 100644 --- a/cake/tests/cases/libs/model/behaviors/acl.test.php +++ b/cake/tests/cases/libs/model/behaviors/acl.test.php @@ -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); } - + } -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/datasources/dbo_source.test.php b/cake/tests/cases/libs/model/datasources/dbo_source.test.php index 4ab9013c8..4077cf577 100644 --- a/cake/tests/cases/libs/model/datasources/dbo_source.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo_source.test.php @@ -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); } -} +} ?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/model.test.php b/cake/tests/cases/libs/model/model.test.php index 7127bf184..292bbf092 100644 --- a/cake/tests/cases/libs/model/model.test.php +++ b/cake/tests/cases/libs/model/model.test.php @@ -5556,5 +5556,4 @@ class ModelTest extends CakeTestCase { ClassRegistry::flush(); } } - -?> +?> \ No newline at end of file diff --git a/cake/tests/cases/libs/model/schema.test.php b/cake/tests/cases/libs/model/schema.test.php index 6b5e4aa95..d1969579d 100644 --- a/cake/tests/cases/libs/model/schema.test.php +++ b/cake/tests/cases/libs/model/schema.test.php @@ -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); } } -?> +?> \ No newline at end of file diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index 186fce9a1..2646aa99c 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -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 { } } } -?> +?> \ No newline at end of file