2010-01-04 04:22:16 +00:00
|
|
|
<?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)
|
2010-01-26 22:03:03 +00:00
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2010-01-04 04:22:16 +00:00
|
|
|
* @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';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
2010-01-06 03:20:32 +00:00
|
|
|
'show' => 'groups',
|
|
|
|
'show_passes' => false
|
2010-01-04 04:22:16 +00:00
|
|
|
);
|
2010-01-04 05:17:42 +00:00
|
|
|
|
2010-01-05 04:58:09 +00:00
|
|
|
/**
|
|
|
|
* The classname for the TestManager being used
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-01-10 00:35:01 +00:00
|
|
|
var $_managerClass = 'TestManager';
|
2010-01-05 04:58:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Instance of the Manager being used.
|
|
|
|
*
|
|
|
|
* @var TestManager subclass
|
|
|
|
*/
|
|
|
|
var $Manager;
|
|
|
|
|
2010-01-06 04:12:28 +00:00
|
|
|
/**
|
|
|
|
* Baseurl for the request
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_baseUrl;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base dir of the request. Used for accessing assets.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $_baseDir;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function CakeTestSuiteDispatcher() {
|
|
|
|
$this->_baseUrl = $_SERVER['PHP_SELF'];
|
2010-03-19 21:20:51 +00:00
|
|
|
$dir = rtrim(dirname($this->_baseUrl), '\\');
|
2010-01-14 03:29:10 +00:00
|
|
|
$this->_baseDir = ($dir === '/') ? $dir : $dir . '/';
|
2010-01-06 04:12:28 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 04:22:16 +00:00
|
|
|
/**
|
|
|
|
* Runs the actions required by the URL parameters.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function dispatch() {
|
|
|
|
$this->_checkSimpleTest();
|
|
|
|
$this->_parseParams();
|
|
|
|
|
|
|
|
if ($this->params['group']) {
|
|
|
|
$this->_runGroupTest();
|
|
|
|
} elseif ($this->params['case']) {
|
|
|
|
$this->_runTestCase();
|
|
|
|
} elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
|
2010-01-06 04:16:12 +00:00
|
|
|
$this->_testCaseList();
|
2010-01-04 04:22:16 +00:00
|
|
|
} else {
|
2010-01-06 04:16:12 +00:00
|
|
|
$this->_groupTestList();
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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')) {
|
2010-01-13 13:02:45 +00:00
|
|
|
$baseDir = $this->_baseDir;
|
2010-01-06 03:51:39 +00:00
|
|
|
include CAKE_TESTS_LIB . 'templates' . DS . 'simpletest.php';
|
2010-01-04 04:22:16 +00:00
|
|
|
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')) {
|
2010-01-13 13:02:45 +00:00
|
|
|
$baseDir = $this->_baseDir;
|
2010-01-06 03:51:39 +00:00
|
|
|
include CAKE_TESTS_LIB . 'templates' . DS . 'xdebug.php';
|
2010-01-04 04:22:16 +00:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 04:16:12 +00:00
|
|
|
/**
|
|
|
|
* Generates a page containing the a list of test cases that could be run.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _testCaseList() {
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter =& $this->getReporter();
|
2010-01-09 16:20:47 +00:00
|
|
|
$Reporter->paintDocumentStart();
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter->paintTestMenu();
|
2010-01-07 04:02:37 +00:00
|
|
|
$Reporter->testCaseList();
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter->paintDocumentEnd();
|
2010-01-06 04:16:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generates a page containing a list of group tests that could be run.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _groupTestList() {
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter =& $this->getReporter();
|
2010-01-09 16:20:47 +00:00
|
|
|
$Reporter->paintDocumentStart();
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter->paintTestMenu();
|
2010-01-07 04:02:37 +00:00
|
|
|
$Reporter->groupTestList();
|
2010-01-07 03:52:04 +00:00
|
|
|
$Reporter->paintDocumentEnd();
|
2010-01-06 04:16:12 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 05:17:42 +00:00
|
|
|
/**
|
|
|
|
* Sets the Manager to use for the request.
|
|
|
|
*
|
|
|
|
* @return string The manager class name
|
|
|
|
* @static
|
|
|
|
*/
|
2010-01-06 03:51:39 +00:00
|
|
|
function &getManager() {
|
2010-01-05 04:58:09 +00:00
|
|
|
if (empty($this->Manager)) {
|
|
|
|
$this->Manager = new $this->_managerClass();
|
2010-01-04 05:17:42 +00:00
|
|
|
}
|
2010-01-05 04:58:09 +00:00
|
|
|
return $this->Manager;
|
2010-01-04 05:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the reporter based on the request parameters
|
|
|
|
*
|
|
|
|
* @return void
|
2010-01-06 03:51:39 +00:00
|
|
|
* @static
|
2010-01-04 05:17:42 +00:00
|
|
|
*/
|
|
|
|
function &getReporter() {
|
|
|
|
static $Reporter = NULL;
|
|
|
|
if (!$Reporter) {
|
2010-01-06 01:10:41 +00:00
|
|
|
$type = strtolower($this->params['output']);
|
2010-01-04 05:24:39 +00:00
|
|
|
$coreClass = 'Cake' . ucwords($this->params['output']) . 'Reporter';
|
2010-01-06 01:10:41 +00:00
|
|
|
$coreFile = CAKE_TESTS_LIB . 'reporter' . DS . 'cake_' . $type . '_reporter.php';
|
2010-01-04 05:24:39 +00:00
|
|
|
|
2010-01-04 05:17:42 +00:00
|
|
|
$appClass = $this->params['output'] . 'Reporter';
|
2010-01-06 01:10:41 +00:00
|
|
|
$appFile = APPLIBS . 'test_suite' . DS . 'reporter' . DS . $type . '_reporter.php';
|
2010-01-04 05:24:39 +00:00
|
|
|
if (include_once $coreFile) {
|
2010-01-06 03:20:32 +00:00
|
|
|
$Reporter =& new $coreClass(null, $this->params);
|
2010-01-04 05:24:39 +00:00
|
|
|
} elseif (include_once $appFile) {
|
2010-01-06 03:20:32 +00:00
|
|
|
$Reporter =& new $appClass(null, $this->params);
|
2010-01-04 05:17:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $Reporter;
|
|
|
|
}
|
|
|
|
|
2010-01-04 04:22:16 +00:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
}
|
2010-01-06 14:50:39 +00:00
|
|
|
$this->params['baseUrl'] = $this->_baseUrl;
|
|
|
|
$this->params['baseDir'] = $this->_baseDir;
|
2010-01-04 05:17:42 +00:00
|
|
|
$this->getManager();
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs the group test case.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _runGroupTest() {
|
2010-01-05 04:58:09 +00:00
|
|
|
$Reporter =& CakeTestSuiteDispatcher::getReporter();
|
2010-01-26 19:22:07 +00:00
|
|
|
if ($this->params['codeCoverage']) {
|
|
|
|
CodeCoverageManager::init($this->params['group'], $Reporter);
|
|
|
|
}
|
2010-01-04 04:22:16 +00:00
|
|
|
if ('all' == $this->params['group']) {
|
2010-01-05 05:09:07 +00:00
|
|
|
$this->Manager->runAllTests($Reporter);
|
2010-01-04 04:22:16 +00:00
|
|
|
} else {
|
2010-01-05 05:09:07 +00:00
|
|
|
$this->Manager->runGroupTest(ucfirst($this->params['group']), $Reporter);
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs a test case file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _runTestCase() {
|
2010-01-05 04:58:09 +00:00
|
|
|
$Reporter =& CakeTestSuiteDispatcher::getReporter();
|
2010-01-04 04:22:16 +00:00
|
|
|
if ($this->params['codeCoverage']) {
|
2010-01-10 18:24:41 +00:00
|
|
|
CodeCoverageManager::init($this->params['case'], $Reporter);
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
2010-01-06 14:46:48 +00:00
|
|
|
$this->Manager->runTestCase($this->params['case'], $Reporter);
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
}
|