Skip to content

Commit

Permalink
Made SchemaShell::view() work better with plugins. Tests added.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 4, 2009
1 parent 30ef796 commit 75f2106
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cake/console/libs/schema.php
Expand Up @@ -61,26 +61,36 @@ function startup() {
$name = $file = $path = $connection = $plugin = null;
if (!empty($this->params['name'])) {
$name = $this->params['name'];
} elseif (!empty($this->args[0])) {
$name = $this->params['name'] = $this->args[0];
}
if (strpos($name, '.')) {
list($this->params['plugin'], $this->params['name']) = explode('.', $name);
$name = $this->params['name'];
}

if ($name) {
$this->params['file'] = Inflector::underscore($name);
}

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';
}
$file = $this->params['file'];

if (!empty($this->params['path'])) {
$path = $this->params['path'];
}

if (!empty($this->params['connection'])) {
$connection = $this->params['connection'];
}
if (!empty($this->params['plugin'])) {
$plugin = $this->params['plugin'];
}

$this->Schema =& new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin'));
}

Expand Down
24 changes: 24 additions & 0 deletions cake/tests/cases/console/libs/schema.test.php
Expand Up @@ -184,9 +184,33 @@ function testView() {
$this->Shell->Schema->path = APP . 'config' . DS . 'schema';
$this->Shell->params['file'] = 'i18n.php';
$this->Shell->expectOnce('_stop');
$this->Shell->expectOnce('out');
$this->Shell->view();
}

/**
* test that view() can find plugin schema files.
*
* @return void
**/
function testViewWithPlugins() {
App::build(array(
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS)
));
$this->Shell->args = array('TestPlugin.schema');
$this->Shell->startup();
$this->Shell->expectCallCount('_stop', 2);
$this->Shell->expectCallCount('out', 2);
$this->Shell->view();

$this->Shell->args = array();
$this->Shell->params = array('plugin' => 'TestPlugin');
$this->Shell->startup();
$this->Shell->view();

App::build();
}

/**
* test dump() with sql file generation
*
Expand Down

0 comments on commit 75f2106

Please sign in to comment.