From b412f9c4c9af3eada5006e020fac02ad3bb25183 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 17 Sep 2011 11:51:00 +0200 Subject: [PATCH] MDL-29029 move all the simpletest bits into new tool unittest AMOS BEGIN MOV [pluginname,report_unittest],[pluginname,tool_unittest] MOV [unittest:view,report_unittest],[unittest:execute,tool_unittest] MOV [dbtest,core_admin],[dbtest,tool_unittest] MOV [addconfigprefix,core_simpletest],[addconfigprefix,tool_unittest] MOV [all,core_simpletest],[all,tool_unittest] MOV [codecoverageanalysis,core_simpletest],[codecoverageanalysis,tool_unittest] MOV [codecoveragecompletereport,core_simpletest],[codecoveragecompletereport,tool_unittest] MOV [codecoveragedisabled,core_simpletest],[codecoveragedisabled,tool_unittest] MOV [codecoveragelatestdetails,core_simpletest],[codecoveragelatestdetails,tool_unittest] MOV [codecoveragelatestreport,core_simpletest],[codecoveragelatestreport,tool_unittest] MOV [confignonwritable,core_simpletest],[confignonwritable,tool_unittest] MOV [coveredlines,core_simpletest],[coveredlines,tool_unittest] MOV [coveredpercentage,core_simpletest],[coveredpercentage,tool_unittest] MOV [deletingnoninsertedrecord,core_simpletest],[deletingnoninsertedrecord,tool_unittest] MOV [deletingnoninsertedrecords,core_simpletest],[deletingnoninsertedrecords,tool_unittest] MOV [droptesttables,core_simpletest],[droptesttables,tool_unittest] MOV [exception,core_simpletest],[exception,tool_unittest] MOV [executablelines,core_simpletest],[executablelines,tool_unittest] MOV [fail,core_simpletest],[fail,tool_unittest] MOV [ignorefile,core_simpletest],[ignorefile,tool_unittest] MOV [ignorethisfile,core_simpletest],[ignorethisfile,tool_unittest] MOV [installtesttables,core_simpletest],[installtesttables,tool_unittest] MOV [moodleunittests,core_simpletest],[moodleunittests,tool_unittest] MOV [notice,core_simpletest],[notice,tool_unittest] MOV [onlytest,core_simpletest],[onlytest,tool_unittest] MOV [pass,core_simpletest],[pass,tool_unittest] MOV [pathdoesnotexist,core_simpletest],[pathdoesnotexist,tool_unittest] MOV [prefix,core_simpletest],[prefix,tool_unittest] MOV [prefixnotset,core_simpletest],[prefixnotset,tool_unittest] MOV [reinstalltesttables,core_simpletest],[reinstalltesttables,tool_unittest] MOV [retest,core_simpletest],[retest,tool_unittest] MOV [retestonlythisfile,core_simpletest],[retestonlythisfile,tool_unittest] MOV [runall,core_simpletest],[runall,tool_unittest] MOV [runat,core_simpletest],[runat,tool_unittest] MOV [runonlyfile,core_simpletest],[runonlyfile,tool_unittest] MOV [runonlyfolder,core_simpletest],[runonlyfolder,tool_unittest] MOV [runtests,core_simpletest],[runtests,tool_unittest] MOV [rununittests,core_simpletest],[rununittests,tool_unittest] MOV [showpasses,core_simpletest],[showpasses,tool_unittest] MOV [showsearch,core_simpletest],[showsearch,tool_unittest] MOV [skip,core_simpletest],[skip,tool_unittest] MOV [stacktrace,core_simpletest],[stacktrace,tool_unittest] MOV [summary,core_simpletest],[summary,tool_unittest] MOV [tablesnotsetup,core_simpletest],[tablesnotsetup,tool_unittest] MOV [testdboperations,core_simpletest],[testdboperations,tool_unittest] MOV [testtablescsvfileunwritable,core_simpletest],[testtablescsvfileunwritable,tool_unittest] MOV [testtablesneedupgrade,core_simpletest],[testtablesneedupgrade,tool_unittest] MOV [testtablesok,core_simpletest],[testtablesok,tool_unittest] MOV [thorough,core_simpletest],[thorough,tool_unittest] MOV [timetakes,core_simpletest],[timetakes,tool_unittest] MOV [totallines,core_simpletest],[totallines,tool_unittest] MOV [uncaughtexception,core_simpletest],[uncaughtexception,tool_unittest] MOV [uncoveredlines,core_simpletest],[uncoveredlines,tool_unittest] MOV [unittestprefixsetting,core_simpletest],[unittestprefixsetting,tool_unittest] MOV [unittests,core_simpletest],[unittests,tool_unittest] MOV [updatingnoninsertedrecord,core_simpletest],[updatingnoninsertedrecord,tool_unittest] MOV [version,core_simpletest],[version,tool_unittest] AMOS END --- admin/report/unittest/db/access.php | 38 ---------- admin/report/unittest/settings.php | 8 -- admin/report/unittest/version.php | 28 ------- .../unittest/coveragefile.php | 9 +-- admin/tool/unittest/db/access.php | 37 +++++++++ admin/tool/unittest/db/install.php | 39 ++++++++++ admin/{report => tool}/unittest/dbtest.php | 36 +++++++-- .../{report => tool}/unittest/ex_reporter.php | 28 +++++-- .../unittest/ex_simple_test.php | 24 +++++- admin/{report => tool}/unittest/index.php | 75 ++++++++++++++----- .../tool/unittest/lang/en/tool_unittest.php | 16 ++-- .../filtersettingsperformancetester.php | 64 ++++++++-------- .../tool/unittest/other}/pdflibtestpage.php | 15 ++-- .../unittest/other}/test_tables.php | 2 +- .../tool/unittest/other}/todochecker.php | 18 ++--- admin/tool/unittest/settings.php | 30 ++++++++ .../tool/unittest}/simpletestcoveragelib.php | 34 ++++----- .../tool/unittest}/simpletestlib.php | 22 +++--- .../unittest/version.php} | 16 ++-- lang/en/admin.php | 2 - lib/moodlelib.php | 1 - lib/pluginlib.php | 4 +- lib/simpletest/testoutputlib.php | 2 +- lib/simpletest/testpagelib_moodlepage.php | 2 +- mod/quiz/report/simpletest/testreportlib.php | 4 +- 25 files changed, 336 insertions(+), 218 deletions(-) delete mode 100644 admin/report/unittest/db/access.php delete mode 100644 admin/report/unittest/settings.php delete mode 100644 admin/report/unittest/version.php rename admin/{report => tool}/unittest/coveragefile.php (92%) create mode 100644 admin/tool/unittest/db/access.php create mode 100644 admin/tool/unittest/db/install.php rename admin/{report => tool}/unittest/dbtest.php (78%) rename admin/{report => tool}/unittest/ex_reporter.php (90%) rename admin/{report => tool}/unittest/ex_simple_test.php (86%) rename admin/{report => tool}/unittest/index.php (56%) rename lang/en/simpletest.php => admin/tool/unittest/lang/en/tool_unittest.php (89%) rename {lib/simpletest => admin/tool/unittest/other}/filtersettingsperformancetester.php (80%) rename {lib/simpletest => admin/tool/unittest/other}/pdflibtestpage.php (92%) rename admin/{report/unittest => tool/unittest/other}/test_tables.php (97%) rename {lib/simpletest => admin/tool/unittest/other}/todochecker.php (92%) create mode 100644 admin/tool/unittest/settings.php rename {lib => admin/tool/unittest}/simpletestcoveragelib.php (94%) rename {lib => admin/tool/unittest}/simpletestlib.php (99%) rename admin/{report/unittest/lang/en/report_unittest.php => tool/unittest/version.php} (61%) diff --git a/admin/report/unittest/db/access.php b/admin/report/unittest/db/access.php deleted file mode 100644 index da0247e82f3a2..0000000000000 --- 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 8826c312661ca..0000000000000 --- 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 f734c5663e308..0000000000000 --- 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 ba31eb13279a1..8c17b60e3eb19 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 0000000000000..6a0c8d26561b6 --- /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 0000000000000..3beba4a211407 --- /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 ae57bcfb68ffc..8a0a60c646f06 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 @@ $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 '
'; 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 '
    '; @@ -134,7 +154,7 @@ $CFG->func_test_db_2 = array("native", "mssql", "localhost", "moodleuser", "password", "moodle", "test", null);

    where order of parameters is: dblibrary, dbtype, dbhost, dbuser, dbpass, dbname, prefix, dboptions

    '; -echo '

    '; +echo '

    '; 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 8e3fc6c9b810b..995bebd82ca30 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 @@ function _paintPassFail($passorfail, $message, $stacktrace = null, $debuginfo = 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 @@ function _stripParameterFromUrl($url, $param) { * 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 140360c4b8343..1428a01da4ba7 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 c19f4e8f0132b..4deef62da5d51 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 @@ $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 @@ 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 @@ } 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 7054213bfc623..ce4bb3679c16b 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' + * + * This file contains strings that were previously located in lang/en/simpletest.php * - * @package simpletest - * @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['addconfigprefix'] = 'Add prefix to config file'; @@ -34,6 +36,7 @@ $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['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['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 adcd5a77c5b94..aed2eee21aa0c 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 @@ 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 @@ break; case 'teardown': + require_sesskey(); foreach ($requiredtables as $tablename) { $table = new xmldb_table($tablename); if ($dbman->table_exists($table)) { @@ -94,6 +91,7 @@ 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 @@ 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 92ebbfb2509f8..03832ce3e713a 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 @@ public function _getfontpath() { $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 @@ public function _getfontpath() { 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 6728ce69263d2..61fb673641136 100644 --- a/admin/report/unittest/test_tables.php +++ b/admin/tool/unittest/other/test_tables.php @@ -11,7 +11,7 @@ // 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 930b327e6c579..c9228dbcf5741 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 0000000000000..a9e9f7e799e06 --- /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 eb0bd862a5d16..88943c7fc5516 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 @@ static public function get_summary_info($type) { $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 @@ static public function get_link_to_latest($type) { $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 12b1eff2feef1..d920503c7b3c6 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 @@ function testMessage($html) { 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 @@ public function __construct($label = false) { 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 @@ public function get_table_data($filename) { } 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 @@ public static function instantiate() { 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 @@ public static function instantiate() { $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 @@ public function update_record($table, $dataobject, $bulk=false) { $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 @@ public function delete_records($table, array $conditions=array()) { 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 @@ public function delete_records_select($table, $select, array $params=null) { 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 1da08967629f3..84fc757e4790d 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 c3c674b862e6f..5b8622c7b3a6c 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -407,7 +407,6 @@ $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['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 619f97a915684..c68929754cd08 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 f85317442f49b..a0cf93449ba84 100644 --- a/lib/pluginlib.php +++ b/lib/pluginlib.php @@ -344,7 +344,7 @@ public static function standard_plugins_list($type) { 'report' => array( 'backups', 'configlog', 'courseoverview', 'customlang', 'log', 'questioninstances', - 'security', 'spamcleaner', 'stats', 'unittest' + 'security', 'spamcleaner', 'stats' ), 'repository' => array( @@ -367,7 +367,7 @@ public static function standard_plugins_list($type) { ), 'tool' => array( - 'capability', 'profiling', 'unsuproles' + 'capability', 'profiling', 'unittest', 'unsuproles' ), 'webservice' => array( diff --git a/lib/simpletest/testoutputlib.php b/lib/simpletest/testoutputlib.php index 404a64cb12872..49dcdf71e17d2 100644 --- a/lib/simpletest/testoutputlib.php +++ b/lib/simpletest/testoutputlib.php @@ -34,7 +34,7 @@ * 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 154c2a637d519..8f699b0571e3f 100644 --- a/lib/simpletest/testpagelib_moodlepage.php +++ b/lib/simpletest/testpagelib_moodlepage.php @@ -237,7 +237,7 @@ public function test_set_pagetype() { 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 fcdb40ff52328..87af4e99df317 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