From 2a4489cdf2b8c929cb79f9f4c63a8c85a370b8f8 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Sun, 20 Jun 2010 23:53:54 -0300 Subject: [PATCH] Naming conventions to datasources with plugins. Fixes #819 --- cake/libs/model/connection_manager.php | 7 ++- .../libs/model/connection_manager.test.php | 61 +++++++++++++++++++ cake/tests/test_app/models/datasources/empty | 0 .../models/datasources/test2_other_source.php | 27 ++++++++ .../models/datasources/test2_source.php | 27 ++++++++ .../models/datasources/test_other_source.php | 27 ++++++++ 6 files changed, 147 insertions(+), 2 deletions(-) delete mode 100644 cake/tests/test_app/models/datasources/empty create mode 100644 cake/tests/test_app/models/datasources/test2_other_source.php create mode 100644 cake/tests/test_app/models/datasources/test2_source.php create mode 100644 cake/tests/test_app/plugins/test_plugin/models/datasources/test_other_source.php diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index af3365be3..723ad0994 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -272,9 +272,12 @@ class ConnectionManager extends Object { if ($plugin) { $filename = Inflector::underscore($classname); } else { - $filename = $config['datasource'] . '_source'; - $classname = Inflector::camelize(strtolower($filename)); + $filename = Inflector::underscore($config['datasource']); } + if (substr($filename, -7) != '_source') { + $filename .= '_source'; + } + $classname = Inflector::camelize(strtolower($filename)); } return compact('filename', 'classname', 'parent', 'plugin'); } diff --git a/cake/tests/cases/libs/model/connection_manager.test.php b/cake/tests/cases/libs/model/connection_manager.test.php index 049ad5276..e100a7bf3 100644 --- a/cake/tests/cases/libs/model/connection_manager.test.php +++ b/cake/tests/cases/libs/model/connection_manager.test.php @@ -276,4 +276,65 @@ class ConnectionManagerTest extends CakeTestCase { $source = ConnectionManager::create(null, $config); $this->assertEqual($source, null); } + +/** + * testConnectionData method + * + * @access public + * @return void + */ + function testConnectionData() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS), + 'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS) + )); + + $expected = array( + 'filename' => 'test2_source', + 'classname' => 'Test2Source', + 'parent' => '', + 'plugin' => '' + ); + + ConnectionManager::create('connection1', array('datasource' => 'Test2')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection1']); + + ConnectionManager::create('connection2', array('datasource' => 'Test2Source')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection2']); + + ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.Test')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test_source'; + $expected['classname'] = 'TestSource'; + $expected['plugin'] = 'TestPlugin'; + $this->assertEqual($expected, $connections['connection3']); + + ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection4']); + + ConnectionManager::create('connection5', array('datasource' => 'Test2Other')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test2_other_source'; + $expected['classname'] = 'Test2OtherSource'; + $expected['plugin'] = ''; + $this->assertEqual($expected, $connections['connection5']); + + ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection6']); + + ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOther')); + $connections = ConnectionManager::enumConnectionObjects(); + $expected['filename'] = 'test_other_source'; + $expected['classname'] = 'TestOtherSource'; + $expected['plugin'] = 'TestPlugin'; + $this->assertEqual($expected, $connections['connection7']); + + ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource')); + $connections = ConnectionManager::enumConnectionObjects(); + $this->assertEqual($expected, $connections['connection8']); + } } diff --git a/cake/tests/test_app/models/datasources/empty b/cake/tests/test_app/models/datasources/empty deleted file mode 100644 index e69de29bb..000000000 diff --git a/cake/tests/test_app/models/datasources/test2_other_source.php b/cake/tests/test_app/models/datasources/test2_other_source.php new file mode 100644 index 000000000..d5743f606 --- /dev/null +++ b/cake/tests/test_app/models/datasources/test2_other_source.php @@ -0,0 +1,27 @@ +