From 565cd96120dac6af170852f77c042f995f4660d7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 24 Jul 2009 16:29:18 +0000 Subject: [PATCH] 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 --- cake/tests/cases/libs/cake_test_case.test.php | 22 ++++++++++--------- cake/tests/lib/cake_test_case.php | 5 +++-- cake/tests/lib/cake_test_fixture.php | 9 ++++++-- .../tests_apps_posts_controller.php | 3 ++- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index 399106bc6..895eaaf40 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -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'); diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index f2a5fb442..f642e36a1 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -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); } } diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index acef3028c..cd12f9a32 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -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; } } -?> +?> \ No newline at end of file diff --git a/cake/tests/test_app/controllers/tests_apps_posts_controller.php b/cake/tests/test_app/controllers/tests_apps_posts_controller.php index e9b0d0464..c8ef7953f 100644 --- a/cake/tests/test_app/controllers/tests_apps_posts_controller.php +++ b/cake/tests/test_app/controllers/tests_apps_posts_controller.php @@ -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);