Updating tests for ModelTask. Making it impossible to bake a model which does not have a table on the active connection. Fixes #6035

This commit is contained in:
mark_story 2009-07-08 23:30:29 -04:00
parent 9bbb33ef2f
commit 7e1f9eeebd
2 changed files with 30 additions and 2 deletions

View file

@ -197,6 +197,10 @@ class ModelTask extends Shell {
if (!array_key_exists('id', $fields)) { if (!array_key_exists('id', $fields)) {
$primaryKey = $this->findPrimaryKey($fields); $primaryKey = $this->findPrimaryKey($fields);
} }
} else {
$this->err(sprintf(__('Table %s does not exist, cannot bake a model without a table.', true), $useTable));
$this->_stop();
return false;
} }
$displayField = $tempModel->hasField(array('name', 'title')); $displayField = $tempModel->hasField(array('name', 'title'));
if (!$displayField) { if (!$displayField) {
@ -243,7 +247,7 @@ class ModelTask extends Shell {
$this->hr(); $this->hr();
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y'); $looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
if (strtolower($looksGood) == 'y') { if (strtolower($looksGood) == 'y') {
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField'); $vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
$vars['useDbConfig'] = $this->connection; $vars['useDbConfig'] = $this->connection;

View file

@ -698,6 +698,7 @@ class ModelTaskTest extends CakeTestCase {
function testExecuteIntoInteractive() { function testExecuteIntoInteractive() {
$this->Task->connection = 'test_suite'; $this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/'; $this->Task->path = '/my/path/';
$this->Task->interactive = true;
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article $this->Task->setReturnValueAt(0, 'in', '1'); //choose article
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation $this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
@ -705,11 +706,34 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation $this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation $this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation $this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to looksGood? $this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
$this->Task->setReturnValue('_checkUnitTest', true);
$this->Task->Test->expectOnce('bake');
$this->Task->Fixture->expectOnce('bake');
$filename = '/my/path/article.php'; $filename = '/my/path/article.php';
$this->Task->expectOnce('createFile');
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/'))); $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
$this->Task->execute(); $this->Task->execute();
} }
/**
* test using bake interactively with a table that does not exist.
*
* @return void
**/
function testExecuteWithNonExistantTableName() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->expectOnce('_stop');
$this->Task->expectOnce('err');
$this->Task->setReturnValueAt(0, 'in', 'Foobar');
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->execute();
}
} }
?> ?>