Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 216 lines (199 sloc) 5.172 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
<?php
/**
* CakeTestSuiteDispatcher controls dispatching TestSuite web based requests.
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.cake.tests.lib
* @since CakePHP(tm) v 1.3
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/
require_once CAKE_TESTS_LIB . 'test_manager.php';
require_once CAKE_TESTS_LIB . 'cake_test_menu.php';

/**
* CakeTestSuiteDispatcher handles web requests to the test suite and runs the correct action.
*
* @package cake.tests.libs
*/
class CakeTestSuiteDispatcher {
/**
* 'Request' parameters
*
* @var array
*/
var $params = array(
'codeCoverage' => false,
'group' => null,
'case' => null,
'app' => false,
'plugin' => null,
'output' => 'html',
'show' => 'groups',
'show_passes' => false
);

/**
* The classname for the TestManager being used
*
* @var string
*/
var $_managerClass;

/**
* The Instance of the Manager being used.
*
* @var TestManager subclass
*/
var $Manager;

/**
* Runs the actions required by the URL parameters.
*
* @return void
*/
function dispatch() {
CakeTestMenu::testHeader();
CakeTestMenu::testSuiteHeader();

$this->_checkSimpleTest();
$this->_parseParams();

if ($this->params['group']) {
$this->_runGroupTest();
} elseif ($this->params['case']) {
$this->_runTestCase();
} elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
CakeTestMenu::testCaseList();
} else {
CakeTestMenu::groupTestList();
}

CakeTestMenu::footer();
$output = ob_get_clean();
echo $output;
}

/**
* Checks that simpleTest is installed. Will exit if it doesn't
*
* @return void
*/
function _checkSimpleTest() {
if (!App::import('Vendor', 'simpletest' . DS . 'reporter')) {
include CAKE_TESTS_LIB . 'templates' . DS . 'simpletest.php';
CakeTestMenu::footer();
exit();
}
}

/**
* Checks for the xdebug extension required to do code coverage. Displays an error
* if xdebug isn't installed.
*
* @return void
*/
function _checkXdebug() {
if (!extension_loaded('xdebug')) {
include CAKE_TESTS_LIB . 'templates' . DS . 'xdebug.php';
CakeTestMenu::footer();
exit();
}
}

/**
* Sets the Manager to use for the request.
*
* @return string The manager class name
* @static
*/
function &getManager() {
$className = ucwords($this->params['output']) . 'TestManager';
if (class_exists($className)) {
$this->_managerClass = $className;
} else {
$this->_managerClass = 'TextTestManager';
}
if (empty($this->Manager)) {
$this->Manager = new $this->_managerClass();
}
return $this->Manager;
}

/**
* Gets the reporter based on the request parameters
*
* @return void
* @static
*/
function &getReporter() {
static $Reporter = NULL;
if (!$Reporter) {
$type = strtolower($this->params['output']);
$coreClass = 'Cake' . ucwords($this->params['output']) . 'Reporter';
$coreFile = CAKE_TESTS_LIB . 'reporter' . DS . 'cake_' . $type . '_reporter.php';

$appClass = $this->params['output'] . 'Reporter';
$appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php';
if (include_once $coreFile) {
$Reporter =& new $coreClass(null, $this->params);
} elseif (include_once $appFile) {
$Reporter =& new $appClass(null, $this->params);
}
}
return $Reporter;
}

/**
* Parse url params into a 'request'
*
* @return void
*/
function _parseParams() {
if (!isset($_SERVER['SERVER_NAME'])) {
$_SERVER['SERVER_NAME'] = '';
}
foreach ($this->params as $key => $value) {
if (isset($_GET[$key])) {
$this->params[$key] = $_GET[$key];
}
}
if (isset($_GET['code_coverage'])) {
$this->params['codeCoverage'] = true;
require_once CAKE_TESTS_LIB . 'code_coverage_manager.php';
$this->_checkXdebug();
}
$this->getManager();
}

/**
* Runs the group test case.
*
* @return void
*/
function _runGroupTest() {
$Reporter =& CakeTestSuiteDispatcher::getReporter();
if ('all' == $this->params['group']) {
$this->Manager->runAllTests($Reporter);
} else {
if ($this->params['codeCoverage']) {
CodeCoverageManager::start($this->params['group'], $Reporter);
}
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter);
if ($this->params['codeCoverage']) {
CodeCoverageManager::report();
}
}
}

/**
* Runs a test case file.
*
* @return void
*/
function _runTestCase() {
$Reporter =& CakeTestSuiteDispatcher::getReporter();
if ($this->params['codeCoverage']) {
CodeCoverageManager::start($_GET['case'], $Reporter);
}

$this->Manager->runTestCase($_GET['case'], $Reporter);

if ($this->params['codeCoverage']) {
CodeCoverageManager::report();
}
}
}
?>
Something went wrong with that request. Please try again.