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 '
'; echo $OUTPUT->heading("Run functional database tests"); // TODO: localise -echo '

'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'simpletest')).'

'; +echo '

'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')).'

'; if (moodle_coverage_recorder::can_run_codecoverage()) { - echo '

'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'simpletest')).'

'; + echo '

'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')).'

'; } else { - echo '

'; print_string('codecoveragedisabled', 'simpletest'); echo '

'; + echo '

'; print_string('codecoveragedisabled', 'tool_unittest'); echo '

'; } echo '

'."Databases:".'

'; echo '
'; 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 '
'; -echo '

'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'simpletest')).'

'; -echo '

'.html_writer::checkbox('showsearch', 1, $showsearch, get_string('showsearch', 'simpletest')).'

'; +echo '

'.html_writer::checkbox('showpasses', 1, $showpasses, get_string('showpasses', 'tool_unittest')).'

'; +echo '

'.html_writer::checkbox('showsearch', 1, $showsearch, get_string('showsearch', 'tool_unittest')).'

'; if (moodle_coverage_recorder::can_run_codecoverage()) { - echo '

'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'simpletest')).'

'; + echo '

'.html_writer::checkbox('codecoverage', 1, $codecoverage, get_string('codecoverageanalysis', 'tool_unittest')).'

'; } else { - echo '

'; print_string('codecoveragedisabled', 'simpletest'); echo '

'; + echo '

'; print_string('codecoveragedisabled', 'tool_unittest'); echo '

'; } echo '

'; - echo ' '; + echo ' '; echo ''; echo '

