Enabling plugin.name schema file creation and addition.

Making CakeSchema::load() use plugin parameter, tests added.
Plugin schema file added to test_app.
This commit is contained in:
mark_story 2009-10-04 13:32:33 -04:00
parent c2a53d3c69
commit 05f6099def
5 changed files with 94 additions and 17 deletions

View file

@ -63,10 +63,12 @@ class SchemaShell extends Shell {
$name = $this->params['name'];
$this->params['file'] = Inflector::underscore($name);
}
$path = $this->_getPath();
if (empty($this->params['file'])) {
$this->params['file'] = 'schema.php';
}
if (!empty($this->params['path'])) {
$path = $this->params['path'];
}
if (strpos($this->params['file'], '.php') === false) {
$this->params['file'] .= '.php';
}
@ -263,20 +265,23 @@ class SchemaShell extends Shell {
* @return void
**/
function _loadSchema() {
$name = null;
$name = $plugin = null;
if (isset($this->args[0])) {
$name = $this->args[0];
}
if (isset($this->params['name'])) {
$name = $this->params['name'];
}
if (strpos($name, '.') !== false) {
list($plugin, $name) = explode('.', $name);
}
if (isset($this->params['dry'])) {
$this->__dry = true;
$this->out(__('Performing a dry run.', true));
}
$options = array('name' => $name);
$options = array('name' => $name, 'plugin' => $plugin);
if (isset($this->params['s'])) {
$fileName = rtrim($this->Schema->file, '.php');
$options['file'] = $fileName . '_' . $this->params['s'] . '.php';
@ -285,7 +290,7 @@ class SchemaShell extends Shell {
$Schema =& $this->Schema->load($options);
if (!$Schema) {
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->path . DS . $this->Schema->file));
$this->_stop();
}
$table = null;

View file

@ -133,9 +133,10 @@ class CakeSchema extends Object {
}
}
}
if (file_exists($this->path . DS . $file) && is_file($this->path . DS . $file)) {
$this->file = $file;
} elseif (!empty($this->plugin)) {
$this->path = App::pluginPath($this->plugin) . 'config' . DS . 'schema';
}
}

View file

@ -366,19 +366,35 @@ class SchemaShellTest extends CakeTestCase {
'connection' => 'test_suite'
);
$this->Shell->startup();
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema' . DS;
$this->assertEqual($this->Shell->Schema->path, $expected);
unset($this->Shell->Schema);
$this->Shell->params = array(
'plugin' => 'TestPlugin',
'connection' => 'test_suite',
'path' => '/some/path'
);
$this->Shell->startup();
$expected = '/some/path';
$expected = TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS . 'test_plugin' . DS . 'config' . DS . 'schema';
$this->assertEqual($this->Shell->Schema->path, $expected);
App::build();
}
/**
* test that using Plugin.name with write.
*
* @return void
**/
function testPluginDotSyntax() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$this->Shell->params = array(
'connection' => 'test_suite'
);
$this->Shell->args = array('TestPlugin.TestPluginApp');
$this->Shell->startup();
$this->Shell->setReturnValue('in', 'y');
$this->Shell->create();
$db =& ConnectionManager::getDataSource('test_suite');
$sources = $db->listSources();
$this->assertTrue(in_array($db->config['prefix'] . 'acos', $sources));
$db->execute('DROP TABLE ' . $db->config['prefix'] . 'acos');
App::build();
}
}
?>

View file

@ -574,11 +574,27 @@ class CakeSchemaTest extends CakeTestCase {
* @return void
*/
function testSchemaLoading() {
$Other = $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
$Other =& $this->Schema->load(array('name' => 'MyOtherApp', 'path' => TMP . 'tests'));
$this->assertEqual($Other->name, 'MyOtherApp');
$this->assertEqual($Other->tables, $this->Schema->tables);
}
/**
* test loading schema files inside of plugins.
*
* @return void
**/
function testSchemaLoadingFromPlugin() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$Other =& $this->Schema->load(array('name' => 'TestPluginApp', 'plugin' => 'TestPlugin'));
$this->assertEqual($Other->name, 'TestPluginApp');
$this->assertEqual(array_keys($Other->tables), array('acos'));
App::build();
}
/**
* testSchemaCreateTable method
*

View file

@ -0,0 +1,39 @@
<?php
/**
* TestAppSchema file
*
* Use for testing the loading of schema files from plugins.
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.app.config.sql
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
class TestPluginAppSchema extends CakeSchema {
var $name = 'TestPluginApp';
var $acos = array(
'id' => array('type'=>'integer', 'null' => false, 'default' => NULL, 'length' => 10, 'key' => 'primary'),
'parent_id' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'model' => array('type'=>'string', 'null' => true),
'foreign_key' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'alias' => array('type'=>'string', 'null' => true),
'lft' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'rght' => array('type'=>'integer', 'null' => true, 'default' => NULL, 'length' => 10),
'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1))
);
}
?>