2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/* SVN FILE: $Id$ */
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Short description for file.
|
|
|
|
*
|
|
|
|
* Long description for file
|
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2008-10-30 17:30:26 +00:00
|
|
|
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @filesource
|
2008-10-30 17:30:26 +00:00
|
|
|
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
|
|
|
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4433
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-11-08 02:58:37 +00:00
|
|
|
define('CORE_TEST_CASES', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'cases');
|
|
|
|
define('CORE_TEST_GROUPS', TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'groups');
|
|
|
|
define('APP_TEST_CASES', TESTS . 'cases');
|
|
|
|
define('APP_TEST_GROUPS', TESTS . 'groups');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
|
|
|
* Short description for class.
|
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class TestManager {
|
|
|
|
var $_testExtension = '.test.php';
|
|
|
|
var $_groupExtension = '.group.php';
|
|
|
|
var $appTest = false;
|
|
|
|
var $pluginTest = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Constructor for the TestManager class
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function TestManager() {
|
|
|
|
$this->_installSimpleTest();
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$this->appTest = true;
|
|
|
|
}
|
|
|
|
if (isset($_GET['plugin'])) {
|
|
|
|
$this->pluginTest = $_GET['plugin'];
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Includes the required simpletest files in order for the testsuite to run
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _installSimpleTest() {
|
2008-11-07 11:33:13 +00:00
|
|
|
App::import('Vendor', array(
|
|
|
|
'simpletest' . DS . 'unit_tester',
|
|
|
|
'simpletest' . DS . 'mock_objects',
|
|
|
|
'simpletest' . DS . 'web_tester'
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
require_once(CAKE_TESTS_LIB . 'cake_web_test_case.php');
|
|
|
|
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs all tests in the Application depending on the current appTest setting
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $reporter
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-11-07 11:33:13 +00:00
|
|
|
function runAllTests(&$reporter, $testing = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$manager =& new TestManager();
|
|
|
|
|
|
|
|
$testCases =& $manager->_getTestFileList($manager->_getTestsPath());
|
|
|
|
if ($manager->appTest) {
|
2009-09-12 01:43:53 +00:00
|
|
|
$test =& new TestSuite('All App Tests');
|
2008-05-30 11:40:08 +00:00
|
|
|
} else if ($manager->pluginTest) {
|
2009-09-12 01:43:53 +00:00
|
|
|
$test =& new TestSuite('All ' . Inflector::humanize($manager->pluginTest) . ' Plugin Tests');
|
2008-05-30 11:40:08 +00:00
|
|
|
} else {
|
2009-09-12 01:43:53 +00:00
|
|
|
$test =& new TestSuite('All Core Tests');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
|
2008-11-07 16:17:18 +00:00
|
|
|
if ($testing) {
|
|
|
|
return $testCases;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-11-07 11:33:13 +00:00
|
|
|
|
2008-11-07 16:17:18 +00:00
|
|
|
foreach ($testCases as $testCase) {
|
|
|
|
$test->addTestFile($testCase);
|
2008-11-07 11:33:13 +00:00
|
|
|
}
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs a specific test case file
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $testCaseFile
|
|
|
|
* @param string $reporter
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-11-07 11:47:59 +00:00
|
|
|
function runTestCase($testCaseFile, &$reporter, $testing = false) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$manager =& new TestManager();
|
|
|
|
|
|
|
|
$testCaseFileWithPath = $manager->_getTestsPath() . DS . $testCaseFile;
|
2008-11-07 11:47:59 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
if (!file_exists($testCaseFileWithPath)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
trigger_error("Test case {$testCaseFile} cannot be found", E_USER_ERROR);
|
2008-11-07 11:47:59 +00:00
|
|
|
return false;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-11-07 11:47:59 +00:00
|
|
|
|
|
|
|
if ($testing) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-12 01:43:53 +00:00
|
|
|
$test =& new TestSuite("Individual test case: " . $testCaseFile);
|
2008-05-30 11:40:08 +00:00
|
|
|
$test->addTestFile($testCaseFileWithPath);
|
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Runs a specific group test file
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $groupTestName
|
|
|
|
* @param string $reporter
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function runGroupTest($groupTestName, &$reporter) {
|
|
|
|
$manager =& new TestManager();
|
|
|
|
$filePath = $manager->_getTestsPath('groups') . DS . strtolower($groupTestName) . $manager->_groupExtension;
|
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
if (!file_exists($filePath)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
trigger_error("Group test {$groupTestName} cannot be found at {$filePath}", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
require_once $filePath;
|
2009-09-12 01:43:53 +00:00
|
|
|
$test =& new TestSuite($groupTestName . ' group test');
|
2008-05-30 11:40:08 +00:00
|
|
|
foreach ($manager->_getGroupTestClassNames($filePath) as $groupTest) {
|
|
|
|
$testCase = new $groupTest();
|
|
|
|
$test->addTestCase($testCase);
|
|
|
|
if (isset($testCase->label)) {
|
|
|
|
$test->_label = $testCase->label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $test->run($reporter);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Adds all testcases in a given directory to a given GroupTest object
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $groupTest
|
|
|
|
* @param string $directory
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function addTestCasesFromDirectory(&$groupTest, $directory = '.') {
|
|
|
|
$manager =& new TestManager();
|
|
|
|
$testCases =& $manager->_getTestFileList($directory);
|
|
|
|
foreach ($testCases as $testCase) {
|
|
|
|
$groupTest->addTestFile($testCase);
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Adds a specific test file and thereby all of its test cases and group tests to a given group test file
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $groupTest
|
|
|
|
* @param string $file
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-06-07 15:19:57 +00:00
|
|
|
function addTestFile(&$groupTest, $file) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$manager =& new TestManager();
|
2008-06-10 22:38:05 +00:00
|
|
|
|
2008-06-07 15:19:57 +00:00
|
|
|
if (file_exists($file.'.test.php')) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$file .= '.test.php';
|
2008-06-07 15:19:57 +00:00
|
|
|
} elseif (file_exists($file.'.group.php')) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$file .= '.group.php';
|
|
|
|
}
|
|
|
|
$groupTest->addTestFile($file);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of test cases found in the current valid test case path
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getTestCaseList() {
|
|
|
|
$manager =& new TestManager();
|
|
|
|
$return = $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Builds the list of test cases from a given directory
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getTestCaseList($directory = '.') {
|
|
|
|
$fileList =& $this->_getTestFileList($directory);
|
|
|
|
$testCases = array();
|
|
|
|
foreach ($fileList as $testCaseFile) {
|
|
|
|
$testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile);
|
|
|
|
}
|
|
|
|
return $testCases;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Returns a list of test files from a given directory
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getTestFileList($directory = '.') {
|
|
|
|
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestCaseFile'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group tests found in the current valid test case path
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getGroupTestList() {
|
|
|
|
$manager =& new TestManager();
|
|
|
|
$return = $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group test files from a given directory
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getTestGroupFileList($directory = '.') {
|
|
|
|
$return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestGroupFile'));
|
|
|
|
return $return;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of group test files from a given directory
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getTestGroupList($directory = '.') {
|
|
|
|
$fileList =& $this->_getTestGroupFileList($directory);
|
|
|
|
$groupTests = array();
|
|
|
|
|
|
|
|
foreach ($fileList as $groupTestFile) {
|
|
|
|
$groupTests[$groupTestFile] = str_replace($this->_groupExtension, '', basename($groupTestFile));
|
|
|
|
}
|
|
|
|
sort($groupTests);
|
|
|
|
return $groupTests;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
2008-09-07 14:21:21 +00:00
|
|
|
* Returns a list of class names from a group test file
|
2008-07-30 13:37:06 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getGroupTestClassNames($groupTestFile) {
|
|
|
|
$file = implode("\n", file($groupTestFile));
|
2009-09-12 01:43:53 +00:00
|
|
|
preg_match("~lass\s+?(.*)\s+?extends TestSuite~", $file, $matches);
|
2008-11-07 11:33:13 +00:00
|
|
|
if (!empty($matches)) {
|
2008-05-30 11:40:08 +00:00
|
|
|
unset($matches[0]);
|
|
|
|
return $matches;
|
|
|
|
}
|
2009-09-12 01:43:53 +00:00
|
|
|
$matches = array();
|
|
|
|
return $matches;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Gets a recursive list of files from a given directory and matches then against
|
|
|
|
* a given fileTestFunction, like isTestCaseFile()
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &_getRecursiveFileList($directory = '.', $fileTestFunction) {
|
|
|
|
$fileList = array();
|
|
|
|
if (!is_dir($directory)) {
|
|
|
|
return $fileList;
|
|
|
|
}
|
|
|
|
|
2008-11-06 23:35:08 +00:00
|
|
|
$files = glob($directory . DS . '*');
|
2009-02-16 00:45:50 +00:00
|
|
|
$files = $files ? $files : array();
|
|
|
|
|
2008-11-06 23:35:08 +00:00
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_dir($file)) {
|
|
|
|
$fileList = array_merge($fileList, $this->_getRecursiveFileList($file, $fileTestFunction));
|
|
|
|
} elseif ($fileTestFunction[0]->$fileTestFunction[1]($file)) {
|
|
|
|
$fileList[] = $file;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $fileList;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Tests if a file has the correct test case extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _isTestCaseFile($file) {
|
|
|
|
return $this->_hasExpectedExtension($file, $this->_testExtension);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Tests if a file has the correct group test extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _isTestGroupFile($file) {
|
|
|
|
return $this->_hasExpectedExtension($file, $this->_groupExtension);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Check if a file has a specific extension
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $file
|
|
|
|
* @param string $extension
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _hasExpectedExtension($file, $extension) {
|
|
|
|
return $extension == strtolower(substr($file, (0 - strlen($extension))));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the given path to the test files depending on a given type of tests (cases, group, ..)
|
|
|
|
*
|
2008-09-07 14:21:21 +00:00
|
|
|
* @param string $type
|
2008-07-30 13:37:06 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function _getTestsPath($type = 'cases') {
|
|
|
|
if (!empty($this->appTest)) {
|
|
|
|
if ($type == 'cases') {
|
|
|
|
$result = APP_TEST_CASES;
|
|
|
|
} else if ($type == 'groups') {
|
|
|
|
$result = APP_TEST_GROUPS;
|
|
|
|
}
|
|
|
|
} else if (!empty($this->pluginTest)) {
|
|
|
|
$_pluginBasePath = APP . 'plugins' . DS . $this->pluginTest . DS . 'tests';
|
2009-10-14 13:47:07 +00:00
|
|
|
$pluginPath = App::pluginPath($this->pluginTest);
|
|
|
|
if (file_exists($pluginPath . DS . 'tests')) {
|
|
|
|
$_pluginBasePath = $pluginPath . DS . 'tests';
|
2008-07-30 13:37:06 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = $_pluginBasePath . DS . $type;
|
|
|
|
} else {
|
|
|
|
if ($type == 'cases') {
|
|
|
|
$result = CORE_TEST_CASES;
|
|
|
|
} else if ($type == 'groups') {
|
|
|
|
$result = CORE_TEST_GROUPS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
/**
|
|
|
|
* undocumented function
|
|
|
|
*
|
2008-11-08 02:58:37 +00:00
|
|
|
* @param string $type
|
2008-11-07 11:33:13 +00:00
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function getExtension($type = 'test') {
|
|
|
|
$manager =& new TestManager();
|
|
|
|
if ($type == 'test') {
|
|
|
|
return $manager->_testExtension;
|
|
|
|
}
|
|
|
|
return $manager->_groupExtension;
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-07-30 13:37:06 +00:00
|
|
|
* The CliTestManager ensures that the list of available files are printed in the correct cli format
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CliTestManager extends TestManager {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints the list of group tests in a cli friendly format
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getGroupTestList() {
|
|
|
|
$manager =& new CliTestManager();
|
|
|
|
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
|
$buffer = "Available Group Test:\n";
|
|
|
|
|
|
|
|
foreach ($groupTests as $groupTest) {
|
|
|
|
$buffer .= " " . $groupTest . "\n";
|
|
|
|
}
|
|
|
|
return $buffer . "\n";
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints the list of test cases in a cli friendly format
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getTestCaseList() {
|
|
|
|
$manager =& new CliTestManager();
|
|
|
|
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
|
$buffer = "Available Test Cases:\n";
|
|
|
|
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
|
$buffer .= " " . $testCaseFile . "\n";
|
|
|
|
}
|
|
|
|
return $buffer . "\n";
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-07-30 13:37:06 +00:00
|
|
|
* The TextTestManager ensures that the list of available tests is printed as a list of urls in a text-friendly format
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class TextTestManager extends TestManager {
|
|
|
|
var $_url;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function TextTestManager() {
|
|
|
|
parent::TestManager();
|
|
|
|
$this->_url = $_SERVER['PHP_SELF'];
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the base url
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function getBaseURL() {
|
|
|
|
return $this->_url;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of available group tests in a text-friendly format
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getGroupTestList() {
|
|
|
|
$manager =& new TextTestManager();
|
|
|
|
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
|
|
|
|
|
$buffer = "Core Test Groups:\n";
|
2008-11-07 11:33:13 +00:00
|
|
|
$urlExtra = '';
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($manager->appTest) {
|
|
|
|
$buffer = "App Test Groups:\n";
|
|
|
|
$urlExtra = '&app=true';
|
|
|
|
} else if ($manager->pluginTest) {
|
|
|
|
$buffer = Inflector::humanize($manager->pluginTest) . " Test Groups:\n";
|
|
|
|
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
|
}
|
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
$buffer .= "All tests\n" . $_SERVER['SERVER_NAME'] . $manager->getBaseURL() . "?group=all&output=txt{$urlExtra}\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
foreach ((array)$groupTests as $groupTest) {
|
|
|
|
$buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?group=" . $groupTest . "&output=txt{$urlExtra}"."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return $buffer;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns a list of available test cases in a text-friendly format
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getTestCaseList() {
|
|
|
|
$manager =& new TextTestManager();
|
|
|
|
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
|
|
|
|
|
$buffer = "Core Test Cases:\n";
|
2008-11-07 11:33:13 +00:00
|
|
|
$urlExtra = '';
|
2008-05-30 11:40:08 +00:00
|
|
|
if ($manager->appTest) {
|
|
|
|
$buffer = "App Test Cases:\n";
|
|
|
|
$urlExtra = '&app=true';
|
|
|
|
} else if ($manager->pluginTest) {
|
|
|
|
$buffer = Inflector::humanize($manager->pluginTest) . " Test Cases:\n";
|
|
|
|
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 > count($testCases)) {
|
|
|
|
$buffer .= "EMPTY";
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
|
|
|
$buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?case=" . $testCase . "&output=txt"."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$buffer .= "\n";
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2008-07-30 13:37:06 +00:00
|
|
|
* The HtmlTestManager provides the foundation for the web-based CakePHP testsuite.
|
|
|
|
* It prints the different lists of tests and provides the interface for CodeCoverage, etc.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2008-10-30 17:30:26 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class HtmlTestManager extends TestManager {
|
|
|
|
var $_url;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function HtmlTestManager() {
|
|
|
|
parent::TestManager();
|
|
|
|
$this->_url = $_SERVER['PHP_SELF'];
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns the current base url
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function getBaseURL() {
|
|
|
|
return $this->_url;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints the links to the available group tests
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getGroupTestList() {
|
|
|
|
$urlExtra = '';
|
|
|
|
$manager =& new HtmlTestManager();
|
|
|
|
$groupTests =& $manager->_getTestGroupList($manager->_getTestsPath('groups'));
|
|
|
|
|
|
|
|
$buffer = "<h3>Core Test Groups:</h3>\n<ul>";
|
|
|
|
$urlExtra = null;
|
|
|
|
if ($manager->appTest) {
|
|
|
|
$buffer = "<h3>App Test Groups:</h3>\n<ul>";
|
|
|
|
$urlExtra = '&app=true';
|
|
|
|
} else if ($manager->pluginTest) {
|
|
|
|
$buffer = "<h3>" . Inflector::humanize($manager->pluginTest) . " Test Groups:</h3>\n<ul>";
|
|
|
|
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?group=all$urlExtra'>All tests</a></li>\n";
|
|
|
|
|
2008-11-07 11:33:13 +00:00
|
|
|
foreach ($groupTests as $groupTest) {
|
2008-05-30 11:40:08 +00:00
|
|
|
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?group={$groupTest}" . "{$urlExtra}'>" . $groupTest . "</a></li>\n";
|
|
|
|
}
|
2008-06-10 22:38:05 +00:00
|
|
|
$buffer .= "</ul>\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
return $buffer;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints the links to the available test cases
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &getTestCaseList() {
|
|
|
|
$urlExtra = '';
|
|
|
|
$manager =& new HtmlTestManager();
|
|
|
|
$testCases =& $manager->_getTestCaseList($manager->_getTestsPath());
|
|
|
|
|
|
|
|
$buffer = "<h3>Core Test Cases:</h3>\n<ul>";
|
|
|
|
$urlExtra = null;
|
|
|
|
if ($manager->appTest) {
|
|
|
|
$buffer = "<h3>App Test Cases:</h3>\n<ul>";
|
|
|
|
$urlExtra = '&app=true';
|
|
|
|
} else if ($manager->pluginTest) {
|
|
|
|
$buffer = "<h3>" . Inflector::humanize($manager->pluginTest) . " Test Cases:</h3>\n<ul>";
|
|
|
|
$urlExtra = '&plugin=' . $manager->pluginTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 > count($testCases)) {
|
|
|
|
$buffer .= "<strong>EMPTY</strong>";
|
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($testCases as $testCaseFile => $testCase) {
|
2008-06-03 12:58:20 +00:00
|
|
|
$title = explode(strpos($testCase, '\\') ? '\\' : '/', str_replace('.test.php', '', $testCase));
|
|
|
|
$title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]);
|
|
|
|
$title = join(' / ', $title);
|
|
|
|
|
|
|
|
$buffer .= "<li><a href='" . $manager->getBaseURL() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-10 22:38:05 +00:00
|
|
|
$buffer .= "</ul>\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
return $buffer;
|
|
|
|
}
|
|
|
|
}
|
2009-09-13 17:29:44 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
if (function_exists('caketestsgetreporter')) {
|
|
|
|
echo "You need a new test.php. \n";
|
2009-07-29 08:17:06 +00:00
|
|
|
echo "Try this one: " . dirname(CONSOLE_LIBS) . "templates" . DS . "skel" . DS . "webroot" . DS . "test.php";
|
2008-05-30 11:40:08 +00:00
|
|
|
exit();
|
|
|
|
} else {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Returns an object of the currently needed reporter
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function &CakeTestsGetReporter() {
|
|
|
|
static $Reporter = NULL;
|
|
|
|
if (!$Reporter) {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
|
|
|
require_once CAKE_TESTS_LIB . 'cake_reporter.php';
|
|
|
|
$Reporter =& new CakeHtmlReporter();
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
default:
|
2009-10-31 07:30:59 +00:00
|
|
|
require_once CAKE_TESTS_LIB . 'cake_text_reporter.php';
|
|
|
|
$Reporter =& new CakeTextReporter();
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $Reporter;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Provides the "Run More" links in the testsuite interface
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestRunMore() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
|
|
|
if (isset($_GET['group'])) {
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$show = '?show=groups&app=true';
|
|
|
|
} else if (isset($_GET['plugin'])) {
|
|
|
|
$show = '?show=groups&plugin=' . $_GET['plugin'];
|
|
|
|
} else {
|
|
|
|
$show = '?show=groups';
|
|
|
|
}
|
|
|
|
$query = '?group='.$_GET['group'];
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$query .= '&app=true';
|
|
|
|
} elseif (isset($_GET['plugin'])) {
|
|
|
|
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isset($_GET['case'])) {
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$show = '?show=cases&app=true';
|
|
|
|
} else if (isset($_GET['plugin'])) {
|
|
|
|
$show = '?show=cases&plugin=' . $_GET['plugin'];
|
|
|
|
} else {
|
|
|
|
$show = '?show=cases';
|
|
|
|
}
|
|
|
|
$query = '?case='.$_GET['case'];
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$query .= '&app=true';
|
|
|
|
} elseif (isset($_GET['plugin'])) {
|
|
|
|
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
|
}
|
|
|
|
}
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-05-30 11:40:08 +00:00
|
|
|
echo "<p><a href='" . RUN_TEST_LINK . $show . "'>Run more tests</a> | <a href='" . RUN_TEST_LINK . $query . "&show_passes=1'>Show Passes</a> | \n";
|
2008-11-07 11:33:13 +00:00
|
|
|
|
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Provides the links to analyzing code coverage
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestAnalyzeCodeCoverage() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
|
|
|
if (isset($_GET['case'])) {
|
|
|
|
$query = '?case='.$_GET['case'];
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$query .= '&app=true';
|
|
|
|
} elseif (isset($_GET['plugin'])) {
|
|
|
|
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$query = '?group='.$_GET['group'];
|
|
|
|
if (isset($_GET['app'])) {
|
|
|
|
$query .= '&app=true';
|
|
|
|
} elseif (isset($_GET['plugin'])) {
|
|
|
|
$query .= '&plugin=' . $_GET['plugin'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$query .= '&code_coverage=true';
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-05-30 11:40:08 +00:00
|
|
|
echo " <a href='" . RUN_TEST_LINK . $query . "'>Analyze Code Coverage</a></p>\n";
|
2008-11-07 11:33:13 +00:00
|
|
|
|
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints a list of test cases
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestCaseList() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-05-30 11:40:08 +00:00
|
|
|
echo HtmlTestManager::getTestCaseList();
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
|
default:
|
|
|
|
echo TextTestManager::getTestCaseList();
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Prints a list of group tests
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestGroupTestList() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
|
|
|
echo HtmlTestManager::getGroupTestList();
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
|
default:
|
|
|
|
echo TextTestManager::getGroupTestList();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Includes the Testsuite Header
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestHeader() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-06-17 05:11:57 +00:00
|
|
|
if (!class_exists('dispatcher')) {
|
|
|
|
require CAKE . 'dispatcher.php';
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
$dispatch =& new Dispatcher();
|
|
|
|
$dispatch->baseUrl();
|
|
|
|
define('BASE', $dispatch->webroot);
|
|
|
|
$baseUrl = BASE;
|
|
|
|
$characterSet = 'charset=utf-8';
|
|
|
|
include CAKE_TESTS_LIB . 'header.php';
|
2008-11-07 11:33:13 +00:00
|
|
|
|
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
case CAKE_TEST_OUTPUT_TEXT:
|
|
|
|
default:
|
|
|
|
header('content-type: text/plain');
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Provides the left hand navigation for the testsuite
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestSuiteHeader() {
|
|
|
|
switch (CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-05-30 11:40:08 +00:00
|
|
|
$groups = $_SERVER['PHP_SELF'].'?show=groups';
|
|
|
|
$cases = $_SERVER['PHP_SELF'].'?show=cases';
|
2009-06-10 23:13:39 +00:00
|
|
|
$plugins = App::objects('plugin');
|
2008-05-30 11:40:08 +00:00
|
|
|
include CAKE_TESTS_LIB . 'content.php';
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-07-30 13:37:06 +00:00
|
|
|
/**
|
|
|
|
* Provides the testsuite footer text
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function CakePHPTestSuiteFooter() {
|
|
|
|
switch ( CAKE_TEST_OUTPUT) {
|
|
|
|
case CAKE_TEST_OUTPUT_HTML:
|
2008-06-10 22:38:05 +00:00
|
|
|
ob_start();
|
2008-05-30 11:40:08 +00:00
|
|
|
$baseUrl = BASE;
|
|
|
|
include CAKE_TESTS_LIB . 'footer.php';
|
2008-11-07 11:33:13 +00:00
|
|
|
break;
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|