Skip to content
Permalink
Browse files

Not forcing the use of ds, so will use $useDbConfig instead, tests ad…

…ded. Fixes #324.
  • Loading branch information...
renan committed Feb 15, 2010
1 parent f04add4 commit d7b49e349454c4f0e35e5b74762b4b424cf43775
@@ -238,9 +238,9 @@ function read($options = array()) {
$model = $this->plugin . '.' . $model;
}
if (PHP5) {
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
} else {
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => $connection));
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => null));
}
if (is_object($Object) && $Object->useTable !== false) {
@@ -369,6 +369,85 @@ class Testdescribe extends CakeTestModel {
var $name = 'Testdescribe';
}
/**
* SchemaCrossDatabase class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaCrossDatabase extends CakeTestModel {
/**
* name property
*
* @var string 'SchemaCrossDatabase'
* @access public
*/
var $name = 'SchemaCrossDatabase';
/**
* useTable property
*
* @var string 'posts'
* @access public
*/
var $useTable = 'cross_database';
/**
* useDbConfig property
*
* @var string 'test2'
* @access public
*/
var $useDbConfig = 'test2';
}
/**
* SchemaCrossDatabaseFixture class
*
* @package cake
* @subpackage cake.tests.cases.libs.model
*/
class SchemaCrossDatabaseFixture extends CakeTestFixture {
/**
* name property
*
* @var string 'CrossDatabase'
* @access public
*/
var $name = 'CrossDatabase';
/**
* table property
*
* @access public
*/
var $table = 'cross_database';
/**
* fields property
*
* @var array
* @access public
*/
var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
'name' => 'string'
);
/**
* records property
*
* @var array
* @access public
*/
var $records = array(
array('id' => 1, 'name' => 'First'),
array('id' => 2, 'name' => 'Second'),
);
}
/**
* CakeSchemaTest
*
@@ -384,7 +463,7 @@ class CakeSchemaTest extends CakeTestCase {
* @access public
*/
var $fixtures = array(
'core.post', 'core.tag', 'core.posts_tag', 'core.comment', 'core.datatype', 'core.auth_user'
'core.post', 'core.tag', 'core.posts_tag', 'core.comment', 'core.datatype', 'core.auth_user', 'core.author'
);
/**
@@ -406,6 +485,7 @@ function startTest() {
function tearDown() {
@unlink(TMP . 'tests' . DS .'schema.php');
unset($this->Schema);
ClassRegistry::flush();
}
/**
@@ -468,6 +548,7 @@ function testSchemaRead() {
));
$this->assertFalse(isset($read['tables']['missing']['posts']), 'Posts table was not read from tablePrefix %s');
}
/**
* test reading schema from plugins.
*
@@ -486,14 +567,58 @@ function testSchemaReadWithPlugins() {
'models' => true
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['posts']));
$this->assertTrue(isset($read['tables']['auth_users']));
$this->assertEqual(count($read['tables']), 2);
$this->assertTrue(isset($read['tables']['authors']));
$this->assertTrue(isset($read['tables']['comments']));
$this->assertTrue(isset($read['tables']['posts']));
$this->assertEqual(count($read['tables']), 4);
App::build();
}
/**
* test reading schema with tables from another database.
*
* @return void
*/
function testSchemaReadWithCrossDatabase() {
$config = new DATABASE_CONFIG();
$skip = $this->skipIf(
!isset($config->test) || !isset($config->test2),
'%s Primary and secondary test databases not configured, skipping cross-database '
.'join tests.'
.' To run these tests, you must define $test and $test2 in your database configuration.'
);
if ($skip) {
return;
}
$db2 =& ConnectionManager::getDataSource('test2');
$fixture = new SchemaCrossDatabaseFixture();
$fixture->create($db2);
$fixture->insert($db2);
$read = $this->Schema->read(array(
'connection' => 'test_suite',
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertTrue(isset($read['tables']['posts']));
$this->assertFalse(isset($read['tables']['cross_database']));
$read = $this->Schema->read(array(
'connection' => 'test2',
'name' => 'TestApp',
'models' => array('SchemaCrossDatabase', 'SchemaPost')
));
unset($read['tables']['missing']);
$this->assertFalse(isset($read['tables']['posts']));
$this->assertTrue(isset($read['tables']['cross_database']));
$fixture->drop($db2);
}
/**
* test that tables are generated correctly
*
@@ -642,7 +767,7 @@ function testTableParametersAndIndexComparison() {
),
'change' => array(
'tableParameters' => array(
'charset' => 'utf8',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
'engine' => 'MyISAM'
)
@@ -654,7 +779,7 @@ function testTableParametersAndIndexComparison() {
),
'change' => array(
'tableParameters' => array(
'charset' => 'utf8',
'charset' => 'utf8',
'collate' => 'utf8_general_ci',
)
)
@@ -17,5 +17,5 @@
* @since CakePHP(tm) v 1.2.0.5432
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
class TestPluginAppModel extends AppModel {}
class TestPluginAppModel extends CakeTestModel {}
?>

0 comments on commit d7b49e3

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