mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding patches, and tests from tkykmw. Add support for plugin datasource drivers. Fixes #297
This commit is contained in:
parent
e1eb827ee8
commit
2279b1a736
5 changed files with 102 additions and 4 deletions
|
@ -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']);
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class TestLocalDriver extends TestSource {
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
class DboDummy extends DboSource {
|
||||
function connect() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
class TestDriver extends TestSource {
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue