From f875c0098b8ee6a3b922578e7094c5d65042728d Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 17 Oct 2008 16:39:39 +0000 Subject: [PATCH] Updating test_suite header to improve readability of connection names. Adding test for using CakeTestCase::testAction() with fixturize parameter. Updating TestsAppPostsController and adding Post Model to test suite. Refs #5620 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7760 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/tests/cases/libs/cake_test_case.test.php | 28 ++++++++++++++++ cake/tests/lib/cake_test_case.php | 2 +- cake/tests/lib/header.php | 1 + .../tests_apps_posts_controller.php | 18 ++++++++-- cake/tests/test_app/models/post.php | 33 +++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 cake/tests/test_app/models/post.php diff --git a/cake/tests/cases/libs/cake_test_case.test.php b/cake/tests/cases/libs/cake_test_case.test.php index f189ab34a..96d6a6e5a 100644 --- a/cake/tests/cases/libs/cake_test_case.test.php +++ b/cake/tests/cases/libs/cake_test_case.test.php @@ -290,6 +290,34 @@ class CakeTestCaseTest extends CakeTestCase { )); $this->assertEqual(array_keys($result['data']), array('name', 'pork')); + $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); + + $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); + + $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']); diff --git a/cake/tests/lib/cake_test_case.php b/cake/tests/lib/cake_test_case.php index aec627030..a47fcb812 100644 --- a/cake/tests/lib/cake_test_case.php +++ b/cake/tests/lib/cake_test_case.php @@ -179,7 +179,7 @@ class CakeTestCase extends UnitTestCase { $object =& ClassRegistry::init($name); //switch back to specified datasource. $object->setDataSource($params['connection']); - $db =& ConnectionManager::getDataSource($object->useDbConfig); + $db =& ConnectionManager::getDataSource($object->useDbConfig); $db->cacheSources = false; $models[$object->alias] = array( diff --git a/cake/tests/lib/header.php b/cake/tests/lib/header.php index 9a9b5b76c..bfc0f65da 100644 --- a/cake/tests/lib/header.php +++ b/cake/tests/lib/header.php @@ -50,6 +50,7 @@ ul.tests li.skipped {background: url(http://cakephp.org/img/test-skip-icon.png) top left no-repeat;} ul.tests li div { margin: 5px 0 8px 0; } ul.tests li div.msg { font-weight: bold; } + table caption { color:#fff;} 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 4ec42b046..8b980654b 100644 --- a/cake/tests/test_app/controllers/tests_apps_posts_controller.php +++ b/cake/tests/test_app/controllers/tests_apps_posts_controller.php @@ -43,16 +43,30 @@ class TestsAppsPostsController extends AppController { $this->set('posts', $this->Post->find('all')); $this->render('index'); } - +/** + * check url params + * + */ function url_var() { $this->set('params', $this->params); $this->render('index'); } - +/** + * post var testing + * + */ function post_var() { $this->set('data', $this->data); $this->render('index'); } +/** + * Fixturized action for testAction() + * + */ + function fixtured() { + $this->set('posts', $this->Post->find('all')); + $this->render('index'); + } } ?> \ No newline at end of file diff --git a/cake/tests/test_app/models/post.php b/cake/tests/test_app/models/post.php new file mode 100644 index 000000000..2cc28c060 --- /dev/null +++ b/cake/tests/test_app/models/post.php @@ -0,0 +1,33 @@ + + * Copyright 2006-2008, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The MIT License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2006-2008, Cake Software Foundation, Inc. + * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project + * @package cake + * @subpackage cake.cake.libs. + * @since CakePHP v 1.2.0.7726 + * @version $Revision$ + * @modifiedby $LastChangedBy$ + * @lastmodified $Date$ + * @license http://www.opensource.org/licenses/mit-license.php The MIT License + */ +class Post extends AppModel { + var $useTable = 'posts'; + var $name = 'Post'; +} +?> \ No newline at end of file