'; -echo ''; +echo ''; echo '
'; 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 ''; + echo $OUTPUT->box_end(); +} + + // Print link to latest code coverage for this report type if (is_null($path) || !$codecoverage) { moodle_coverage_reporter::print_link_to_latest('unittest'); diff --git a/lang/en/simpletest.php b/admin/tool/unittest/lang/en/tool_unittest.php similarity index 89% rename from lang/en/simpletest.php rename to admin/tool/unittest/lang/en/tool_unittest.php index 7054213bfc6..ce4bb3679c1 100644 --- a/lang/en/simpletest.php +++ b/admin/tool/unittest/lang/en/tool_unittest.php @@ -1,5 +1,4 @@ . /** - * Strings for component 'simpletest', language 'en', branch 'MOODLE_20_STABLE' + * Strings for component 'tool_unittest', language 'en', branch 'MOODLE_22_STABLE' * - * @package simpletest - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * This file contains strings that were previously located in lang/en/simpletest.php + * + * @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 */ $string['addconfigprefix'] = 'Add prefix to config file'; @@ -34,6 +36,7 @@ $string['confignonwritable'] = 'The file config.php is not writeable by the web $CFG->unittestprefix = \'tst_\' // Change tst_ to a prefix of your choice, different from $CFG->prefix'; $string['coveredlines'] = 'Covered lines'; $string['coveredpercentage'] = 'Overall code coverage'; +$string['dbtest'] = 'Functional DB tests'; $string['deletingnoninsertedrecord'] = 'Trying to delete a record that was not inserted by these unit tests (id {$a->id} in table {$a->table}).'; $string['deletingnoninsertedrecords'] = 'Trying to delete records that were not inserted by these unit tests (from table {$a->table}).'; $string['droptesttables'] = 'Drop test tables'; @@ -46,8 +49,10 @@ $string['installtesttables'] = 'Install test tables'; $string['moodleunittests'] = 'Moodle unit tests: {$a}'; $string['notice'] = 'Notice'; $string['onlytest'] = 'Only run tests in'; +$string['othertestpages'] = 'Other test pages'; $string['pass'] = 'Pass'; $string['pathdoesnotexist'] = 'The path \'{$a}\' does not exist.'; +$string['pluginname'] = 'Unit tests'; $string['prefix'] = 'Unit test tables prefix'; $string['prefixnotset'] = 'The unit test database table prefix is not configured. Fill and submit this form to add it to config.php.'; $string['reinstalltesttables'] = 'Reinstall test tables'; @@ -74,6 +79,7 @@ $string['timetakes'] = 'Time taken: {$a}.'; $string['totallines'] = 'Total lines'; $string['uncaughtexception'] = 'Uncaught exception [{$a->getMessage()}] in [{$a->getFile()}:{$a->getLine()}] TESTS ABORTED.'; $string['uncoveredlines'] = 'Uncovered lines'; +$string['unittest:execute'] = 'Execute unit tests'; $string['unittestprefixsetting'] = 'Unit test prefix: {$a->unittestprefix} (Edit config.php to modify this).'; $string['unittests'] = 'Unit tests'; $string['updatingnoninsertedrecord'] = 'Trying to update a record that was not inserted by these unit tests (id {$a->id} in table {$a->table}).'; diff --git a/lib/simpletest/filtersettingsperformancetester.php b/admin/tool/unittest/other/filtersettingsperformancetester.php similarity index 80% rename from lib/simpletest/filtersettingsperformancetester.php rename to admin/tool/unittest/other/filtersettingsperformancetester.php index adcd5a77c5b..aed2eee21aa 100644 --- a/lib/simpletest/filtersettingsperformancetester.php +++ b/admin/tool/unittest/other/filtersettingsperformancetester.php @@ -1,47 +1,42 @@ . /** + * Run the unit tests. + * * A simple test script that sets up test data in the database then * measures performance of filter_get_active_in_context. * - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package moodlecore - *//** */ + * @copyright 2009 Tim Hunt + * @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 + */ -require_once(dirname(__FILE__) . '/../../config.php'); +require(dirname(__FILE__) . '/../../../../config.php'); require_once($CFG->libdir . '/ddllib.php'); require_login(); $syscontext = get_context_instance(CONTEXT_SYSTEM); -require_capability('moodle/site:config', $syscontext); +require_capability('tool/unittest:execute', $syscontext); -$baseurl = $CFG->wwwroot . '/lib/simpletest/filtersettingsperformancetester.php'; +$baseurl = new moodle_url('/admin/tool/unittest/other/filtersettingsperformancetester.php'); $title = 'filter_get_active_in_context performance test'; -$PAGE->set_url('/lib/simpletest/filtersettingsperformancetester.php'); +$PAGE->set_url($baseurl); +$PAGE->set_context($syscontext); $PAGE->navbar->add($title); $PAGE->set_title($title); $PAGE->set_heading($title); @@ -67,6 +62,7 @@ foreach ($requiredtables as $table) { switch (optional_param('action', '', PARAM_ACTION)) { case 'setup': + require_sesskey(); if ($issetup == 0) { foreach ($requiredtables as $table) { $dbman->install_one_table_from_xmldb_file($CFG->dirroot . '/lib/db/install.xml', $table); @@ -83,6 +79,7 @@ switch (optional_param('action', '', PARAM_ACTION)) { break; case 'teardown': + require_sesskey(); foreach ($requiredtables as $tablename) { $table = new xmldb_table($tablename); if ($dbman->table_exists($table)) { @@ -94,6 +91,7 @@ switch (optional_param('action', '', PARAM_ACTION)) { break; case 'test': + require_sesskey(); if ($issetup != count($requiredtables)) { echo $OUTPUT->notification('Something is wrong, please delete the test tables and try again.'); } else { @@ -116,13 +114,13 @@ $DB = $realdb; echo $OUTPUT->container_start(); -$aurl = new moodle_url($baseurl, array('action' => 'setup')); +$aurl = new moodle_url($baseurl, array('action' => 'setup', 'sesskey'=>sesskey())); echo $OUTPUT->single_button($aurl, 'Set up test tables', 'get', array('disabled'=>($issetup > 0))); -$aurl = new moodle_url($baseurl, array('action' => 'teardown')); +$aurl = new moodle_url($baseurl, array('action' => 'teardown', 'sesskey'=>sesskey())); echo $OUTPUT->single_button($aurl, 'Drop test tables', 'get', array('disabled'=>($issetup == 0))); -$aurl = new moodle_url($baseurl, array('action' => 'test')); +$aurl = new moodle_url($baseurl, array('action' => 'test', 'sesskey'=>sesskey())); echo $OUTPUT->single_button($aurl, 'Run tests', 'get', array('disabled'=>($issetup != count($requiredtables)))); echo $OUTPUT->container_end(); diff --git a/lib/simpletest/pdflibtestpage.php b/admin/tool/unittest/other/pdflibtestpage.php similarity index 92% rename from lib/simpletest/pdflibtestpage.php rename to admin/tool/unittest/other/pdflibtestpage.php index 92ebbfb2509..03832ce3e71 100644 --- a/lib/simpletest/pdflibtestpage.php +++ b/admin/tool/unittest/other/pdflibtestpage.php @@ -1,5 +1,4 @@ - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @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 */ -require_once(dirname(dirname(dirname(__FILE__))) . '/config.php'); +require(dirname(__FILE__) . '/../../../../config.php'); require_once($CFG->libdir . '/pdflib.php'); require_login(); $context = get_context_instance(CONTEXT_SYSTEM); -require_capability('moodle/site:config', $context); +require_capability('tool/unittest:execute', $context); $getpdf = optional_param('getpdf', 0, PARAM_INT); $fontfamily = optional_param('fontfamily', PDF_DEFAULT_FONT, PARAM_ALPHA); // to be configurable @@ -54,7 +55,7 @@ if ($getpdf) { $doc->SetTitle('Moodle PDF library test'); $doc->SetAuthor('Moodle ' . $CFG->release); - $doc->SetCreator('lib/simpletest/pdflibtestpage.php'); + $doc->SetCreator('admin/tool/unittest/pdflibtestpage.php'); $doc->SetKeywords('Moodle, PDF'); $doc->SetSubject('This has been generated by Moodle as its PDF library test page'); $doc->SetMargins(15, 30); @@ -133,7 +134,7 @@ if ($getpdf) { exit(); } -$PAGE->set_url('/lib/simpletest/pdflibtestpage.php'); +$PAGE->set_url('/admin/tool/unittest/other/pdflibtestpage.php'); $PAGE->set_context($context); $PAGE->set_title('PDF library test'); $PAGE->set_heading('PDF library test'); diff --git a/admin/report/unittest/test_tables.php b/admin/tool/unittest/other/test_tables.php similarity index 97% rename from admin/report/unittest/test_tables.php rename to admin/tool/unittest/other/test_tables.php index 6728ce69263..61fb6736411 100644 --- a/admin/report/unittest/test_tables.php +++ b/admin/tool/unittest/other/test_tables.php @@ -11,7 +11,7 @@ die;die;die; // extra security session_write_close(); - $return_url = "$CFG->wwwroot/$CFG->admin/report/unittest/test_tables.php"; + $return_url = "$CFG->wwwroot/$CFG->admin/tool/unittest/test_tables.php"; // Temporarily override $DB and $CFG for a fresh install on the unit test prefix diff --git a/lib/simpletest/todochecker.php b/admin/tool/unittest/other/todochecker.php similarity index 92% rename from lib/simpletest/todochecker.php rename to admin/tool/unittest/other/todochecker.php index 930b327e6c5..c9228dbcf57 100644 --- a/lib/simpletest/todochecker.php +++ b/admin/tool/unittest/other/todochecker.php @@ -1,5 +1,4 @@ libdir . '/simpletestlib.php'); + +require(dirname(__FILE__) . '/../../../../config.php'); +require_once('../simpletestlib.php'); require_login(); $context = get_context_instance(CONTEXT_SYSTEM); -require_capability('moodle/site:config', $context); +require_capability('tool/unittest:execute', $context); -$PAGE->set_url('/lib/simpletest/todochecker.php'); +$PAGE->set_url('/admin/tool/todochecker.php'); $PAGE->set_context($context); $PAGE->set_title('To-do checker'); $PAGE->set_heading('To-do checker'); diff --git a/admin/tool/unittest/settings.php b/admin/tool/unittest/settings.php new file mode 100644 index 00000000000..a9e9f7e799e --- /dev/null +++ b/admin/tool/unittest/settings.php @@ -0,0 +1,30 @@ +. + +/** + * Unittest settings + * + * @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 + */ + + +defined('MOODLE_INTERNAL') || die; + +$ADMIN->add('development', new admin_externalpage('toolsimpletest', get_string('pluginname', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/index.php", 'tool/unittest:execute')); +$ADMIN->add('development', new admin_externalpage('tooldbtest', get_string('dbtest', 'tool_unittest'), "$CFG->wwwroot/$CFG->admin/tool/unittest/dbtest.php", 'tool/unittest:execute')); diff --git a/lib/simpletestcoveragelib.php b/admin/tool/unittest/simpletestcoveragelib.php similarity index 94% rename from lib/simpletestcoveragelib.php rename to admin/tool/unittest/simpletestcoveragelib.php index eb0bd862a5d..88943c7fc55 100644 --- a/lib/simpletestcoveragelib.php +++ b/admin/tool/unittest/simpletestcoveragelib.php @@ -1,5 +1,4 @@ libdir.'/tablelib.php'); -require_once($CFG->libdir . '/simpletestlib.php'); -require_once($CFG->dirroot . '/' . $CFG->admin . '/report/unittest/ex_simple_test.php'); +require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/unittest/simpletestlib.php'); +require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/unittest/ex_simple_test.php'); require_once($CFG->libdir . '/spikephpcoverage/src/CoverageRecorder.php'); require_once($CFG->libdir . '/spikephpcoverage/src/reporter/HtmlCoverageReporter.php'); @@ -439,19 +437,19 @@ class moodle_coverage_reporter extends HtmlCoverageReporter { $table->id = 'codecoveragetable_' . $type; $table->rowclasses = array('label', 'value'); $table->data = array( - array(get_string('date') , userdate($data->time)), - array(get_string('files') , format_float($data->totalfiles, 0)), - array(get_string('totallines', 'simpletest') , format_float($data->totalln, 0)), - array(get_string('executablelines', 'simpletest') , format_float($data->totalcoveredln + $data->totaluncoveredln, 0)), - array(get_string('coveredlines', 'simpletest') , format_float($data->totalcoveredln, 0)), - array(get_string('uncoveredlines', 'simpletest') , format_float($data->totaluncoveredln, 0)), - array(get_string('coveredpercentage', 'simpletest'), format_float($data->totalpercentage, 2) . '%') + array(get_string('date') , userdate($data->time)), + array(get_string('files') , format_float($data->totalfiles, 0)), + array(get_string('totallines', 'tool_unittest') , format_float($data->totalln, 0)), + array(get_string('executablelines', 'tool_unittest') , format_float($data->totalcoveredln + $data->totaluncoveredln, 0)), + array(get_string('coveredlines', 'tool_unittest') , format_float($data->totalcoveredln, 0)), + array(get_string('uncoveredlines', 'tool_unittest') , format_float($data->totaluncoveredln, 0)), + array(get_string('coveredpercentage', 'tool_unittest'), format_float($data->totalpercentage, 2) . '%') ); - $url = $CFG->wwwroot . '/admin/report/unittest/coveragefile.php/' . $type . '/index.html'; + $url = $CFG->wwwroot . '/'.$CFG->admin.'/tool/unittest/coveragefile.php/' . $type . '/index.html'; $result .= $OUTPUT->heading($data->title, 3, 'main codecoverageheading'); $result .= $OUTPUT->heading('' . get_string('codecoveragecompletereport', 'simpletest') . '', 4, 'main codecoveragelink'); + ' title="">' . get_string('codecoveragecompletereport', 'tool_unittest') . '', 4, 'main codecoveragelink'); $result .= html_writer::table($table); return $OUTPUT->box($result, 'generalbox boxwidthwide boxaligncenter codecoveragebox', '', true); @@ -489,12 +487,12 @@ class moodle_coverage_reporter extends HtmlCoverageReporter { $info->files = format_float($data->totalfiles, 0); $info->percentage = format_float($data->totalpercentage, 2) . '%'; - $strlatestreport = get_string('codecoveragelatestreport', 'simpletest'); - $strlatestdetails = get_string('codecoveragelatestdetails', 'simpletest', $info); + $strlatestreport = get_string('codecoveragelatestreport', 'tool_unittest'); + $strlatestdetails = get_string('codecoveragelatestdetails', 'tool_unittest', $info); // return one link to latest complete report $result = ''; - $url = $CFG->wwwroot . '/admin/report/unittest/coveragefile.php/' . $type . '/index.html'; + $url = $CFG->wwwroot . '/'.$CFG->admin.'/tool/unittest/coveragefile.php/' . $type . '/index.html'; $result .= $OUTPUT->heading('' . $strlatestreport . '', 3, 'main codecoveragelink'); $result .= $OUTPUT->heading($strlatestdetails, 4, 'main codecoveragedetails'); diff --git a/lib/simpletestlib.php b/admin/tool/unittest/simpletestlib.php similarity index 99% rename from lib/simpletestlib.php rename to admin/tool/unittest/simpletestlib.php index 12b1eff2fee..d920503c7b3 100644 --- a/lib/simpletestlib.php +++ b/admin/tool/unittest/simpletestlib.php @@ -1,5 +1,4 @@ libdir . '/simpletestlib/simpletest.php'); require_once($CFG->libdir . '/simpletestlib/unit_tester.php'); require_once($CFG->libdir . '/simpletestlib/expectation.php'); @@ -214,7 +212,7 @@ abstract class XMLStructureExpectation extends SimpleExpectation { foreach ($parsererrors as $key => $message) { $parsererrors[$key] = $message->message; } - return 'Could not parse XML [' . $html . '] errors were [' . + return 'Could not parse XML [' . $html . '] errors were [' . implode('], [', $parsererrors) . ']'; } return $this->customMessage($html); @@ -958,7 +956,7 @@ class FakeDBUnitTestCase extends UnitTestCase { if (!file_put_contents($this->pkfile, $tabledata)) { $a = new stdClass(); $a->filename = $this->pkfile; - throw new moodle_exception('testtablescsvfileunwritable', 'simpletest', '', $a); + throw new moodle_exception('testtablescsvfileunwritable', 'tool_unittest', '', $a); } } } @@ -1010,7 +1008,7 @@ class FakeDBUnitTestCase extends UnitTestCase { } else { $a = new stdClass(); $a->filename = $this->pkfile; - throw new moodle_exception('testtablescsvfilemissing', 'simpletest', '', $a); + throw new moodle_exception('testtablescsvfilemissing', 'tool_unittest', '', $a); return false; } } @@ -1155,7 +1153,7 @@ class UnitTestDB { global $CFG, $DB; UnitTestDB::$real_db = clone($DB); if (empty($CFG->unittestprefix)) { - print_error("prefixnotset", 'simpletest'); + print_error("prefixnotset", 'tool_unittest'); } if (empty(UnitTestDB::$DB)) { @@ -1166,7 +1164,7 @@ class UnitTestDB { $manager = UnitTestDB::$DB->get_manager(); if (!$manager->table_exists('user')) { - print_error('tablesnotsetup', 'simpletest'); + print_error('tablesnotsetup', 'tool_unittest'); } $DB = new UnitTestDB(); @@ -1220,7 +1218,7 @@ class UnitTestDB { $a = new stdClass(); $a->id = $dataobject->id; $a->table = $table; - throw new moodle_exception('updatingnoninsertedrecord', 'simpletest', '', $a); + throw new moodle_exception('updatingnoninsertedrecord', 'tool_unittest', '', $a); } else { return UnitTestDB::$DB->update_record($table, $dataobject, $bulk); } @@ -1261,7 +1259,7 @@ class UnitTestDB { if ($proceed_with_delete) { return UnitTestDB::$DB->delete_records($table, $conditions); } else { - throw new moodle_exception('deletingnoninsertedrecord', 'simpletest', '', $a); + throw new moodle_exception('deletingnoninsertedrecord', 'tool_unittest', '', $a); } } @@ -1294,7 +1292,7 @@ class UnitTestDB { if ($proceed_with_delete) { return UnitTestDB::$DB->delete_records_select($table, $select, $params); } else { - throw new moodle_exception('deletingnoninsertedrecord', 'simpletest', '', $a); + throw new moodle_exception('deletingnoninsertedrecord', 'tool_unittest', '', $a); } } diff --git a/admin/report/unittest/lang/en/report_unittest.php b/admin/tool/unittest/version.php similarity index 61% rename from admin/report/unittest/lang/en/report_unittest.php rename to admin/tool/unittest/version.php index 1da08967629..84fc757e479 100644 --- a/admin/report/unittest/lang/en/report_unittest.php +++ b/admin/tool/unittest/version.php @@ -1,5 +1,4 @@ . /** - * Strings for component 'report_unittest', language 'en', branch 'MOODLE_20_STABLE' + * Unittest version info * - * @package report_unittest - * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @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 */ -$string['pluginname'] = 'Unit tests'; -$string['unittest:view'] = 'Execute unit tests'; +$plugin->version = 2011091700; // The current plugin version (Date: YYYYMMDDXX) +$plugin->requires = 2011091600; // Requires this Moodle version +$plugin->component = 'tool_unittest'; // Full name of the plugin (used for diagnostics) + diff --git a/lang/en/admin.php b/lang/en/admin.php index c3c674b862e..5b8622c7b3a 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -407,7 +407,6 @@ $string['dbmigratewarning2'] = 'Warning: You are about to start the database $string['dbmigrationdeprecateddb'] = 'This database is migrated to a new UTF8 database and deprecated. Please edit your config.php and use the new database for this moodle.'; $string['dbmigrationdupfailed'] = 'Database duplication failed with possible error:
{$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