mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
9eaad7528f
commit
565cd96120
4 changed files with 24 additions and 15 deletions
|
@ -219,6 +219,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
$this->Case->before('start');
|
$this->Case->before('start');
|
||||||
$this->expectError();
|
$this->expectError();
|
||||||
$this->Case->loadFixtures('Wrong!');
|
$this->Case->loadFixtures('Wrong!');
|
||||||
|
$this->Case->end();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* testGetTests Method
|
* testGetTests Method
|
||||||
|
@ -263,6 +264,10 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
|
$result = $this->Case->testAction('/tests_apps/set_action', array('return' => 'vars'));
|
||||||
$this->assertEqual($result, array('var' => 'string'));
|
$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'));
|
$result = $this->Case->testAction('/tests_apps_posts/add', array('return' => 'vars'));
|
||||||
$this->assertTrue(array_key_exists('posts', $result));
|
$this->assertTrue(array_key_exists('posts', $result));
|
||||||
$this->assertEqual(count($result['posts']), 1);
|
$this->assertEqual(count($result['posts']), 1);
|
||||||
|
@ -304,7 +309,7 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
|
$this->assertEqual(array_keys($result['data']), array('name', 'pork'));
|
||||||
|
$fixture->drop($db);
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
$_backPrefix = $db->config['prefix'];
|
$_backPrefix = $db->config['prefix'];
|
||||||
|
@ -314,11 +319,11 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
$config['prefix'] = 'cake_testcase_test_';
|
$config['prefix'] = 'cake_testcase_test_';
|
||||||
|
|
||||||
ConnectionManager::create('cake_test_case', $config);
|
ConnectionManager::create('cake_test_case', $config);
|
||||||
$db =& ConnectionManager::getDataSource('cake_test_case');
|
$db2 =& ConnectionManager::getDataSource('cake_test_case');
|
||||||
|
|
||||||
$fixture =& new PostFixture($db);
|
$fixture =& new PostFixture($db2);
|
||||||
$fixture->create($db);
|
$fixture->create($db2);
|
||||||
$fixture->insert($db);
|
$fixture->insert($db2);
|
||||||
|
|
||||||
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
$result = $this->Case->testAction('/tests_apps_posts/fixtured', array(
|
||||||
'return' => 'vars',
|
'return' => 'vars',
|
||||||
|
@ -327,15 +332,12 @@ class CakeTestCaseTest extends CakeTestCase {
|
||||||
));
|
));
|
||||||
$this->assertTrue(isset($result['posts']));
|
$this->assertTrue(isset($result['posts']));
|
||||||
$this->assertEqual(count($result['posts']), 3);
|
$this->assertEqual(count($result['posts']), 3);
|
||||||
$tables = $db->listSources(true);
|
$tables = $db2->listSources();
|
||||||
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
|
$this->assertFalse(in_array('cake_testaction_test_suite_posts', $tables));
|
||||||
|
|
||||||
$fixture->drop($db);
|
$fixture->drop($db2);
|
||||||
|
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
$db->config['prefix'] = $_backPrefix;
|
|
||||||
$fixture->drop($db);
|
|
||||||
|
|
||||||
|
|
||||||
//test that drop tables behaves as exepected with testAction
|
//test that drop tables behaves as exepected with testAction
|
||||||
$db =& ConnectionManager::getDataSource('test_suite');
|
$db =& ConnectionManager::getDataSource('test_suite');
|
||||||
|
|
|
@ -425,10 +425,11 @@ class CakeTestCase extends UnitTestCase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach ($this->_fixtures as $fixture) {
|
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->drop($this->db);
|
||||||
$fixture->create($this->db);
|
$fixture->create($this->db);
|
||||||
} elseif (!in_array($fixture->table, $sources)) {
|
} elseif (!in_array($table, $sources)) {
|
||||||
$fixture->create($this->db);
|
$fixture->create($this->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
* @subpackage cake.cake.tests.lib
|
* @subpackage cake.cake.tests.lib
|
||||||
*/
|
*/
|
||||||
class CakeTestFixture extends Object {
|
class CakeTestFixture extends Object {
|
||||||
|
/**
|
||||||
|
* Name of the object
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
**/
|
||||||
|
var $name = null;
|
||||||
/**
|
/**
|
||||||
* Cake's DBO driver (e.g: DboMysql).
|
* Cake's DBO driver (e.g: DboMysql).
|
||||||
*
|
*
|
||||||
|
@ -43,7 +49,6 @@ class CakeTestFixture extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $table = null;
|
var $table = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiate the fixture.
|
* Instantiate the fixture.
|
||||||
*
|
*
|
||||||
|
@ -185,4 +190,4 @@ class CakeTestFixture extends Object {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -33,7 +33,8 @@ class TestsAppsPostsController extends AppController {
|
||||||
$data = array(
|
$data = array(
|
||||||
'Post' => array(
|
'Post' => array(
|
||||||
'title' => 'Test article',
|
'title' => 'Test article',
|
||||||
'body' => 'Body of article.'
|
'body' => 'Body of article.',
|
||||||
|
'author_id' => 1
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$this->Post->save($data);
|
$this->Post->save($data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue