diff --git a/admin/report/unittest/db/access.php b/admin/report/unittest/db/access.php deleted file mode 100644 index da0247e82f3..00000000000 --- a/admin/report/unittest/db/access.php +++ /dev/null @@ -1,38 +0,0 @@ - array( - 'riskbitmask' => RISK_DATALOSS, - 'captype' => 'read', - 'contextlevel' => CONTEXT_SYSTEM, - 'archetypes' => array( - 'manager' => CAP_ALLOW - ), - - 'clonepermissionsfrom' => 'moodle/site:config', - ) -); diff --git a/admin/report/unittest/settings.php b/admin/report/unittest/settings.php deleted file mode 100644 index 8826c312661..00000000000 --- a/admin/report/unittest/settings.php +++ /dev/null @@ -1,8 +0,0 @@ -add('development', new admin_externalpage('reportsimpletest', get_string('simpletest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/index.php",'report/unittest:view')); - $ADMIN->add('development', new admin_externalpage('reportdbtest', get_string('dbtest', 'admin'), "$CFG->wwwroot/$CFG->admin/report/unittest/dbtest.php",'report/unittest:view')); -} diff --git a/admin/report/unittest/version.php b/admin/report/unittest/version.php deleted file mode 100644 index f734c5663e3..00000000000 --- a/admin/report/unittest/version.php +++ /dev/null @@ -1,28 +0,0 @@ -version = 2010090501; -$plugin->requires = 2010090501; - diff --git a/admin/report/unittest/coveragefile.php b/admin/tool/unittest/coveragefile.php similarity index 92% rename from admin/report/unittest/coveragefile.php rename to admin/tool/unittest/coveragefile.php index ba31eb13279..8c17b60e3eb 100644 --- a/admin/report/unittest/coveragefile.php +++ b/admin/tool/unittest/coveragefile.php @@ -1,5 +1,4 @@ libdir . '/filelib.php'); // basic security, require login + require site config cap require_login(); -require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)); +require_capability('tool/unittest:execute', get_context_instance(CONTEXT_SYSTEM)); // get file requested $relativepath = get_file_argument(); diff --git a/admin/tool/unittest/db/access.php b/admin/tool/unittest/db/access.php new file mode 100644 index 00000000000..6a0c8d26561 --- /dev/null +++ b/admin/tool/unittest/db/access.php @@ -0,0 +1,37 @@ +. + +/** + * Unitest caps. + * + * @package tool + * @subpackage unittest + * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$capabilities = array( + + // Note: do not add managers here, unittests are dangerous and not intended for production sites!!! + + 'tool/unittest:execute' => array( + 'riskbitmask' => RISK_DATALOSS, + 'captype' => 'write', // it writes into database, really! + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + ) + ) +); diff --git a/admin/tool/unittest/db/install.php b/admin/tool/unittest/db/install.php new file mode 100644 index 00000000000..3beba4a2114 --- /dev/null +++ b/admin/tool/unittest/db/install.php @@ -0,0 +1,39 @@ +. + +/** + * Post installation and migration code. + * + * @package tool + * @subpackage unittest + * @copyright 2011 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die; + +function xmldb_tool_unittest_install() { + global $CFG; + + // this is a hack - this plugin used to live in admin/tool/unittest, + // we want to remove the orphaned version info and capability + // unless there is a new report type with the same name + + if (!file_exists("$CFG->dirroot/report/unittest")) { + unset_all_config_for_plugin('report_unittest'); + capabilities_cleanup('report_unittest'); + } +} diff --git a/admin/report/unittest/dbtest.php b/admin/tool/unittest/dbtest.php similarity index 78% rename from admin/report/unittest/dbtest.php rename to admin/tool/unittest/dbtest.php index ae57bcfb68f..8a0a60c646f 100644 --- a/admin/report/unittest/dbtest.php +++ b/admin/tool/unittest/dbtest.php @@ -1,14 +1,34 @@ . + /** * Run database functional tests. - * @package SimpleTestEx + * + * @package tool + * @subpackage unittest + * @copyright 2008 Petr Skoda {@link http://skodak.org} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('NO_OUTPUT_BUFFERING', true); -require_once(dirname(__FILE__).'/../../../config.php'); +require(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->libdir.'/simpletestcoveragelib.php'); +require_once('simpletestlib.php'); +require_once('simpletestcoveragelib.php'); require_once('ex_simple_test.php'); require_once('ex_reporter.php'); @@ -17,7 +37,7 @@ $codecoverage = optional_param('codecoverage', false, PARAM_BOOL); $selected = optional_param_array('selected', array(), PARAM_INT); // Print the header and check access. -admin_externalpage_setup('reportdbtest'); +admin_externalpage_setup('tooldbtest'); echo $OUTPUT->header(); global $UNITTEST; @@ -108,11 +128,11 @@ echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); echo '
'; echo $OUTPUT->box_end(); diff --git a/admin/report/unittest/ex_reporter.php b/admin/tool/unittest/ex_reporter.php similarity index 90% rename from admin/report/unittest/ex_reporter.php rename to admin/tool/unittest/ex_reporter.php index 8e3fc6c9b81..995bebd82ca 100644 --- a/admin/report/unittest/ex_reporter.php +++ b/admin/tool/unittest/ex_reporter.php @@ -1,11 +1,27 @@ . + /** * A SimpleTest report format for Moodle. * - * @copyright © 2006 The Open University - * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package SimpleTestEx + * @package tool + * @subpackage unittest + * @copyright © 2006 The Open University + * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (!defined('MOODLE_INTERNAL')) { @@ -164,7 +180,7 @@ class ExHtmlReporter extends HtmlReporter { foreach ($stacktrace as $frame) { if (empty($frame['file']) || (strpos($frame['file'], 'simpletestlib') === false && strpos($frame['file'], 'simpletestcoveragelib') === false - && strpos($frame['file'], 'report/unittest') === false)) { + && strpos($frame['file'], 'tool/unittest') === false)) { $filteredstacktrace[] = $frame; $interestinglines += 1; $dotsadded = false; @@ -271,6 +287,6 @@ class ExHtmlReporter extends HtmlReporter { * Look up a lang string in the appropriate file. */ function get_string($identifier, $a = NULL) { - return get_string($identifier, 'simpletest', $a); + return get_string($identifier, 'tool_unittest', $a); } } diff --git a/admin/report/unittest/ex_simple_test.php b/admin/tool/unittest/ex_simple_test.php similarity index 86% rename from admin/report/unittest/ex_simple_test.php rename to admin/tool/unittest/ex_simple_test.php index 140360c4b83..1428a01da4b 100644 --- a/admin/report/unittest/ex_simple_test.php +++ b/admin/tool/unittest/ex_simple_test.php @@ -1,12 +1,28 @@ . + /** * A SimpleTest GroupTest that automatically finds all the * test files in a directory tree according to certain rules. * - * @copyright © 2006 The Open University - * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package SimpleTestEx + * @package tool + * @subpackage unittest + * @copyright © 2006 The Open University + * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ if (!defined('MOODLE_INTERNAL')) { diff --git a/admin/report/unittest/index.php b/admin/tool/unittest/index.php similarity index 56% rename from admin/report/unittest/index.php rename to admin/tool/unittest/index.php index c19f4e8f013..4deef62da5d 100644 --- a/admin/report/unittest/index.php +++ b/admin/tool/unittest/index.php @@ -1,18 +1,35 @@ . + /** * Run the unit tests. * - * @copyright © 2006 The Open University - * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package SimpleTestEx + * @package tool + * @subpackage unittest + * @copyright © 2006 The Open University + * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('NO_OUTPUT_BUFFERING', true); -require_once(dirname(__FILE__).'/../../../config.php'); +require(dirname(__FILE__) . '/../../../config.php'); require_once($CFG->libdir.'/adminlib.php'); -require_once($CFG->libdir.'/simpletestcoveragelib.php'); +require_once('simpletestlib.php'); +require_once('simpletestcoveragelib.php'); require_once('ex_simple_test.php'); require_once('ex_reporter.php'); @@ -27,7 +44,7 @@ $showpasses = optional_param('showpasses', false, PARAM_BOOL); $codecoverage = optional_param('codecoverage', false, PARAM_BOOL); $showsearch = optional_param('showsearch', false, PARAM_BOOL); -admin_externalpage_setup('reportsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch)); +admin_externalpage_setup('toolsimpletest', '', array('showpasses'=>$showpasses, 'showsearch'=>$showsearch)); $unittest = true; @@ -41,7 +58,7 @@ $UNITTEST = new stdClass(); define('TIME_ALLOWED_PER_UNIT_TEST', 60); // Print the header. -$strtitle = get_string('unittests', 'simpletest'); +$strtitle = get_string('unittests', 'tool_unittest'); if (!is_null($path)) { //trim so user doesn't get an error if they include a space on the end of the path (ie by pasting path) @@ -85,48 +102,68 @@ if (!is_null($path)) { } else if (is_dir($path)){ $test->findTestFiles($path); } else { - echo $OUTPUT->box(get_string('pathdoesnotexist', 'simpletest', $path), 'errorbox'); + echo $OUTPUT->box(get_string('pathdoesnotexist', 'tool_unittest', $path), 'errorbox'); $ok = false; } // If we have something to test, do it. if ($ok) { if ($path == $CFG->dirroot) { - $title = get_string('moodleunittests', 'simpletest', get_string('all', 'simpletest')); + $title = get_string('moodleunittests', 'tool_unittest', get_string('all', 'tool_unittest')); } else { - $title = get_string('moodleunittests', 'simpletest', $displaypath); + $title = get_string('moodleunittests', 'tool_unittest', $displaypath); } echo $OUTPUT->heading($title); $test->run($reporter); } - $formheader = get_string('retest', 'simpletest'); + $formheader = get_string('retest', 'tool_unittest'); } else { $displaypath = ''; echo $OUTPUT->header(); - $formheader = get_string('rununittests', 'simpletest'); + $formheader = get_string('rununittests', 'tool_unittest'); } // Print the form for adjusting options. echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); echo $OUTPUT->heading($formheader); echo ''; echo $OUTPUT->box_end(); +$otherpages = array(); +$otherpages['PDF lib test'] = new moodle_url('/admin/tool/unittest/other/pdflibtestpage.php'); +if (debugging('', DEBUG_DEVELOPER)) { + $otherpages['TODO checker'] = new moodle_url('/admin/tool/unittest/other/todochecker.php'); +} + +// print list of extra test pages that are not simpletests, +// not everything there is good enough to show to our users +if ($otherpages) { + echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter'); + echo $OUTPUT->heading(get_string('othertestpages', 'tool_unittest')); + echo '{$a}';
$string['dbsessions'] = 'Use database for session information';
-$string['dbtest'] = 'Functional DB tests';
$string['debug'] = 'Debug messages';
$string['debugall'] = 'ALL: Show all reasonable PHP debug messages';
$string['debugdeveloper'] = 'DEVELOPER: extra Moodle debug messages for developers';
@@ -936,7 +935,6 @@ $string['settingmemorylimit'] = 'Insufficient memory detected, please set higher
$string['settingsafemode'] = 'Moodle is not fully compatible with safe mode, please ask server administrator to turn it off. Running Moodle under safe mode is not supported, please expect various problems if you do so.';
$string['showcommentscount'] = 'Show comments count';
$string['showdetails'] = 'Show details';
-$string['simpletest'] = 'Unit tests';
$string['simplexmlrequired'] = 'The SimpleXML PHP extension is now required by Moodle.';
$string['sitelangchanged'] = 'Site language setting changed successfully';
$string['sitemaintenance'] = 'The site is undergoing maintenance and is currently not available';
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index 619f97a9156..c68929754cd 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -7245,7 +7245,6 @@ function get_core_subsystems() {
'repository' => 'repository',
'rss' => 'rss',
'role' => $CFG->admin.'/role',
- 'simpletest' => NULL,
'search' => 'search',
'table' => NULL,
'tag' => 'tag',
diff --git a/lib/pluginlib.php b/lib/pluginlib.php
index f85317442f4..a0cf93449ba 100644
--- a/lib/pluginlib.php
+++ b/lib/pluginlib.php
@@ -344,7 +344,7 @@ class plugin_manager {
'report' => array(
'backups', 'configlog', 'courseoverview',
'customlang', 'log', 'questioninstances',
- 'security', 'spamcleaner', 'stats', 'unittest'
+ 'security', 'spamcleaner', 'stats'
),
'repository' => array(
@@ -367,7 +367,7 @@ class plugin_manager {
),
'tool' => array(
- 'capability', 'profiling', 'unsuproles'
+ 'capability', 'profiling', 'unittest', 'unsuproles'
),
'webservice' => array(
diff --git a/lib/simpletest/testoutputlib.php b/lib/simpletest/testoutputlib.php
index 404a64cb128..49dcdf71e17 100644
--- a/lib/simpletest/testoutputlib.php
+++ b/lib/simpletest/testoutputlib.php
@@ -34,7 +34,7 @@ require_once($CFG->libdir . '/outputlib.php');
* Unit tests for the xhtml_container_stack class.
*
* These tests assume that developer debug mode is on, which, at the time of
- * writing, is true. admin/report/unittest/index.php forces it on.
+ * writing, is true. admin/tool/unittest/index.php forces it on.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
diff --git a/lib/simpletest/testpagelib_moodlepage.php b/lib/simpletest/testpagelib_moodlepage.php
index 154c2a637d5..8f699b0571e 100644
--- a/lib/simpletest/testpagelib_moodlepage.php
+++ b/lib/simpletest/testpagelib_moodlepage.php
@@ -237,7 +237,7 @@ class moodle_page_test extends UnitTestCase {
public function test_initialise_default_pagetype() {
// Exercise SUT
- $this->testpage->initialise_default_pagetype('admin/report/unittest/index.php');
+ $this->testpage->initialise_default_pagetype('admin/tool/unittest/index.php');
// Validate
$this->assertEqual('admin-report-unittest-index', $this->testpage->pagetype);
}
diff --git a/mod/quiz/report/simpletest/testreportlib.php b/mod/quiz/report/simpletest/testreportlib.php
index fcdb40ff523..87af4e99df3 100644
--- a/mod/quiz/report/simpletest/testreportlib.php
+++ b/mod/quiz/report/simpletest/testreportlib.php
@@ -26,10 +26,8 @@
defined('MOODLE_INTERNAL') || die();
-require_once(dirname(__FILE__) . '/../../../../config.php');
-
global $CFG;
-require_once($CFG->libdir . '/simpletestlib.php'); // Include the test libraries
+
require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php'); // Include the code to test