3
* CakeTestSuiteDispatcher controls dispatching TestSuite web based requests.
7
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
8
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
10
* Licensed under The Open Group Test Suite License
11
* Redistributions of files must retain the above copyright notice.
13
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
14
* @link http://cakephp.org CakePHP(tm) Project
16
* @subpackage cake.cake.tests.lib
17
* @since CakePHP(tm) v 1.3
18
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
20
require_once CAKE_TESTS_LIB . 'test_manager.php';
23
* CakeTestSuiteDispatcher handles web requests to the test suite and runs the correct action.
25
* @package cake.tests.libs
27
class CakeTestSuiteDispatcher {
29
* 'Request' parameters
34
'codeCoverage' => false,
41
'show_passes' => false
45
* The classname for the TestManager being used
49
var $_managerClass = 'TestManager';
52
* The Instance of the Manager being used.
54
* @var TestManager subclass
59
* Baseurl for the request
66
* Base dir of the request. Used for accessing assets.
77
function CakeTestSuiteDispatcher() {
78
$this->_baseUrl = $_SERVER['PHP_SELF'];
79
$dir = rtrim(dirname($this->_baseUrl), '\\');
80
$this->_baseDir = ($dir === '/') ? $dir : $dir . '/';
84
* Runs the actions required by the URL parameters.
89
$this->_checkSimpleTest();
90
$this->_parseParams();
92
if ($this->params['group']) {
93
$this->_runGroupTest();
94
} elseif ($this->params['case']) {
95
$this->_runTestCase();
96
} elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
97
$this->_testCaseList();
99
$this->_groupTestList();
102
$output = ob_get_clean();
107
* Checks that simpleTest is installed. Will exit if it doesn't
111
function _checkSimpleTest() {
112
if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
113
$baseDir = $this->_baseDir;
114
include CAKE_TESTS_LIB . 'templates' . DS . 'simpletest.php';
120
* Checks for the xdebug extension required to do code coverage. Displays an error
121
* if xdebug isn't installed.
125
function _checkXdebug() {
126
if (!extension_loaded('xdebug')) {
127
$baseDir = $this->_baseDir;
128
include CAKE_TESTS_LIB . 'templates' . DS . 'xdebug.php';
134
* Generates a page containing the a list of test cases that could be run.
138
function _testCaseList() {
139
$Reporter =& $this->getReporter();
140
$Reporter->paintDocumentStart();
141
$Reporter->paintTestMenu();
142
$Reporter->testCaseList();
143
$Reporter->paintDocumentEnd();
147
* Generates a page containing a list of group tests that could be run.
151
function _groupTestList() {
152
$Reporter =& $this->getReporter();
153
$Reporter->paintDocumentStart();
154
$Reporter->paintTestMenu();
155
$Reporter->groupTestList();
156
$Reporter->paintDocumentEnd();
160
* Sets the Manager to use for the request.
162
* @return string The manager class name
165
function &getManager() {
166
if (empty($this->Manager)) {
167
$this->Manager = new $this->_managerClass();
169
return $this->Manager;
173
* Gets the reporter based on the request parameters
178
function &getReporter() {
179
static $Reporter = NULL;
181
$type = strtolower($this->params['output']);
182
$coreClass = 'Cake' . ucwords($this->params['output']) . 'Reporter';
183
$coreFile = CAKE_TESTS_LIB . 'reporter' . DS . 'cake_' . $type . '_reporter.php';
185
$appClass = $this->params['output'] . 'Reporter';
186
$appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php';
187
if (include_once $coreFile) {
188
$Reporter =& new $coreClass(null, $this->params);
189
} elseif (include_once $appFile) {
190
$Reporter =& new $appClass(null, $this->params);
197
* Parse url params into a 'request'
201
function _parseParams() {
202
if (!isset($_SERVER['SERVER_NAME'])) {
203
$_SERVER['SERVER_NAME'] = '';
205
foreach ($this->params as $key => $value) {
206
if (isset($_GET[$key])) {
207
$this->params[$key] = $_GET[$key];
210
if (isset($_GET['code_coverage'])) {
211
$this->params['codeCoverage'] = true;
212
require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
213
$this->_checkXdebug();
215
$this->params['baseUrl'] = $this->_baseUrl;
216
$this->params['baseDir'] = $this->_baseDir;
221
* Runs the group test case.
225
function _runGroupTest() {
226
$Reporter =& CakeTestSuiteDispatcher::getReporter();
227
if ($this->params['codeCoverage']) {
228
CodeCoverageManager::init($this->params['group'], $Reporter);
230
if ('all' == $this->params['group']) {
231
$this->Manager->runAllTests($Reporter);
233
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter);
238
* Runs a test case file.
242
function _runTestCase() {
243
$Reporter =& CakeTestSuiteDispatcher::getReporter();
244
if ($this->params['codeCoverage']) {
245
CodeCoverageManager::init($this->params['case'], $Reporter);
247
$this->Manager->runTestCase($this->params['case'], $Reporter);