Skip to content
This repository
Browse code

Adding patches, and tests from tkykmw. Add support for plugin datasou…

…rce drivers. Fixes #297
  • Loading branch information...
commit 2279b1a736ca772622aa63f809b54b5368805857 1 parent e1eb827
Mark Story authored
14  cake/libs/model/connection_manager.php
@@ -256,11 +256,17 @@ function __connectionData($config) {
256 256
 		$filename = $classname = $parent = $plugin = null;
257 257
 
258 258
 		if (!empty($config['driver'])) {
259  
-			$source = $config['datasource'] . '_' . $config['driver'];
260  
-
261  
-			$filename = $config['datasource'] . DS . $source;
262  
-			$classname = Inflector::camelize(strtolower($source));
263 259
 			$parent = $this->__connectionData(array('datasource' => $config['datasource']));
  260
+			$parentSource = preg_replace('/_source$/', '', $parent['filename']);
  261
+
  262
+			if (strpos($config['driver'], '.') !== false) {
  263
+				list($plugin, $classname) = explode('.', $config['driver']);
  264
+				$source = Inflector::underscore($classname);
  265
+			} else {
  266
+				$source = $parentSource . '_' . $config['driver'];
  267
+				$classname = Inflector::camelize(strtolower($source));
  268
+			}
  269
+			$filename = $parentSource . DS . $source;
264 270
 		} else {
265 271
 			if (strpos($config['datasource'], '.') !== false) {
266 272
 				list($plugin, $classname) = explode('.', $config['datasource']);
71  cake/tests/cases/libs/model/connection_manager.test.php
@@ -114,6 +114,77 @@ function testGetPluginDataSource() {
114 114
 	}
115 115
 
116 116
 /**
  117
+ * testGetPluginDataSourceAndPluginDriver method
  118
+ *
  119
+ * @access public
  120
+ * @return void
  121
+ */
  122
+	function testGetPluginDataSourceAndPluginDriver() {
  123
+		App::build(array(
  124
+			'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  125
+		));
  126
+
  127
+		$name = 'test_plugin_source_and_driver';
  128
+		$config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'TestPlugin.TestDriver');
  129
+
  130
+		$connection = ConnectionManager::create($name, $config);
  131
+
  132
+		$this->assertTrue(class_exists('TestSource'));
  133
+		$this->assertTrue(class_exists('TestDriver'));
  134
+		$this->assertEqual($connection->configKeyName, $name);
  135
+		$this->assertEqual($connection->config, $config);
  136
+
  137
+		App::build();
  138
+	}
  139
+
  140
+/**
  141
+ * testGetLocalDataSourceAndPluginDriver method
  142
+ *
  143
+ * @access public
  144
+ * @return void
  145
+ */
  146
+	function testGetLocalDataSourceAndPluginDriver() {
  147
+		App::build(array(
  148
+			'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
  149
+		));
  150
+
  151
+		$name = 'test_local_source_and_plugin_driver';
  152
+		$config = array('datasource' => 'dbo', 'driver' => 'TestPlugin.DboDummy');
  153
+
  154
+		$connection = ConnectionManager::create($name, $config);
  155
+
  156
+		$this->assertTrue(class_exists('DboSource'));
  157
+		$this->assertTrue(class_exists('DboDummy'));
  158
+		$this->assertEqual($connection->configKeyName, $name);
  159
+
  160
+		App::build();
  161
+	}
  162
+
  163
+/**
  164
+ * testGetPluginDataSourceAndLocalDriver method
  165
+ *
  166
+ * @access public
  167
+ * @return void
  168
+ */
  169
+	function testGetPluginDataSourceAndLocalDriver() {
  170
+		App::build(array(
  171
+			'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
  172
+			'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS)
  173
+		));
  174
+
  175
+		$name = 'test_plugin_source_and_local_driver';
  176
+		$config = array('datasource' => 'TestPlugin.TestSource', 'driver' => 'local_driver');
  177
+
  178
+		$connection = ConnectionManager::create($name, $config);
  179
+
  180
+		$this->assertTrue(class_exists('TestSource'));
  181
+		$this->assertTrue(class_exists('TestLocalDriver'));
  182
+		$this->assertEqual($connection->configKeyName, $name);
  183
+		$this->assertEqual($connection->config, $config);
  184
+		App::build();
  185
+	}
  186
+
  187
+/**
117 188
  * testSourceList method
118 189
  *
119 190
  * @access public
6  cake/tests/test_app/models/datasources/test/test_local_driver.php
... ...
@@ -0,0 +1,6 @@
  1
+<?php
  2
+
  3
+class TestLocalDriver extends TestSource {
  4
+}
  5
+
  6
+?>
9  cake/tests/test_app/plugins/test_plugin/models/datasources/dbo/dbo_dummy.php
... ...
@@ -0,0 +1,9 @@
  1
+<?php
  2
+
  3
+class DboDummy extends DboSource {
  4
+	function connect() {
  5
+		return true;
  6
+	}
  7
+}
  8
+
  9
+?>
6  cake/tests/test_app/plugins/test_plugin/models/datasources/test/test_driver.php
... ...
@@ -0,0 +1,6 @@
  1
+<?php
  2
+
  3
+class TestDriver extends TestSource {
  4
+}
  5
+
  6
+?>

0 notes on commit 2279b1a

Please sign in to comment.
Something went wrong with that request. Please try again.