diff --git a/cake/console/libs/tasks/fixture.php b/cake/console/libs/tasks/fixture.php index c31ee8a83ef..e2ee6026464 100644 --- a/cake/console/libs/tasks/fixture.php +++ b/cake/console/libs/tasks/fixture.php @@ -90,6 +90,7 @@ function execute() { } if (isset($this->args[0])) { + $this->interactive = false; if (!isset($this->connection)) { $this->connection = 'default'; } @@ -109,6 +110,7 @@ function execute() { **/ function all() { $this->interactive = false; + $this->Model->interactive = false; $tables = $this->Model->listAll($this->connection, false); foreach ($tables as $table) { $model = $this->_modelName($table); @@ -215,7 +217,7 @@ function bake($model, $useTable = false, $importOptions = array()) { } $records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount)); } - if (isset($importOptions['fromTable'])) { + if (isset($this->params['records']) || isset($importOptions['fromTable'])) { $records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable)); } $out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields')); @@ -359,10 +361,14 @@ function _makeRecordString($records) { * @return array Array of records. **/ function _getRecordsFromTable($modelName, $useTable = null) { - $condition = null; - $prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true); - while (!$condition) { - $condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10'); + if ($this->interactive) { + $condition = null; + $prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true); + while (!$condition) { + $condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10'); + } + } else { + $condition = 'WHERE 1=1 ' . isset($this->params['count']) ? $this->params['count'] : 10; } App::import('Model', 'Model', false); $modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection)); diff --git a/cake/tests/cases/console/libs/tasks/fixture.test.php b/cake/tests/cases/console/libs/tasks/fixture.test.php index 856c996bf75..3839010e406 100644 --- a/cake/tests/cases/console/libs/tasks/fixture.test.php +++ b/cake/tests/cases/console/libs/tasks/fixture.test.php @@ -198,10 +198,10 @@ function testAllWithCountAndRecordsFlags() { $this->Task->Model->setReturnValue('listAll', array('articles', 'comments')); $filename = '/my/path/article_fixture.php'; - $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/'))); + $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/title\' => \'Third Article\'/'))); $filename = '/my/path/comment_fixture.php'; - $this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/'))); + $this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/comment\' => \'First Comment for First Article/'))); $this->Task->expectCallCount('createFile', 2); $this->Task->all(); }