Permalink
Browse files

Updating tests for ModelTask. Making it impossible to bake a model wh…

…ich does not have a table on the active connection. Fixes #6035
  • Loading branch information...
1 parent 9bbb33e commit 7e1f9eeebdf7836c020ebd1227c31ec98cc459ae @markstory markstory committed Jul 9, 2009
Showing with 30 additions and 2 deletions.
  1. +5 −1 cake/console/libs/tasks/model.php
  2. +25 −1 cake/tests/cases/console/libs/tasks/model.test.php
@@ -197,6 +197,10 @@ function __interactive() {
if (!array_key_exists('id', $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'));
if (!$displayField) {
@@ -243,7 +247,7 @@ function __interactive() {
$this->hr();
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');
-
+
if (strtolower($looksGood) == 'y') {
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
$vars['useDbConfig'] = $this->connection;
@@ -698,18 +698,42 @@ function testExecuteIntoAll() {
function testExecuteIntoInteractive() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
+ $this->Task->interactive = true;
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user 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';
+ $this->Task->expectOnce('createFile');
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
$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();
+ }
}
?>

0 comments on commit 7e1f9ee

Please sign in to comment.