Skip to content

Commit

Permalink
Applying patch from 'rynop'. Fixing FixtureTask so it includes the da…
Browse files Browse the repository at this point in the history
…tasource if its not the default one.

Updating tests.
Fixes #1419
  • Loading branch information
markstory committed Dec 31, 2010
1 parent 5092013 commit a706151
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
17 changes: 10 additions & 7 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -161,7 +161,9 @@ function bake($model, $useTable = false, $importOptions = array()) {
if (!class_exists('CakeSchema')) {
App::import('Model', 'CakeSchema', false);
}
$table = $schema = $records = $import = $modelImport = $recordImport = null;
$table = $schema = $records = $import = $modelImport = null;
$importBits = array();

if (!$useTable) {
$useTable = Inflector::tableize($model);
} elseif ($useTable != Inflector::tableize($model)) {
Expand All @@ -170,16 +172,17 @@ function bake($model, $useTable = false, $importOptions = array()) {

if (!empty($importOptions)) {
if (isset($importOptions['schema'])) {
$modelImport = "'model' => '{$importOptions['schema']}'";
$modelImport = true;
$importBits[] = "'model' => '{$importOptions['schema']}'";
}
if (isset($importOptions['records'])) {
$recordImport = "'records' => true";
$importBits[] = "'records' => true";
}
if ($modelImport && $recordImport) {
$modelImport .= ', ';
if ($this->connection != 'default') {
$importBits[] .= "'connection' => '{$this->connection}'";
}
if (!empty($modelImport) || !empty($recordImport)) {
$import = sprintf("array(%s%s)", $modelImport, $recordImport);
if (!empty($importBits)) {
$import = sprintf("array(%s)", implode(', ', $importBits));
}
}

Expand Down
26 changes: 23 additions & 3 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -135,6 +135,17 @@ function testImportOptions() {
$this->assertEqual($result, $expected);
}

/**
* test that connection gets set to the import options when a different connection is used.
*
* @return void
*/
function testImportOptionsAlternateConnection() {
$this->Task->connection = 'test';
$result = $this->Task->bake('Article', false, array('schema' => 'Article'));
$this->assertPattern("/'connection' => 'test'/", $result);
}

/**
* test generating a fixture with database conditions.
*
Expand Down Expand Up @@ -287,15 +298,24 @@ function testBake() {
$this->assertPattern('/var \$fields = array\(/', $result);

$result = $this->Task->bake('Article', 'comments', array('records' => true));
$this->assertPattern("/var \\\$import \= array\('records' \=\> true\);/", $result);
$this->assertPattern(
"/var \\\$import \= array\('records' \=\> true, 'connection' => 'test_suite'\);/",
$result
);
$this->assertNoPattern('/var \$records/', $result);

$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article'));
$this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\);/", $result);
$this->assertPattern(
"/var \\\$import \= array\('model' \=\> 'Article', 'connection' => 'test_suite'\);/",
$result
);
$this->assertNoPattern('/var \$fields/', $result);

$result = $this->Task->bake('Article', 'comments', array('schema' => 'Article', 'records' => true));
$this->assertPattern("/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true\);/", $result);
$this->assertPattern(
"/var \\\$import \= array\('model' \=\> 'Article'\, 'records' \=\> true, 'connection' => 'test_suite'\);/",
$result
);
$this->assertNoPattern('/var \$fields/', $result);
$this->assertNoPattern('/var \$records/', $result);
}
Expand Down

0 comments on commit a706151

Please sign in to comment.