Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding tests for database imports causing duplicated db prefix. Addin…

…g a workaround for the duplicated prefix name.

Fixes #962
  • Loading branch information...
commit 3bda2ce1005957d79ebd8cd392336e2b366de110 1 parent a9bb4ee
@markstory markstory authored
View
35 cake/tests/cases/libs/cake_test_fixture.test.php
@@ -198,11 +198,12 @@ function testInitDbPrefix() {
$this->assertEqual(count($Fixture->records), count($Source->records));
$Fixture =& new CakeTestFixtureImportFixture();
- $Fixture->fields = $Fixture->records = null;
+ $Fixture->fields = $Fixture->records = $Fixture->table = null;
$Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
-
+ $this->assertEqual($Fixture->table, 'fixture_tests');
+
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
@@ -210,12 +211,42 @@ function testInitDbPrefix() {
}
/**
+ * test that fixtures don't duplicate the test db prefix.
+ *
+ * @return void
+ */
+ function testInitDbPrefixDuplication() {
+ $this->_initDb();
+ $backPrefix = $this->db->config['prefix'];
+ $this->db->config['prefix'] = 'cake_fixture_test_';
+
+ $Source =& new CakeTestFixtureTestFixture();
+ $Source->create($this->db);
+ $Source->insert($this->db);
+
+ $Fixture =& new CakeTestFixtureImportFixture();
+ $Fixture->fields = $Fixture->records = $Fixture->table = null;
+ $Fixture->import = array('model' => 'FixtureImportTestModel', 'connection' => 'test_suite');
+
+ $Fixture->init();
+ $this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
+ $this->assertEqual($Fixture->table, 'fixture_tests');
+
+ $Source->drop($this->db);
+ $this->db->config['prefix'] = $backPrefix;
+ }
+
+/**
* test init with a model that has a tablePrefix declared.
*
* @return void
*/
function testInitModelTablePrefix() {
$this->_initDb();
+ $hasPrefix = !empty($this->db->config['prefix']);
+ if ($this->skipIf($hasPrefix, 'Cannot run this test, you have a database connection prefix.')) {
+ return;
+ }
$Source =& new CakeTestFixtureTestFixture();
$Source->create($this->db);
$Source->insert($this->db);
View
5 cake/tests/lib/cake_test_fixture.php
@@ -92,6 +92,11 @@ function init() {
$model->table = $import['table'];
$model->tablePrefix = $db->config['prefix'];
$this->fields = $model->schema(true);
+ ClassRegistry::flush();
+ }
+
+ if (!empty($db->config['prefix']) && strpos($this->table, $db->config['prefix']) === 0) {
+ $this->table = str_replace($db->config['prefix'], '', $this->table);
}
if (isset($import['records']) && $import['records'] !== false && isset($model) && isset($db)) {
Please sign in to comment.
Something went wrong with that request. Please try again.