Fixing issue in CakeTestCase where fixture tables were incorrectly detected and dropped when running tests with no $test config or $test config and $default config on the same database.

Updating TestAppsPostsController to fix compatibility issues with postgres.
Defining $name in CakeTestFixture to remove notice errors, when constructing a nameless Fixture.
Fixes #6518

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8254 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mark_story 2009-07-24 16:29:18 +00:00
parent 9eaad7528f
commit 565cd96120
4 changed files with 24 additions and 15 deletions

View file

@ -219,6 +219,7 @@ class CakeTestCaseTest extends CakeTestCase {
$this->Case->before('start');
$this->expectError();
$this->Case->loadFixtures('Wrong!');
$this->Case->end();
}
/**
* testGetTests Method
@ -263,6 +264,10 @@ class CakeTestCaseTest extends CakeTestCase {
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
$this->assertEqual($result, array('var' => 'string'));
$db =& ConnectionManager::getDataSource('test_suite');
$fixture =& new PostFixture();
$fixture->create($db);
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
$this->assertTrue(array_key_exists('posts', $result));
$this->assertEqual(count($result['posts']), 1);
@ -304,7 +309,7 @@ class CakeTestCaseTest extends CakeTestCase {
)
));
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
$fixture->drop($db);
$db =& ConnectionManager::getDataSource('test_suite');
$_backPrefix = $db->config['prefix'];
@ -314,11 +319,11 @@ class CakeTestCaseTest extends CakeTestCase {
$config['prefix'] = 'cake_testcase_test_';
ConnectionManager::create('cake_test_case', $config);
$db =& ConnectionManager::getDataSource('cake_test_case');
$db2 =& ConnectionManager::getDataSource('cake_test_case');
$fixture =& new PostFixture($db);
$fixture->create($db);
$fixture->insert($db);
$fixture =& new PostFixture($db2);
$fixture->create($db2);
$fixture->insert($db2);
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
'return' => 'vars',
@ -327,15 +332,12 @@ class CakeTestCaseTest extends CakeTestCase {
));
$this->assertTrue(isset($result['posts']));
$this->assertEqual(count($result['posts']), 3);
$tables = $db->listSources(true);
$tables = $db2->listSources();
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
$fixture->drop($db);
$fixture->drop($db2);
$db =& ConnectionManager::getDataSource('test_suite');
$db->config['prefix'] = $_backPrefix;
$fixture->drop($db);
//test that drop tables behaves as exepected with testAction
$db =& ConnectionManager::getDataSource('test_suite');

View file

@ -425,10 +425,11 @@ class CakeTestCase extends UnitTestCase {
return;
}
foreach ($this->_fixtures as $fixture) {
if (in_array($fixture->table, $sources)) {
$table = $this->db->config['prefix'] . $fixture->table;
if (in_array($table, $sources)) {
$fixture->drop($this->db);
$fixture->create($this->db);
} elseif (!in_array($fixture->table, $sources)) {
} elseif (!in_array($table, $sources)) {
$fixture->create($this->db);
}
}

View file

@ -31,6 +31,12 @@
* @subpackage cake.cake.tests.lib
*/
class CakeTestFixture extends Object {
/**
* Name of the object
*
* @var string
**/
var $name = null;
/**
* Cake's DBO driver (e.g: DboMysql).
*
@ -43,7 +49,6 @@ class CakeTestFixture extends Object {
* @access public
*/
var $table = null;
/**
* Instantiate the fixture.
*
@ -185,4 +190,4 @@ class CakeTestFixture extends Object {
return $return;
}
}
?>
?>

View file

@ -33,7 +33,8 @@ class TestsAppsPostsController extends AppController {
$data = array(
'Post' => array(
'title' => 'Test article',
'body' => 'Body of article.'
'body' => 'Body of article.',
'author_id' => 1
)
);
$this->Post->save($data);