From 7e1f9eeebdf7836c020ebd1227c31ec98cc459ae Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 8 Jul 2009 23:30:29 -0400 Subject: [PATCH] Updating tests for ModelTask. Making it impossible to bake a model which does not have a table on the active connection. Fixes #6035 --- cake/console/libs/tasks/model.php | 6 ++++- .../cases/console/libs/tasks/model.test.php | 26 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index ab4b73147..efa8ad7a8 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -197,6 +197,10 @@ class ModelTask extends Shell { 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 @@ class ModelTask extends Shell { $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; diff --git a/cake/tests/cases/console/libs/tasks/model.test.php b/cake/tests/cases/console/libs/tasks/model.test.php index 51bcf5424..addd57007 100644 --- a/cake/tests/cases/console/libs/tasks/model.test.php +++ b/cake/tests/cases/console/libs/tasks/model.test.php @@ -698,6 +698,7 @@ class ModelTaskTest extends CakeTestCase { 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 @@ -705,11 +706,34 @@ class ModelTaskTest extends CakeTestCase { $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(); + } } ?> \ No newline at end of file