2007-08-15 08:38:41 +02:00
|
|
|
<?php
|
2008-01-08 07:37:50 +01:00
|
|
|
/**
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
|
|
|
|
2007-08-15 12:01:35 +02:00
|
|
|
// Check that PHPUnit is installed
|
2008-03-19 21:38:52 +01:00
|
|
|
function hasPhpUnit() {
|
|
|
|
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
|
|
|
|
foreach($paths as $path) {
|
2009-06-27 08:29:12 +02:00
|
|
|
if(substr($path,-1) == DIRECTORY_SEPARATOR) $path = substr($path,0,-1);
|
2008-03-19 21:38:52 +01:00
|
|
|
if(@file_exists("$path/PHPUnit/Framework.php")) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
|
2008-01-09 05:18:36 +01:00
|
|
|
/**
|
|
|
|
*/
|
2008-03-19 21:38:52 +01:00
|
|
|
if(hasPhpUnit()) {
|
2007-08-15 08:38:41 +02:00
|
|
|
require_once 'PHPUnit/Framework.php';
|
2008-08-25 03:41:58 +02:00
|
|
|
require_once 'PHPUnit/Util/Report.php';
|
2007-08-15 08:38:41 +02:00
|
|
|
require_once 'PHPUnit/TextUI/TestRunner.php';
|
2008-03-19 21:38:52 +01:00
|
|
|
}
|
2007-08-15 08:38:41 +02:00
|
|
|
|
|
|
|
/**
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
* Controller that executes PHPUnit tests.
|
2009-07-01 00:35:46 +02:00
|
|
|
*
|
|
|
|
* <h2>URL Options</h2>
|
|
|
|
* - SkipTests: A comma-separated list of test classes to skip (useful when running dev/tests/all)
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
*
|
2009-07-01 00:30:33 +02:00
|
|
|
* See {@link browse()} output for generic usage instructions.
|
|
|
|
*
|
2008-01-09 05:18:36 +01:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
2007-08-15 08:38:41 +02:00
|
|
|
*/
|
|
|
|
class TestRunner extends Controller {
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
/** @ignore */
|
|
|
|
private static $default_reporter;
|
|
|
|
|
2008-08-09 06:06:52 +02:00
|
|
|
static $url_handlers = array(
|
2008-08-09 08:18:32 +02:00
|
|
|
'' => 'browse',
|
2008-08-25 03:41:58 +02:00
|
|
|
'coverage' => 'coverage',
|
2008-08-27 10:19:46 +02:00
|
|
|
'startsession' => 'startsession',
|
|
|
|
'endsession' => 'endsession',
|
2009-03-04 08:31:23 +01:00
|
|
|
'cleanupdb' => 'cleanupdb',
|
2009-07-01 00:30:33 +02:00
|
|
|
'module/$ModuleName' => 'module',
|
2009-10-23 05:06:59 +02:00
|
|
|
'all' => 'all',
|
|
|
|
'build' => 'build',
|
2008-08-09 08:18:32 +02:00
|
|
|
'$TestCase' => 'only',
|
2008-08-09 06:06:52 +02:00
|
|
|
);
|
|
|
|
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
/**
|
|
|
|
* Override the default reporter with a custom configured subclass.
|
|
|
|
*
|
|
|
|
* @param string $reporter
|
|
|
|
*/
|
|
|
|
static function set_reporter($reporter) {
|
|
|
|
if (is_string($reporter)) $reporter = new $reporter;
|
|
|
|
self::$default_reporter = $reporter;
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
parent::init();
|
2009-09-10 03:49:56 +02:00
|
|
|
|
|
|
|
$canAccess = (Director::isDev() || Director::is_cli() || Permission::check("ADMIN"));
|
|
|
|
if(!$canAccess) return Security::permissionFailure($this);
|
|
|
|
|
2008-08-13 03:47:05 +02:00
|
|
|
if (!self::$default_reporter) self::set_reporter(Director::is_cli() ? 'CliDebugView' : 'DebugView');
|
2009-05-25 04:29:05 +02:00
|
|
|
|
|
|
|
if(!hasPhpUnit()) {
|
2009-05-25 04:31:35 +02:00
|
|
|
die("Please install PHPUnit using pear");
|
2009-05-25 04:29:05 +02:00
|
|
|
}
|
Merged revisions 53150,53681,53700,53820,54200,54459 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/roa
........
r53150 | ischommer | 2008-04-22 11:12:43 +1200 (Tue, 22 Apr 2008) | 1 line
FEATURE Added a "test mode" for /db/build which allows mock-DataObject-subclasses which are just built in a test run
........
r53681 | mrickerby | 2008-04-29 15:26:52 +1200 (Tue, 29 Apr 2008) | 1 line
adding default wrapping header and footer methods, and configurable reporting to the TestRunner
........
r53700 | mrickerby | 2008-04-29 16:41:57 +1200 (Tue, 29 Apr 2008) | 1 line
FEATURE: adding support for /dev/tests --> DevelopmentAdmin-->tests() --> TestRunner, /dev/tasks --> DevelopmentAdmin-->tasks() --> TaskRunner
........
r53820 | mrickerby | 2008-04-30 19:27:52 +1200 (Wed, 30 Apr 2008) | 1 line
BUGFIX fixing up BuildTask interface and task runner action
........
r54200 | sminnee | 2008-05-09 00:28:44 +1200 (Fri, 09 May 2008) | 1 line
Added TestSession object to help with the testing of forms
........
r54459 | sminnee | 2008-05-13 17:28:25 +1200 (Tue, 13 May 2008) | 1 line
Added a basic menu of options to /dev
........
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@54456 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-05-13 07:57:09 +02:00
|
|
|
}
|
|
|
|
|
2008-08-09 08:40:50 +02:00
|
|
|
public function Link() {
|
|
|
|
return Controller::join_links(Director::absoluteBaseURL(), 'dev/tests/');
|
|
|
|
}
|
|
|
|
|
2007-08-16 08:35:27 +02:00
|
|
|
/**
|
2009-10-23 05:06:59 +02:00
|
|
|
* Run test classes that should be run with every commit.
|
|
|
|
* Currently excludes PhpSyntaxTest
|
2007-08-16 08:35:27 +02:00
|
|
|
*/
|
2009-10-23 05:06:59 +02:00
|
|
|
function all() {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
2009-05-25 04:29:05 +02:00
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
|
|
|
unset($tests['FunctionalTest']);
|
2009-10-23 05:06:59 +02:00
|
|
|
|
|
|
|
// Remove tests that don't need to be executed every time
|
|
|
|
unset($tests['PhpSyntaxTest']);
|
|
|
|
|
2009-07-01 00:35:46 +02:00
|
|
|
foreach($tests as $class => $v) {
|
|
|
|
$reflection = new ReflectionClass($class);
|
|
|
|
if(!$reflection->isInstantiable()) unset($tests[$class]);
|
|
|
|
}
|
2009-05-25 04:29:05 +02:00
|
|
|
|
|
|
|
$this->runTests($tests);
|
2007-08-16 08:35:27 +02:00
|
|
|
}
|
2008-05-26 08:21:30 +02:00
|
|
|
|
2009-10-23 05:06:59 +02:00
|
|
|
/**
|
|
|
|
* Run test classes that should be run before build - i.e., everything possible.
|
|
|
|
*/
|
|
|
|
function build() {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
2009-10-23 05:06:59 +02:00
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
|
|
|
unset($tests['FunctionalTest']);
|
|
|
|
foreach($tests as $class => $v) {
|
|
|
|
$reflection = new ReflectionClass($class);
|
|
|
|
if(!$reflection->isInstantiable()) unset($tests[$class]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->runTests($tests);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
/**
|
|
|
|
* Browse all enabled test cases in the environment
|
|
|
|
*/
|
|
|
|
function browse() {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
2008-08-09 08:40:50 +02:00
|
|
|
self::$default_reporter->writeHeader();
|
2008-11-09 16:34:29 +01:00
|
|
|
self::$default_reporter->writeInfo('Available Tests', false);
|
|
|
|
if(Director::is_cli()) {
|
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
$relativeLink = Director::makeRelative($this->Link());
|
|
|
|
echo "sake {$relativeLink}all: Run all " . count($tests) . " tests\n";
|
|
|
|
echo "sake {$relativeLink}coverage: Runs all tests and make test coverage report\n";
|
2009-07-01 00:30:33 +02:00
|
|
|
echo "sake {$relativeLink}module/<modulename>: Runs all tests in a module folder\n";
|
2008-11-09 16:34:29 +01:00
|
|
|
foreach ($tests as $test) {
|
|
|
|
echo "sake {$relativeLink}$test: Run $test\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo '<div class="trace">';
|
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
2008-12-04 23:38:32 +01:00
|
|
|
asort($tests);
|
2008-11-09 16:34:29 +01:00
|
|
|
echo "<h3><a href=\"" . $this->Link() . "all\">Run all " . count($tests) . " tests</a></h3>";
|
|
|
|
echo "<h3><a href=\"" . $this->Link() . "coverage\">Runs all tests and make test coverage report</a></h3>";
|
|
|
|
echo "<hr />";
|
|
|
|
foreach ($tests as $test) {
|
|
|
|
echo "<h3><a href=\"" . $this->Link() . "$test\">Run $test</a></h3>";
|
|
|
|
}
|
|
|
|
echo '</div>';
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
2008-11-09 16:34:29 +01:00
|
|
|
|
2008-08-09 08:40:50 +02:00
|
|
|
self::$default_reporter->writeFooter();
|
2008-08-09 08:18:32 +02:00
|
|
|
}
|
|
|
|
|
2008-05-26 08:21:30 +02:00
|
|
|
function coverage() {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
|
|
|
ManifestBuilder::load_all_classes();
|
|
|
|
|
2009-05-25 04:29:05 +02:00
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
|
|
|
unset($tests['FunctionalTest']);
|
|
|
|
|
|
|
|
$this->runTests($tests, true);
|
2008-05-26 08:21:30 +02:00
|
|
|
}
|
2009-03-04 08:31:23 +01:00
|
|
|
|
|
|
|
function cleanupdb() {
|
|
|
|
SapphireTest::delete_all_temp_dbs();
|
|
|
|
}
|
2007-08-16 08:35:27 +02:00
|
|
|
|
|
|
|
/**
|
2009-03-31 21:42:08 +02:00
|
|
|
* Run only a single test class or a comma-separated list of tests
|
2007-08-16 08:35:27 +02:00
|
|
|
*/
|
2008-08-09 06:06:52 +02:00
|
|
|
function only($request) {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
2009-05-06 08:36:16 +02:00
|
|
|
if($request->param('TestCase') == 'all') {
|
2009-03-31 21:42:08 +02:00
|
|
|
$this->all();
|
2007-08-16 08:35:27 +02:00
|
|
|
} else {
|
2009-05-06 08:36:16 +02:00
|
|
|
$classNames = explode(',', $request->param('TestCase'));
|
2009-03-31 21:42:08 +02:00
|
|
|
foreach($classNames as $className) {
|
2009-07-17 01:56:36 +02:00
|
|
|
if(!class_exists($className) || !is_subclass_of($className, 'SapphireTest')) {
|
2009-03-31 21:42:08 +02:00
|
|
|
user_error("TestRunner::only(): Invalid TestCase '$className', cannot find matching class", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->runTests($classNames);
|
2007-08-16 08:35:27 +02:00
|
|
|
}
|
|
|
|
}
|
2009-07-01 00:30:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run tests for one or more "modules".
|
|
|
|
* A module is generally a toplevel folder, e.g. "mysite" or "sapphire".
|
|
|
|
*/
|
|
|
|
function module($request) {
|
2009-12-06 03:48:32 +01:00
|
|
|
ManifestBuilder::load_test_manifest();
|
2009-07-01 00:30:33 +02:00
|
|
|
$classNames = array();
|
|
|
|
$moduleNames = explode(',', $request->param('ModuleName'));
|
|
|
|
foreach($moduleNames as $moduleName) {
|
|
|
|
$classesForModule = ClassInfo::classes_for_folder($moduleName);
|
|
|
|
if($classesForModule) foreach($classesForModule as $class) {
|
2009-07-02 02:17:29 +02:00
|
|
|
if(class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
|
|
|
|
$classNames[] = $class;
|
|
|
|
}
|
2009-07-01 00:30:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->runTests($classNames);
|
|
|
|
}
|
2007-08-16 08:35:27 +02:00
|
|
|
|
2009-07-01 00:35:46 +02:00
|
|
|
/**
|
|
|
|
* @param array $classList
|
|
|
|
* @param boolean $coverage
|
|
|
|
*/
|
2008-05-26 08:21:30 +02:00
|
|
|
function runTests($classList, $coverage = false) {
|
2009-08-21 05:02:43 +02:00
|
|
|
$startTime = microtime(true);
|
|
|
|
|
2009-03-04 04:44:11 +01:00
|
|
|
// XDEBUG seem to cause problems with test execution :-(
|
|
|
|
if(function_exists('xdebug_disable')) xdebug_disable();
|
|
|
|
|
2008-11-10 06:06:23 +01:00
|
|
|
ini_set('max_execution_time', 0);
|
|
|
|
|
2008-08-13 04:47:14 +02:00
|
|
|
$this->setUp();
|
|
|
|
|
2009-07-01 00:35:46 +02:00
|
|
|
// Optionally skip certain tests
|
|
|
|
$skipTests = array();
|
|
|
|
if($this->request->getVar('SkipTests')) {
|
|
|
|
$skipTests = explode(',', $this->request->getVar('SkipTests'));
|
|
|
|
}
|
|
|
|
$classList = array_diff($classList, $skipTests);
|
|
|
|
|
2008-08-11 01:03:35 +02:00
|
|
|
// run tests before outputting anything to the client
|
2007-08-15 08:38:41 +02:00
|
|
|
$suite = new PHPUnit_Framework_TestSuite();
|
2009-05-01 01:52:55 +02:00
|
|
|
natcasesort($classList);
|
2007-08-16 08:35:27 +02:00
|
|
|
foreach($classList as $className) {
|
2008-01-08 03:12:18 +01:00
|
|
|
// Ensure that the autoloader pulls in the test class, as PHPUnit won't know how to do this.
|
|
|
|
class_exists($className);
|
2009-04-22 05:22:09 +02:00
|
|
|
$suite->addTest(new SapphireTestSuite($className));
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|
2008-08-11 08:10:59 +02:00
|
|
|
|
|
|
|
// Remove the error handler so that PHPUnit can add its own
|
|
|
|
restore_error_handler();
|
|
|
|
|
2008-08-11 01:03:35 +02:00
|
|
|
/*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/
|
2008-08-13 03:47:05 +02:00
|
|
|
if(Director::is_cli()) $reporter = new CliTestReporter();
|
|
|
|
else $reporter = new SapphireTestReporter();
|
|
|
|
|
|
|
|
self::$default_reporter->writeHeader("Sapphire Test Runner");
|
|
|
|
if (count($classList) > 1) {
|
2009-12-16 06:38:42 +01:00
|
|
|
self::$default_reporter->writeInfo("All Tests", "Running test cases: ",implode(", ", $classList));
|
2008-08-13 03:47:05 +02:00
|
|
|
} else {
|
|
|
|
self::$default_reporter->writeInfo($classList[0], "");
|
|
|
|
}
|
|
|
|
|
2008-08-09 08:18:32 +02:00
|
|
|
$results = new PHPUnit_Framework_TestResult();
|
|
|
|
$results->addListener($reporter);
|
|
|
|
|
2008-05-26 08:21:30 +02:00
|
|
|
if($coverage) {
|
2008-08-25 03:41:58 +02:00
|
|
|
$results->collectCodeCoverageInformation(true);
|
2008-08-09 08:18:32 +02:00
|
|
|
$suite->run($results);
|
2008-08-25 03:41:58 +02:00
|
|
|
|
ENHANCEMENT Introduced constants for system paths like /sapphire in preparation for a more flexible directory reorganisation. Instead of hardcoding your path, please use the following constants: BASE_PATH, BASE_URL, SAPPHIRE_DIR, SAPPHIRE_PATH, CMS_DIR, CMS_PATH, THIRDPARTY_DIR, THIRDPARTY_PATH, ASSETS_DIR, ASSETS_PATH, THEMES_DIR, THEMES_PATH
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@63154 467b73ca-7a2a-4603-9d3b-597d59a354a9
2008-09-27 18:02:38 +02:00
|
|
|
if(!file_exists(ASSETS_PATH . '/coverage-report')) mkdir(ASSETS_PATH . '/coverage-report');
|
|
|
|
PHPUnit_Util_Report::render($results, ASSETS_PATH . '/coverage-report/');
|
|
|
|
$coverageApp = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',Director::baseFolder())) . '.html';
|
|
|
|
$coverageTemplates = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/','_',preg_replace('/(\/$)|(^\/)/','',realpath(TEMP_FOLDER))) . '.html';
|
2008-08-25 03:41:58 +02:00
|
|
|
echo "<p>Coverage reports available here:<ul>
|
|
|
|
<li><a href=\"$coverageApp\">Coverage report of the application</a></li>
|
|
|
|
<li><a href=\"$coverageTemplates\">Coverage report of the templates</a></li>
|
|
|
|
</ul>";
|
2008-08-09 08:18:32 +02:00
|
|
|
} else {
|
|
|
|
$suite->run($results);
|
2008-05-26 08:21:30 +02:00
|
|
|
}
|
2008-05-15 10:46:40 +02:00
|
|
|
|
2008-09-23 05:22:13 +02:00
|
|
|
if(!Director::is_cli()) echo '<div class="trace">';
|
2008-08-09 08:18:32 +02:00
|
|
|
$reporter->writeResults();
|
2009-08-21 05:02:43 +02:00
|
|
|
|
|
|
|
$endTime = microtime(true);
|
|
|
|
if(Director::is_cli()) echo "\n\nTotal time: " . round($endTime-$startTime,3) . " seconds\n";
|
|
|
|
else echo "<p>Total time: " . round($endTime-$startTime,3) . " seconds</p>\n";
|
2008-08-09 08:18:32 +02:00
|
|
|
|
2008-05-15 10:46:40 +02:00
|
|
|
if(!Director::is_cli()) echo '</div>';
|
2008-05-15 06:58:13 +02:00
|
|
|
|
|
|
|
// Put the error handlers back
|
|
|
|
Debug::loadErrorHandlers();
|
|
|
|
|
2008-05-15 10:46:40 +02:00
|
|
|
if(!Director::is_cli()) self::$default_reporter->writeFooter();
|
2008-08-13 03:47:05 +02:00
|
|
|
|
2008-08-13 04:47:14 +02:00
|
|
|
$this->tearDown();
|
|
|
|
|
2008-05-15 10:46:40 +02:00
|
|
|
// Todo: we should figure out how to pass this data back through Director more cleanly
|
2008-08-13 03:47:05 +02:00
|
|
|
if(Director::is_cli() && ($results->failureCount() + $results->errorCount()) > 0) exit(2);
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
2008-08-13 04:47:14 +02:00
|
|
|
|
2008-08-27 10:19:46 +02:00
|
|
|
/**
|
|
|
|
* Start a test session.
|
|
|
|
* Usage: visit dev/tests/startsession?fixture=(fixturefile). A test database will be constructed, and your browser session will be amended
|
|
|
|
* to use this database. This can only be run on dev and test sites.
|
|
|
|
*/
|
|
|
|
function startsession() {
|
|
|
|
if(!Director::isLive()) {
|
|
|
|
if(SapphireTest::using_temp_db()) {
|
|
|
|
$endLink = Director::baseURL() . "/dev/tests/endsession";
|
|
|
|
return "<p><a id=\"end-session\" href=\"$endLink\">You're in the middle of a test session; click here to end it.</a></p>";
|
|
|
|
|
|
|
|
} else if(!isset($_GET['fixture'])) {
|
|
|
|
$me = Director::baseURL() . "/dev/tests/startsession";
|
|
|
|
return <<<HTML
|
|
|
|
<form action="$me">
|
|
|
|
<p>Enter a fixture file name to start a new test session. Don't forget to visit dev/tests/endsession when you're done!</p>
|
|
|
|
<p>Fixture file: <input id="fixture-file" name="fixture" /></p>
|
|
|
|
<input type="hidden" name="flush" value="1">
|
|
|
|
<p><input id="start-session" value="Start test session" type="submit" /></p>
|
|
|
|
</form>
|
|
|
|
HTML;
|
|
|
|
} else {
|
|
|
|
$fixtureFile = $_GET['fixture'];
|
|
|
|
|
|
|
|
// Validate fixture file
|
2010-04-13 01:14:36 +02:00
|
|
|
$realFile = realpath(BASE_PATH.'/'.$fixtureFile);
|
2008-08-27 10:19:46 +02:00
|
|
|
$baseDir = realpath(Director::baseFolder());
|
|
|
|
if(!$realFile || !file_exists($realFile)) {
|
|
|
|
return "<p>Fixture file doesn't exist</p>";
|
|
|
|
} else if(substr($realFile,0,strlen($baseDir)) != $baseDir) {
|
|
|
|
return "<p>Fixture file must be inside $baseDir</p>";
|
|
|
|
} else if(substr($realFile,-4) != '.yml') {
|
|
|
|
return "<p>Fixture file must be a .yml file</p>";
|
|
|
|
} else if(!preg_match('/^([^\/.][^\/]+)\/tests\//', $fixtureFile)) {
|
|
|
|
return "<p>Fixture file must be inside the tests subfolder of one of your modules.</p>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbname = SapphireTest::create_temp_db();
|
2008-10-09 20:49:24 +02:00
|
|
|
|
2008-08-27 10:19:46 +02:00
|
|
|
DB::set_alternative_database_name($dbname);
|
|
|
|
|
|
|
|
$fixture = new YamlFixture($_GET['fixture']);
|
|
|
|
$fixture->saveIntoDatabase();
|
|
|
|
|
|
|
|
return "<p>Started testing session with fixture '$fixtureFile'. Time to start testing; where would you like to start?</p>
|
|
|
|
<ul>
|
|
|
|
<li><a id=\"home-link\" href=\"" .Director::baseURL() . "\">Homepage - published site</a></li>
|
|
|
|
<li><a id=\"draft-link\" href=\"" .Director::baseURL() . "?stage=Stage\">Homepage - draft site</a></li>
|
|
|
|
<li><a id=\"admin-link\" href=\"" .Director::baseURL() . "admin/\">CMS Admin</a></li>
|
|
|
|
</ul>";
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return "<p>startession can only be used on dev and test sites</p>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function endsession() {
|
|
|
|
SapphireTest::kill_temp_db();
|
|
|
|
DB::set_alternative_database_name(null);
|
|
|
|
|
|
|
|
return "<p>Test session ended.</p>";
|
|
|
|
}
|
|
|
|
|
2008-08-13 04:47:14 +02:00
|
|
|
function setUp() {
|
2009-11-27 01:24:56 +01:00
|
|
|
// The first DB test will sort out the DB, we don't have to
|
2008-10-16 21:48:12 +02:00
|
|
|
SSViewer::flush_template_cache();
|
2008-08-13 04:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
SapphireTest::kill_temp_db();
|
2009-02-03 22:17:23 +01:00
|
|
|
DB::set_alternative_database_name(null);
|
2008-08-13 04:47:14 +02:00
|
|
|
}
|
2007-08-15 12:01:35 +02:00
|
|
|
}
|
|
|
|
|
2008-01-10 01:33:18 +01:00
|
|
|
// This class is here to help with documentation.
|
2008-03-19 21:38:52 +01:00
|
|
|
if(!hasPhpUnit()) {
|
2008-01-10 01:33:18 +01:00
|
|
|
/**
|
|
|
|
* PHPUnit is a testing framework that can be installed using PEAR.
|
|
|
|
* It's not bundled with Sapphire, you will need to install it yourself.
|
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage testing
|
|
|
|
*/
|
|
|
|
class PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
}
|
2007-08-15 08:38:41 +02:00
|
|
|
}
|