Skip to content
Permalink
Browse files

Moving init() tests into separate test methods.

Adding tests for table prefixes on models being used as imports.
Fixing issue where tablePrefix was not accurately used when importing model information.  Fixes #765
  • Loading branch information...
markstory committed Jun 9, 2010
1 parent 2f527cc commit bca3c4ab38e0326dd4782b0536f9e3b8cd71f83e
Showing with 41 additions and 1 deletion.
  1. +39 −0 cake/tests/cases/libs/cake_test_fixture.test.php
  2. +2 −1 cake/tests/lib/cake_test_fixture.php
@@ -114,6 +114,14 @@ class FixtureImportTestModel extends Model {
var $useTable = 'fixture_tests';
var $useDbConfig = 'test_suite';
}
class FixturePrefixTest extends Model {
var $name = 'FixturePrefix';
var $useTable = '_tests';
var $tablePrefix = 'fixture';
var $useDbConfig = 'test_suite';
}
Mock::generate('DboSource', 'FixtureMockDboSource');
/**
@@ -162,7 +170,14 @@ function testInit() {
$Fixture->primaryKey = 'my_random_key';
$Fixture->init();
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
}
/**
* test that init() correctly sets the fixture table when the connection or model have prefixes defined.
*
* @return void
*/
function testInitDbPrefix() {
$this->_initDb();
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
@@ -194,6 +209,30 @@ function testInit() {
$Source->drop($this->db);
}
/**
* test init with a model that has a tablePrefix declared.
*
* @return void
*/
function testInitModelTablePrefix() {
$this->_initDb();
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
$Fixture =& new CakeTestFixtureImportFixture();
unset($Fixture->table);
$Fixture->fields = $Fixture->records = null;
$Fixture->import = array('model' => 'FixturePrefixTest', 'connection' => 'test_suite', 'records' => false);
$Fixture->init();
$this->assertEqual($Fixture->table, 'fixture_tests');
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($this->db);
}
/**
* testImport
*
@@ -80,6 +80,7 @@ function init() {
$db->cacheSources = false;
$this->fields = $model->schema(true);
$this->fields[$model->primaryKey]['key'] = 'primary';
$this->table = $db->fullTableName($model, false);
ClassRegistry::config(array('ds' => 'test_suite'));
ClassRegistry::flush();
} elseif (isset($import['table'])) {
@@ -97,7 +98,7 @@ function init() {
$this->records = array();
$query = array(
'fields' => $db->fields($model, null, array_keys($this->fields)),
'table' => $db->fullTableName($model->table),
'table' => $db->fullTableName($model),
'alias' => $model->alias,
'conditions' => array(),
'order' => null,

0 comments on commit bca3c4a

Please sign in to comment.
You can’t perform that action at this time.