diff --git a/app/webroot/test.php b/app/webroot/test.php new file mode 100644 index 000000000..fb3fd2cfe --- /dev/null +++ b/app/webroot/test.php @@ -0,0 +1,231 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.cake.tests.libs + * @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 + */ +error_reporting(E_ALL); +set_time_limit(600); +ini_set('memory_limit','128M'); +class CakeDummyTestClass{ + +} + +if (!defined('DS')) { + define('DS', DIRECTORY_SEPARATOR); +} +if (!defined('ROOT')) { + //define('ROOT', 'FULL PATH TO DIRECTORY WHERE APP DIRECTORY IS LOCATED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; + define('ROOT', dirname(dirname(dirname(dirname(__FILE__)))).DS); +} +if (!defined('APP_DIR')) { + //define('APP_DIR', 'DIRECTORY NAME OF APPLICATION'; + define ('APP_DIR', basename(dirname(dirname(dirname(__FILE__)))).DS); +} +/** + * This only needs to be changed if the cake installed libs are located + * outside of the distributed directory structure. + */ +if (!defined('CAKE_CORE_INCLUDE_PATH')) { + //define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR'; + define('CAKE_CORE_INCLUDE_PATH', ROOT); +} +if (!defined('WEBROOT_DIR')) { + define ('WEBROOT_DIR', basename(dirname(dirname(__FILE__)))); +} +define('WWW_ROOT', dirname(dirname(__FILE__))); + +if (!defined('CORE_PATH')) { + if (function_exists('ini_set')) { + ini_set('include_path', CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get('include_path')); + define('APP_PATH', null); + define('CORE_PATH', null); + } else { + define('APP_PATH', ROOT . DS . APP_DIR . DS); + define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); + } +} + +require_once APP_PATH . 'core.php'; +if(DEBUG < 1) { + die('Invalid url.'); +} +require_once 'cake' . DS . 'bootstrap.php'; +require_once 'cake' . DS . 'basics.php'; +require_once 'cake' . DS . 'config' . DS . 'paths.php'; +require_once 'cake' . DS . 'tests' . DS . 'lib' . DS . 'test_manager.php'; +vendor('simpletest' . DS . 'reporter'); + +if (!isset($_SERVER['SERVER_NAME'])) { + $_SERVER['SERVER_NAME'] = ''; +} +if (empty( $_GET['output'])) { + $_GET['output'] = 'html'; +} + +if (!defined('BASE_URL')){ + $dispatch =& new Dispatcher(); + define('BASE_URL', $dispatch->baseUrl()); +} +/** + * + * Used to determine output to display + */ +define('CAKE_TEST_OUTPUT_HTML',1); +define('CAKE_TEST_OUTPUT_TEXT',2); + +if(isset($_GET['output']) && $_GET['output'] == 'html') { + define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_HTML); +} else { + define('CAKE_TEST_OUTPUT', CAKE_TEST_OUTPUT_TEXT); +} + + function &CakeTestsGetReporter() { + static $Reporter = NULL; + if (!$Reporter) { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + require_once TESTS . 'lib'.DS.'cake_reporter.php'; + $Reporter = new CakeHtmlReporter(); + break; + default: + $Reporter = new TextReporter(); + break; + } + } + return $Reporter; + } + + function CakePHPTestRunMore() { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + echo "

Run more tests

\n"; + break; + } + } + + function CakePHPTestCaseList() { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + if (isset($_GET['app'])) { + echo HtmlTestManager::getTestCaseList(APP_TEST_CASES); + } else { + echo HtmlTestManager::getTestCaseList(CORE_TEST_CASES); + } + break; + case CAKE_TEST_OUTPUT_TEXT: + default: + if (isset($_GET['app'])) { + echo TextTestManager::getTestCaseList(APP_TEST_CASES); + } else { + echo TextTestManager::getTestCaseList(CORE_TEST_CASES); + } + break; + } + } + + function CakePHPTestGroupTestList() { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + if (isset($_GET['app'])) { + echo HtmlTestManager::getGroupTestList(APP_TEST_GROUPS); + } else { + echo HtmlTestManager::getGroupTestList(CORE_TEST_GROUPS); + } + break; + case CAKE_TEST_OUTPUT_TEXT: + default: + if (isset($_GET['app'])) { + echo TextTestManager::getGroupTestList(APP_TEST_GROUPS); + } else { + echo TextTestManager::getGroupTestList(CORE_TEST_GROUPS); + } + break; + } + } + + function CakePHPTestHeader() { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + $baseUrl = BASE_URL; + include 'cake' . DS . 'tests' . DS . 'lib' . DS . 'header.php'; + break; + case CAKE_TEST_OUTPUT_TEXT: + default: + header(' content-type: text/plain'); + break; + } + } + + function CakePHPTestSuiteHeader() { + switch (CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + $groups = $_SERVER['PHP_SELF'].'?show=groups'; + $cases = $_SERVER['PHP_SELF'].'?show=cases'; + include 'cake' . DS . 'tests' . DS . 'lib' . DS . 'content.php'; + break; + } + } + + function CakePHPTestSuiteFooter() { + switch ( CAKE_TEST_OUTPUT) { + case CAKE_TEST_OUTPUT_HTML: + include 'cake' . DS . 'tests' . DS . 'lib' . DS . 'footer.php'; + break; + } + } + + if (isset($_GET['group'])) { + if ('all' == $_GET['group']) { + TestManager::runAllTests(CakeTestsGetReporter()); + } else { + if (isset($_GET['app'])) { + TestManager::runGroupTest(ucfirst($_GET['group']), APP_TEST_GROUPS, CakeTestsGetReporter()); + } else { + TestManager::runGroupTest(ucfirst($_GET['group']), CORE_TEST_GROUPS, CakeTestsGetReporter()); + } + } + CakePHPTestRunMore(); + CakePHPTestSuiteFooter(); + exit(); + } + + if (isset($_GET['case'])) { + TestManager::runTestCase($_GET['case'], CakeTestsGetReporter()); + CakePHPTestRunMore(); + CakePHPTestSuiteFooter(); + exit(); + } + + CakePHPTestHeader(); + CakePHPTestSuiteHeader(); + + if (isset($_GET['show']) && $_GET['show'] == 'cases') { + CakePHPTestCaseList(); + } else { + CakePHPTestGroupTestList(); + } + CakePHPTestSuiteFooter(); +?> \ No newline at end of file diff --git a/cake/tests/lib/cake_reporter.php b/cake/tests/lib/cake_reporter.php new file mode 100644 index 000000000..acd132241 --- /dev/null +++ b/cake/tests/lib/cake_reporter.php @@ -0,0 +1,90 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.cake.tests.libs + * @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 + */ +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class CakeHtmlReporter extends HtmlReporter { +/** + * Does nothing yet. The first output will + * be sent on the first test start. For use + * by a web browser. + * @access public + */ + function CakeHtmlReporter($characterSet = 'ISO-8859-1') { + parent::HtmlReporter($characterSet); + } +/** + * Paints the top of the web page setting the + * title to the name of the starting test. + * @param string $test_name Name class of test. + * @access public + */ + function paintHeader($testName) { + $this->sendNoCacheHeaders(); + $baseUrl = BASE_URL; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "CakePHP(tm) Test Suite v 1.2.0.0 :: $testName\n"; + print "\n"; + print "\n"; + print "\n\n"; + print "
\n"; + print "
\n"; + print "

CakePHP(tm) Test Suite v 1.2.0.0

\n"; + print "

$testName

\n"; + flush(); + } +/** + * Paints the end of the test with a summary of + * the passes and failures. + * @param string $test_name Name class of test. + * @access public + * + */ + function paintFooter($testName) { + $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); + print "
"; + print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); + print " test cases complete:\n"; + print "" . $this->getPassCount() . " passes, "; + print "" . $this->getFailCount() . " fails and "; + print "" . $this->getExceptionCount() . " exceptions."; + print "
\n"; + } +} +?> \ No newline at end of file diff --git a/cake/tests/lib/cake_web_test_case.php b/cake/tests/lib/cake_web_test_case.php new file mode 100644 index 000000000..b1573b6e0 --- /dev/null +++ b/cake/tests/lib/cake_web_test_case.php @@ -0,0 +1,41 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @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 + */ +/** + * Short description + */ + SimpleTestOptions::ignore('CakeWebTestCase'); +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class CakeWebTestCase extends WebTestCase { +} +?> \ No newline at end of file diff --git a/cake/tests/lib/cli_reporter.php b/cake/tests/lib/cli_reporter.php new file mode 100644 index 000000000..1f6ae4da5 --- /dev/null +++ b/cake/tests/lib/cli_reporter.php @@ -0,0 +1,111 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests + * @package cake + * @subpackage cake.cake.tests.libs + * @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 + */ + if (! defined('ST_FAILDETAIL_SEPARATOR')) { + define('ST_FAILDETAIL_SEPARATOR', "->"); + } + + if (! defined('ST_FAILS_RETURN_CODE')) { + define('ST_FAILS_RETURN_CODE', 1); + } + + if (version_compare(phpversion(), '4.3.0', '<') || + php_sapi_name() == 'cgi') { + define('STDOUT', fopen('php://stdout', 'w')); + define('STDERR', fopen('php://stderr', 'w')); + register_shutdown_function( + create_function('', 'fclose(STDOUT); fclose(STDERR); return true;')); + } +/** + * Minimal command line test displayer. Writes fail details to STDERR. Returns 0 + * to the shell if all tests pass, ST_FAILS_RETURN_CODE if any test fails. + * + * @package cake + * @subpackage cake.cake.tests.libs + */ +class CLIReporter extends SimpleReporter { + var $faildetail_separator = ST_FAILDETAIL_SEPARATOR; + + function CLIReporter($faildetail_separator = NULL) { + $this->SimpleReporter(); + if (! is_null($faildetail_separator)) { + $this->setFailDetailSeparator($faildetail_separator); + } + } + + function setFailDetailSeparator($separator) { + $this->faildetail_separator = $separator; + } +/** + * Return a formatted faildetail for printing. + */ + function &_paintTestFailDetail(&$message) { + $buffer = ''; + $faildetail = $this->getTestList(); + array_shift($faildetail); + $buffer .= implode($this->faildetail_separator, $faildetail); + $buffer .= $this->faildetail_separator . "$message\n"; + return $buffer; + } +/** + * Paint fail faildetail to STDERR. + */ + function paintFail($message) { + parent::paintFail($message); + fwrite(STDERR, 'FAIL' . $this->faildetail_separator . $this->_paintTestFailDetail($message)); + } +/** + * Paint exception faildetail to STDERR. + */ + function paintException($message) { + parent::paintException($message); + fwrite(STDERR, 'EXCEPTION' . $this->faildetail_separator . $this->_paintTestFailDetail($message)); + } +/** + * Paint a footer with test case name, timestamp, counts of fails and exceptions. + */ + function paintFooter($test_name) { + $buffer = $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ' test cases complete: '; + + if (0 < ($this->getFailCount() + $this->getExceptionCount())) { + $buffer .= $this->getPassCount() . " passes"; + if (0 < $this->getFailCount()) { + $buffer .= ", " . $this->getFailCount() . " fails"; + } + if (0 < $this->getExceptionCount()) { + $buffer .= ", " . $this->getExceptionCount() . " exceptions"; + } + $buffer .= ".\n"; + fwrite(STDOUT, $buffer); + exit(ST_FAILS_RETURN_CODE); + } else { + fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n"); + } + } +} +?> \ No newline at end of file diff --git a/cake/tests/lib/content.php b/cake/tests/lib/content.php new file mode 100644 index 000000000..8e86a6319 --- /dev/null +++ b/cake/tests/lib/content.php @@ -0,0 +1,40 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @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 + */ +?> +
+
+

