Naming conventions to datasources with plugins. Fixes #819

This commit is contained in:
Juan Basso 2010-06-20 23:53:54 -03:00
parent a1911b4714
commit 2a4489cdf2
6 changed files with 147 additions and 2 deletions

View file

@ -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');
}

View file

@ -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']);
}
}

View file

@ -0,0 +1,27 @@
<?php
class Test2OtherSource extends DataSource {
function describe($model) {
return compact('model');
}
function listSources() {
return array('test_source');
}
function create($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function read($model, $queryData = array()) {
return compact('model', 'queryData');
}
function update($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function delete($model, $id) {
return compact('model', 'id');
}
}

View file

@ -0,0 +1,27 @@
<?php
class Test2Source extends DataSource {
function describe($model) {
return compact('model');
}
function listSources() {
return array('test_source');
}
function create($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function read($model, $queryData = array()) {
return compact('model', 'queryData');
}
function update($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function delete($model, $id) {
return compact('model', 'id');
}
}

View file

@ -0,0 +1,27 @@
<?php
class TestOtherSource extends DataSource {
function describe($model) {
return compact('model');
}
function listSources() {
return array('test_source');
}
function create($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function read($model, $queryData = array()) {
return compact('model', 'queryData');
}
function update($model, $fields = array(), $values = array()) {
return compact('model', 'fields', 'values');
}
function delete($model, $id) {
return compact('model', 'id');
}
}