2010-01-04 04:22:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* CakeTestSuiteDispatcher controls dispatching TestSuite web based requests.
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
2010-05-19 01:15:13 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
|
2010-01-04 04:22:16 +00:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CakeTestSuiteDispatcher handles web requests to the test suite and runs the correct action.
|
|
|
|
*
|
|
|
|
* @package cake.tests.libs
|
|
|
|
*/
|
|
|
|
class CakeTestSuiteDispatcher {
|
|
|
|
/**
|
|
|
|
* 'Request' parameters
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $params = array(
|
2010-01-04 04:22:16 +00:00
|
|
|
'codeCoverage' => false,
|
|
|
|
'case' => null,
|
|
|
|
'app' => false,
|
|
|
|
'plugin' => null,
|
|
|
|
'output' => 'html',
|
2010-01-06 03:20:32 +00:00
|
|
|
'show' => 'groups',
|
2010-05-27 02:21:34 +00:00
|
|
|
'show_passes' => false,
|
|
|
|
'filter' => 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-04-04 06:36:12 +00:00
|
|
|
protected $_managerClass = 'TestManager';
|
2010-01-05 04:58:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Instance of the Manager being used.
|
|
|
|
*
|
|
|
|
* @var TestManager subclass
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $Manager;
|
2010-01-05 04:58:09 +00:00
|
|
|
|
2010-01-06 04:12:28 +00:00
|
|
|
/**
|
|
|
|
* Baseurl for the request
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_baseUrl;
|
2010-01-06 04:12:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Base dir of the request. Used for accessing assets.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2010-04-04 06:36:12 +00:00
|
|
|
protected $_baseDir;
|
2010-01-06 04:12:28 +00:00
|
|
|
|
2010-06-26 17:48:11 +00:00
|
|
|
/**
|
|
|
|
* boolean to set auto parsing of params.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $_paramsParsed = false;
|
|
|
|
|
2010-04-15 03:24:44 +00:00
|
|
|
/**
|
|
|
|
* reporter instance used for the request
|
|
|
|
*
|
|
|
|
* @var CakeBaseReporter
|
|
|
|
*/
|
|
|
|
protected static $_Reporter = null;
|
|
|
|
|
2010-01-06 04:12:28 +00:00
|
|
|
/**
|
|
|
|
* constructor
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-04-15 02:56:51 +00:00
|
|
|
function __construct() {
|
2010-01-06 04:12:28 +00:00
|
|
|
$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() {
|
2010-05-04 21:00:06 +00:00
|
|
|
$this->_checkPHPUnit();
|
2010-01-04 04:22:16 +00:00
|
|
|
$this->_parseParams();
|
|
|
|
|
2010-06-26 16:58:03 +00:00
|
|
|
if ($this->params['case']) {
|
2010-06-26 17:48:11 +00:00
|
|
|
$value = $this->_runTestCase();
|
2010-01-04 04:22:16 +00:00
|
|
|
} else {
|
2010-06-26 17:48:11 +00:00
|
|
|
$value = $this->_testCaseList();
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$output = ob_get_clean();
|
|
|
|
echo $output;
|
2010-06-26 17:48:11 +00:00
|
|
|
return $value;
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-04 21:00:06 +00:00
|
|
|
* Checks that PHPUnit is installed. Will exit if it doesn't
|
2010-01-04 04:22:16 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2010-05-04 21:00:06 +00:00
|
|
|
function _checkPHPUnit() {
|
2010-05-04 18:10:50 +00:00
|
|
|
$found = $path = null;
|
2010-05-04 21:00:06 +00:00
|
|
|
|
|
|
|
if (@include 'PHPUnit' . DS . 'Framework.php') {
|
|
|
|
$found = true;
|
2010-05-04 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-04 21:00:06 +00:00
|
|
|
if (!$found) {
|
|
|
|
foreach (App::path('vendors') as $vendor) {
|
|
|
|
if (is_dir($vendor . 'PHPUnit')) {
|
|
|
|
$path = $vendor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($path && ini_set('include_path', $path . PATH_SEPARATOR . ini_get('include_path'))) {
|
|
|
|
$found = include 'PHPUnit' . DS . 'Framework.php';
|
|
|
|
}
|
2010-05-04 18:10:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$found) {
|
2010-01-13 13:02:45 +00:00
|
|
|
$baseDir = $this->_baseDir;
|
2010-06-29 02:59:01 +00:00
|
|
|
include CAKE_TESTS_LIB . 'templates/phpunit.php';
|
2010-01-04 04:22:16 +00:00
|
|
|
exit();
|
|
|
|
}
|
2010-05-08 20:18:45 +00:00
|
|
|
|
|
|
|
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'DEFAULT');
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-15 03:24:44 +00:00
|
|
|
include CAKE_TESTS_LIB . 'templates/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
|
|
|
}
|
|
|
|
|
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)) {
|
2010-05-04 18:10:50 +00:00
|
|
|
require_once CAKE_TESTS_LIB . 'test_manager.php';
|
2010-05-27 02:21:34 +00:00
|
|
|
$this->Manager = new $this->_managerClass($this->params);
|
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() {
|
2010-04-15 03:24:44 +00:00
|
|
|
if (!self::$_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-04-15 03:24:44 +00:00
|
|
|
$coreFile = CAKE_TESTS_LIB . 'reporter/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-04-15 03:24:44 +00:00
|
|
|
$appFile = APPLIBS . 'test_suite/reporter/' . $type . '_reporter.php';
|
2010-01-04 05:24:39 +00:00
|
|
|
if (include_once $coreFile) {
|
2010-04-15 03:24:44 +00:00
|
|
|
self::$_Reporter = new $coreClass(null, $this->params);
|
2010-01-04 05:24:39 +00:00
|
|
|
} elseif (include_once $appFile) {
|
2010-04-15 03:24:44 +00:00
|
|
|
self::$_Reporter = new $appClass(null, $this->params);
|
2010-01-04 05:17:42 +00:00
|
|
|
}
|
|
|
|
}
|
2010-04-15 03:24:44 +00:00
|
|
|
return self::$_Reporter;
|
2010-01-04 05:17:42 +00:00
|
|
|
}
|
|
|
|
|
2010-06-26 17:48:11 +00:00
|
|
|
/**
|
|
|
|
* Sets the params, calling this will bypass the auto parameter parsing.
|
|
|
|
*
|
|
|
|
* @param array $params Array of parameters for the dispatcher
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setParams($params) {
|
|
|
|
$this->params = $params;
|
|
|
|
$this->_paramsParsed = true;
|
|
|
|
}
|
|
|
|
|
2010-01-04 04:22:16 +00:00
|
|
|
/**
|
|
|
|
* Parse url params into a 'request'
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _parseParams() {
|
2010-06-26 17:48:11 +00:00
|
|
|
if (!$this->_paramsParsed) {
|
|
|
|
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;
|
|
|
|
$this->_checkXdebug();
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
}
|
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 a test case file.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function _runTestCase() {
|
2010-04-15 03:24:44 +00:00
|
|
|
$Reporter = CakeTestSuiteDispatcher::getReporter();
|
2010-06-26 17:48:11 +00:00
|
|
|
return $this->Manager->runTestCase($this->params['case'], $Reporter, $this->params['codeCoverage']);
|
2010-01-04 04:22:16 +00:00
|
|
|
}
|
|
|
|
}
|