CakePHP(tm) Test Suite v 1.2.0.0

+ + \ No newline at end of file diff --git a/cake/tests/lib/footer.php b/cake/tests/lib/footer.php new file mode 100644 index 000000000..977c595ab --- /dev/null +++ b/cake/tests/lib/footer.php @@ -0,0 +1,42 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @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 + */ +?> +
+ +
+ + \ No newline at end of file diff --git a/cake/tests/lib/header.php b/cake/tests/lib/header.php new file mode 100644 index 000000000..2fa8e9b68 --- /dev/null +++ b/cake/tests/lib/header.php @@ -0,0 +1,37 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @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 + */ +?> + + + + + CakePHP(tm) Test Suite v 1.2.0.0 + + + \ No newline at end of file diff --git a/cake/tests/lib/test_manager.php b/cake/tests/lib/test_manager.php new file mode 100644 index 000000000..ad60eef8b --- /dev/null +++ b/cake/tests/lib/test_manager.php @@ -0,0 +1,353 @@ + + * Copyright 2005-2007, Cake Software Foundation, Inc. + * 1785 E. Sahara Avenue, Suite 490-204 + * Las Vegas, Nevada 89104 + * + * Licensed under The Open Group Test Suite License + * Redistributions of files must retain the above copyright notice. + * + * @filesource + * @copyright Copyright 2005-2007, Cake Software Foundation, Inc. + * @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 + */ +define ('CORE_TEST_CASES', CAKE_CORE_INCLUDE_PATH .'cake' . DS . 'tests' .DS. 'cases'); +define ('CORE_TEST_GROUPS', CAKE_CORE_INCLUDE_PATH .'cake' . DS . 'tests' .DS. 'groups'); +define ('APP_TEST_CASES', ROOT . APP_DIR . 'tests' .DS. 'cases'); +define ('APP_TEST_GROUPS', ROOT . APP_DIR . 'tests' .DS. 'groups'); +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class TestManager { + var $_testExtension = '.test.php'; + var $_groupExtension = '.group.php'; + var $usersAppTest = false; + + function TestManager() { + $this->_installSimpleTest(); + if (isset($_GET['app'])) { + $this->usersAppTest = true; + } + } + + function _installSimpleTest() { + vendor('simpletest'.DS.'unit_tester', 'simpletest'.DS.'web_tester', 'simpletest'.DS.'mock_objects'); + require_once(LIB_TESTS.'cake_web_test_case.php'); + } + + function runAllTests(&$reporter) { + $manager =& new TestManager(); + + if(!empty($manager->usersAppTest)) { + $testCasePath = APP_TEST_CASES . DIRECTORY_SEPARATOR; + } else { + $testCasePath = CORE_TEST_CASES . DIRECTORY_SEPARATOR; + } + $testCases =& $manager->_getTestFileList($testCasePath); + $test =& new GroupTest('All Core Tests'); + + if (isset($_GET['app'])) { + $test =& new GroupTest('All App Tests'); + } else { + $test =& new GroupTest('All Core Tests'); + } + + foreach ($testCases as $testCase) { + $test->addTestFile($testCase); + } + $test->run($reporter); + } + + function runTestCase($testCaseFile, &$reporter) { + $manager =& new TestManager(); + + if(!empty($manager->usersAppTest)) { + $testCaseFileWithPath = APP_TEST_CASES . DIRECTORY_SEPARATOR . $testCaseFile; + } else { + $testCaseFileWithPath = CORE_TEST_CASES . DIRECTORY_SEPARATOR . $testCaseFile; + } + if (! file_exists($testCaseFileWithPath)) { + trigger_error("Test case {$testCaseFile} cannot be found", E_USER_ERROR); + } + $test =& new GroupTest("Individual test case: " . $testCaseFile); + $test->addTestFile($testCaseFileWithPath); + $test->run($reporter); + } + + function runGroupTest($groupTestName, $groupTestDirectory, &$reporter) { + $manager =& new TestManager(); + $filePath = $groupTestDirectory . DIRECTORY_SEPARATOR . + strtolower($groupTestName) . $manager->_groupExtension; + + if (! file_exists($filePath)) { + trigger_error("Group test {$groupTestName} cannot be found at {$filePath}", E_USER_ERROR); + } + + require_once $filePath; + $test =& new GroupTest($groupTestName . ' group test'); + + foreach ($manager->_getGroupTestClassNames($filePath) as $groupTest) { + $test->addTestCase(new $groupTest()); + } + $test->run($reporter); + } + + function addTestCasesFromDirectory(&$groupTest, $directory = '.') { + $manager =& new TestManager(); + $testCases =& $manager->_getTestFileList($directory); + foreach ($testCases as $testCase) { + $groupTest->addTestFile($testCase); + } + } + + function &getTestCaseList($directory = '.') { + $manager =& new TestManager(); + $return = $manager->_getTestCaseList($directory); + return $return; + } + + function &_getTestCaseList($directory = '.') { + $fileList =& $this->_getTestFileList($directory); + $testCases = array(); + foreach ($fileList as $testCaseFile) { + $testCases[$testCaseFile] = str_replace($directory . DS, '', $testCaseFile); + } + return $testCases; + } + + function &_getTestFileList($directory = '.') { + $return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestCaseFile')); + return $return; + } + + function &getGroupTestList($directory = '.') { + $manager =& new TestManager(); + $return = $manager->_getTestGroupList($directory); + return $return; + } + + function &_getTestGroupFileList($directory = '.') { + $return = $this->_getRecursiveFileList($directory, array(&$this, '_isTestGroupFile')); + return $return; + } + + 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; + } + + function &_getGroupTestClassNames($groupTestFile) { + $file = implode("\n", file($groupTestFile)); + preg_match("~lass\s+?(.*)\s+?extends GroupTest~", $file, $matches); + if (! empty($matches)) { + unset($matches[0]); + return $matches; + } else { + return array(); + } + } + + function &_getRecursiveFileList($directory = '.', $fileTestFunction) { + $dh = opendir($directory); + if (! is_resource($dh)) { + trigger_error("Couldn't open {$directory}", E_USER_ERROR); + } + + $fileList = array(); + while ($file = readdir($dh)) { + $filePath = $directory . DIRECTORY_SEPARATOR . $file; + if (0 === strpos($file, '.')) { + continue; + } + + if (is_dir($filePath)) { + $fileList = array_merge($fileList, $this->_getRecursiveFileList($filePath, $fileTestFunction)); + } + if ($fileTestFunction[0]->$fileTestFunction[1]($file)) { + $fileList[] = $filePath; + } + } + closedir($dh); + return $fileList; + } + + function _isTestCaseFile($file) { + return $this->_hasExpectedExtension($file, $this->_testExtension); + } + + function _isTestGroupFile($file) { + return $this->_hasExpectedExtension($file, $this->_groupExtension); + } + + function _hasExpectedExtension($file, $extension) { + return $extension == strtolower(substr($file, (0 - strlen($extension)))); + } +} +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class CliTestManager extends TestManager { + + function &getGroupTestList($directory = '.') { + $manager =& new CliTestManager(); + $groupTests =& $manager->_getTestGroupList($directory); + $buffer = "Available Group Test:\n"; + + foreach ($groupTests as $groupTest) { + $buffer .= " " . $groupTest . "\n"; + } + return $buffer . "\n"; + } + + function &getTestCaseList($directory = '.') { + $manager =& new CliTestManager(); + $testCases =& $manager->_getTestCaseList($directory); + $buffer = "Available Test Cases:\n"; + + foreach ($testCases as $testCaseFile => $testCase) { + $buffer .= " " . $testCaseFile . "\n"; + } + return $buffer . "\n"; + } +} +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class TextTestManager extends TestManager { + var $_url; + + function TextTestManager() { + $this->_url = $_SERVER['PHP_SELF']; + } + + function getBaseURL() { + return $this->_url; + } + + function &getGroupTestList($directory = '.') { + $manager =& new TextTestManager(); + $groupTests =& $manager->_getTestGroupList($directory); + + if (1 > count($groupTests)) { + $noGroups = "No test groups set up!\n"; + return $noGroups; + } + $buffer = "Available test groups:\n"; + $buffer .= $manager->getBaseURL() . "?group=all All tests<\n"; + + foreach ($groupTests as $groupTest) { + $buffer .= "
  • " . $groupTest . "&output=txt"."
  • \n"; + } + return $buffer . "\n"; + } + + function &getTestCaseList($directory = '.') { + $manager =& new TextTestManager(); + $testCases =& $manager->_getTestCaseList($directory); + + if (1 > count($testCases)) { + $noTestCases = "No test cases set up!"; + return $noTestCases; + } + $buffer = "Available test cases:\n"; + + foreach ($testCases as $testCaseFile => $testCase) { + $buffer .= $_SERVER['SERVER_NAME']. $manager->getBaseURL()."?case=" . $testCase . "&output=txt"."\n"; + } + return $buffer . "\n"; + } +} +/** + * Short description for class. + * + * @package cake + * @subpackage cake.cake.tests.lib + */ +class HtmlTestManager extends TestManager { + var $_url; + + function HtmlTestManager() { + $this->_url = $_SERVER['PHP_SELF']; + } + + function getBaseURL() { + return $this->_url; + } + + function &getGroupTestList($directory = '.') { + $userApp = ''; + if (isset($_GET['app'])) { + $userApp = '&app=true'; + } + $manager =& new HtmlTestManager(); + $groupTests =& $manager->_getTestGroupList($directory); + + if (isset($_GET['app'])){ + $buffer = "

    Available App Test Groups:

    \n