Skip to content
Permalink
Browse files

Naming conventions to datasources with plugins. Fixes #819

  • Loading branch information...
jrbasso committed Jun 21, 2010
1 parent a1911b4 commit 2a4489cdf2b8c929cb79f9f4c63a8c85a370b8f8
@@ -272,9 +272,12 @@ function __connectionData($config) {
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');
}
@@ -276,4 +276,65 @@ function testCreateDataSourceWithIntegrationTests() {
$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']);
}
}
@@ -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');
}
}
@@ -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');
}
}
@@ -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');
}
}

0 comments on commit 2a4489c

Please sign in to comment.
You can’t perform that action at this time.