Merge branch '1.3-console' into 1.3

Conflicts:
	cake/tests/cases/console/libs/schema.test.php
This commit is contained in:
mark_story 2009-09-20 19:05:03 -04:00
commit 42017e95c6
3 changed files with 56 additions and 15 deletions

View file

@ -58,18 +58,12 @@ class SchemaShell extends Shell {
* @access public * @access public
*/ */
function startup() { function startup() {
$name = null; $name = $file = $path = $connection = null;
if (!empty($this->params['name'])) { if (!empty($this->params['name'])) {
$name = $this->params['name']; $name = $this->params['name'];
$this->params['file'] = Inflector::underscore($name); $this->params['file'] = Inflector::underscore($name);
} }
$path = $this->_getPath();
$path = null;
if (!empty($this->params['path'])) {
$path = $this->params['path'];
}
$file = null;
if (empty($this->params['file'])) { if (empty($this->params['file'])) {
$this->params['file'] = 'schema.php'; $this->params['file'] = 'schema.php';
} }
@ -78,7 +72,6 @@ class SchemaShell extends Shell {
} }
$file = $this->params['file']; $file = $this->params['file'];
$connection = null;
if (!empty($this->params['connection'])) { if (!empty($this->params['connection'])) {
$connection = $this->params['connection']; $connection = $this->params['connection'];
} }
@ -86,6 +79,23 @@ class SchemaShell extends Shell {
$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection')); $this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection'));
} }
/**
* Get the correct path for the params. Uses path, and plugin to find the correct path.
* path param takes precedence over any plugins specified.
*
* @return mixed string to correct path or null.
**/
function _getPath() {
if (!empty($this->params['path'])) {
return $this->params['path'];
}
if (!empty($this->params['plugin'])) {
$pluginPath = $this->_pluginPath($this->params['plugin']);
return $pluginPath . 'config' . DS . 'schema' . DS;
}
return null;
}
/** /**
* Override main * Override main
* *
@ -107,7 +117,8 @@ class SchemaShell extends Shell {
$this->out($File->read()); $this->out($File->read());
$this->_stop(); $this->_stop();
} else { } else {
$this->err(__('Schema could not be found', true)); $file = $this->Schema->path . DS . $this->params['file'];
$this->err(sprintf(__('Schema file (%s) could not be found.', true), $file));
$this->_stop(); $this->_stop();
} }
} }

View file

@ -90,7 +90,11 @@ class CakeSchema extends Object {
} }
if (empty($options['path'])) { if (empty($options['path'])) {
$this->path = CONFIGS . 'schema'; if (is_dir(CONFIGS . 'schema')) {
$this->path = CONFIGS . 'schema';
} else {
$this->path = CONFIGS . 'sql';
}
} }
$options = array_merge(get_object_vars($this), $options); $options = array_merge(get_object_vars($this), $options);
@ -239,8 +243,6 @@ class CakeSchema extends Object {
foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) { foreach ($Object->hasAndBelongsToMany as $Assoc => $assocData) {
if (isset($assocData['with'])) { if (isset($assocData['with'])) {
$class = $assocData['with']; $class = $assocData['with'];
} elseif ($assocData['_with']) {
$class = $assocData['_with'];
} }
if (is_object($Object->$class)) { if (is_object($Object->$class)) {
$table = $db->fullTableName($Object->$class, false); $table = $db->fullTableName($Object->$class, false);

View file

@ -148,7 +148,7 @@ class SchemaShellTest extends CakeTestCase {
$this->Shell->startup(); $this->Shell->startup();
$this->assertTrue(isset($this->Shell->Schema)); $this->assertTrue(isset($this->Shell->Schema));
$this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema')); $this->assertTrue(is_a($this->Shell->Schema, 'CakeSchema'));
$this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR); $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
$this->assertEqual($this->Shell->Schema->file, 'schema.php'); $this->assertEqual($this->Shell->Schema->file, 'schema.php');
unset($this->Shell->Schema); unset($this->Shell->Schema);
@ -168,7 +168,7 @@ class SchemaShellTest extends CakeTestCase {
'path' => '/test/path' 'path' => '/test/path'
); );
$this->Shell->startup(); $this->Shell->startup();
$this->assertEqual(strtolower($this->Shell->Schema->name), APP_DIR); $this->assertEqual(strtolower($this->Shell->Schema->name), strtolower(APP_DIR));
$this->assertEqual($this->Shell->Schema->file, 'other_file.php'); $this->assertEqual($this->Shell->Schema->file, 'other_file.php');
$this->assertEqual($this->Shell->Schema->connection, 'test_suite'); $this->assertEqual($this->Shell->Schema->connection, 'test_suite');
$this->assertEqual($this->Shell->Schema->path, '/test/path'); $this->assertEqual($this->Shell->Schema->path, '/test/path');
@ -354,5 +354,33 @@ class SchemaShellTest extends CakeTestCase {
$this->_fixtures['core.article']->create($this->db); $this->_fixtures['core.article']->create($this->db);
} }
/**
* test that the plugin param creates the correct path in the schema object.
*
* @return void
**/
function testPluginParam() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$this->Shell->params = array(
'plugin' => 'TestPlugin',
'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';
$this->assertEqual($this->Shell->Schema->path, $expected);
}
} }
?> ?>