From 2279b1a736ca772622aa63f809b54b5368805857 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 16 Feb 2010 22:35:16 -0500 Subject: [PATCH 1/2] Adding patches, and tests from tkykmw. Add support for plugin datasource drivers. Fixes #297 --- cake/libs/model/connection_manager.php | 14 ++-- .../libs/model/connection_manager.test.php | 71 +++++++++++++++++++ .../datasources/test/test_local_driver.php | 6 ++ .../models/datasources/dbo/dbo_dummy.php | 9 +++ .../models/datasources/test/test_driver.php | 6 ++ 5 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 cake/tests/test_app/models/datasources/test/test_local_driver.php create mode 100644 cake/tests/test_app/plugins/test_plugin/models/datasources/dbo/dbo_dummy.php create mode 100644 cake/tests/test_app/plugins/test_plugin/models/datasources/test/test_driver.php diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 4de4d406d..4ce71ab38 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -256,11 +256,17 @@ class ConnectionManager extends Object { $filename = $classname = $parent = $plugin = null; if (!empty($config['driver'])) { - $source = $config['datasource'] . '_' . $config['driver']; - - $filename = $config['datasource'] . DS . $source; - $classname = Inflector::camelize(strtolower($source)); $parent = $this->__connectionData(array('datasource' => $config['datasource'])); + $parentSource = preg_replace('/_source$/', '', $parent['filename']); + + if (strpos($config['driver'], '.') !== false) { + list($plugin, $classname) = explode('.', $config['driver']); + $source = Inflector::underscore($classname); + } else { + $source = $parentSource . '_' . $config['driver']; + $classname = Inflector::camelize(strtolower($source)); + } + $filename = $parentSource . DS . $source; } else { if (strpos($config['datasource'], '.') !== false) { list($plugin, $classname) = explode('.', $config['datasource']); diff --git a/cake/tests/cases/libs/model/connection_manager.test.php b/cake/tests/cases/libs/model/connection_manager.test.php index 5c2530ec2..a4336a28a 100644 --- a/cake/tests/cases/libs/model/connection_manager.test.php +++ b/cake/tests/cases/libs/model/connection_manager.test.php @@ -113,6 +113,77 @@ class ConnectionManagerTest extends CakeTestCase { App::build(); } +/** + * testGetPluginDataSourceAndPluginDriver method + * + * @access public + * @return void + */ + function testGetPluginDataSourceAndPluginDriver() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + )); + + $name = 'test_plugin_source_and_driver'; + $config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'TestPlugin.TestDriver'); + + $connection = ConnectionManager::create($name, $config); + + $this->assertTrue(class_exists('TestSource')); + $this->assertTrue(class_exists('TestDriver')); + $this->assertEqual($connection->configKeyName, $name); + $this->assertEqual($connection->config, $config); + + App::build(); + } + +/** + * testGetLocalDataSourceAndPluginDriver method + * + * @access public + * @return void + */ + function testGetLocalDataSourceAndPluginDriver() { + App::build(array( + 'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS) + )); + + $name = 'test_local_source_and_plugin_driver'; + $config = array('datasource' => 'dbo', 'driver' => 'TestPlugin.DboDummy'); + + $connection = ConnectionManager::create($name, $config); + + $this->assertTrue(class_exists('DboSource')); + $this->assertTrue(class_exists('DboDummy')); + $this->assertEqual($connection->configKeyName, $name); + + App::build(); + } + +/** + * testGetPluginDataSourceAndLocalDriver method + * + * @access public + * @return void + */ + function testGetPluginDataSourceAndLocalDriver() { + 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) + )); + + $name = 'test_plugin_source_and_local_driver'; + $config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'local_driver'); + + $connection = ConnectionManager::create($name, $config); + + $this->assertTrue(class_exists('TestSource')); + $this->assertTrue(class_exists('TestLocalDriver')); + $this->assertEqual($connection->configKeyName, $name); + $this->assertEqual($connection->config, $config); + App::build(); + } + /** * testSourceList method * diff --git a/cake/tests/test_app/models/datasources/test/test_local_driver.php b/cake/tests/test_app/models/datasources/test/test_local_driver.php new file mode 100644 index 000000000..fe9c9fdd3 --- /dev/null +++ b/cake/tests/test_app/models/datasources/test/test_local_driver.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/cake/tests/test_app/plugins/test_plugin/models/datasources/dbo/dbo_dummy.php b/cake/tests/test_app/plugins/test_plugin/models/datasources/dbo/dbo_dummy.php new file mode 100644 index 000000000..aee12a17a --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/models/datasources/dbo/dbo_dummy.php @@ -0,0 +1,9 @@ + \ No newline at end of file diff --git a/cake/tests/test_app/plugins/test_plugin/models/datasources/test/test_driver.php b/cake/tests/test_app/plugins/test_plugin/models/datasources/test/test_driver.php new file mode 100644 index 000000000..beae8d0b6 --- /dev/null +++ b/cake/tests/test_app/plugins/test_plugin/models/datasources/test/test_driver.php @@ -0,0 +1,6 @@ + \ No newline at end of file From eb96f4ac3a60b0354baf9c396ebf5d9fb236fb0a Mon Sep 17 00:00:00 2001 From: Mark Story Date: Tue, 16 Feb 2010 22:42:06 -0500 Subject: [PATCH 2/2] Minor refactor of ConnectionManager::__connectionData(). Uses pluginSplit() now to consolidate plugin dot notation handling. --- cake/libs/model/connection_manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cake/libs/model/connection_manager.php b/cake/libs/model/connection_manager.php index 4ce71ab38..a0c9174d3 100644 --- a/cake/libs/model/connection_manager.php +++ b/cake/libs/model/connection_manager.php @@ -259,8 +259,8 @@ class ConnectionManager extends Object { $parent = $this->__connectionData(array('datasource' => $config['datasource'])); $parentSource = preg_replace('/_source$/', '', $parent['filename']); - if (strpos($config['driver'], '.') !== false) { - list($plugin, $classname) = explode('.', $config['driver']); + list($plugin, $classname) = pluginSplit($config['driver']); + if ($plugin) { $source = Inflector::underscore($classname); } else { $source = $parentSource . '_' . $config['driver']; @@ -268,8 +268,8 @@ class ConnectionManager extends Object { } $filename = $parentSource . DS . $source; } else { - if (strpos($config['datasource'], '.') !== false) { - list($plugin, $classname) = explode('.', $config['datasource']); + list($plugin, $classname) = pluginSplit($config['datasource']); + if ($plugin) { $filename = Inflector::underscore($classname); } else { $filename = $config['datasource'] . '_source';