Skip to content

Commit

Permalink
Updating CakeTestCase::testAction() to respect $dropTables. Test case…
Browse files Browse the repository at this point in the history
… added Fixes #6123

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8051 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information
markstory committed Feb 21, 2009
1 parent 52f4cd4 commit 5dfa7bf
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
39 changes: 37 additions & 2 deletions cake/tests/cases/libs/cake_test_case.test.php
Expand Up @@ -265,6 +265,7 @@ function testTestAction() {
));
$this->assertEqual($result['params']['pass'], array('gogo', 'val2'));


$result = $this->Case->testAction('/tests_apps_posts/url_var', array(
'return' => 'vars',
'method' => 'get',
Expand All @@ -288,8 +289,8 @@ function testTestAction() {
));
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));

$db =& ConnectionManager::getDataSource('test_suite');

$db =& ConnectionManager::getDataSource('test_suite');
$_backPrefix = $db->config['prefix'];
$db->config['prefix'] = 'cake_testaction_test_suite_';

Expand All @@ -298,24 +299,58 @@ function testTestAction() {

ConnectionManager::create('cake_test_case', $config);
$db =& ConnectionManager::getDataSource('cake_test_case');

$fixture =& new PostFixture($db);
$fixture->create($db);
$fixture->insert($db);

$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
'return' => 'vars',
'fixturize' => true,
'connection' => 'cake_test_case',
));
$this->assertTrue(isset($result['posts']));
$this->assertEqual(count($result['posts']), 3);
$tables = $db->listSources(true);
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));

$fixture->drop($db);

$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');
$_backPrefix = $db->config['prefix'];
$db->config['prefix'] = 'cake_testaction_test_suite_';

$config = $db->config;
$config['prefix'] = 'cake_testcase_test_';

ConnectionManager::create('cake_test_case', $config);
$db =& ConnectionManager::getDataSource('cake_test_case');
$fixture =& new PostFixture($db);
$fixture->create($db);
$fixture->insert($db);

$this->Case->dropTables = false;
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
'return' => 'vars',
'fixturize' => true,
'connection' => 'cake_test_case',
));

$tables = $db->listSources();
$this->assertTrue(in_array('cake_testaction_test_suite_posts', $tables));

$fixture->drop($db);
$db =& ConnectionManager::getDataSource('test_suite');
$db->config['prefix'] = $_backPrefix;
$fixture->drop($db);


Configure::write('modelPaths', $_back['model']);
Configure::write('controllerPaths', $_back['controller']);
Configure::write('viewPaths', $_back['view']);
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/lib/cake_test_case.php
Expand Up @@ -223,7 +223,7 @@ function startController(&$controller, $params = array()) {
* * @param array $params Additional parameters as sent by testAction().
*/
function endController(&$controller, $params = array()) {
if (isset($this->db) && isset($this->_actionFixtures) && !empty($this->_actionFixtures)) {
if (isset($this->db) && isset($this->_actionFixtures) && !empty($this->_actionFixtures) && $this->dropTables) {
foreach ($this->_actionFixtures as $fixture) {
$fixture->drop($this->db);
}
Expand Down

0 comments on commit 5dfa7bf

Please sign in to comment.