From be02cc3687502f4f9fe9af934df81fcd5c81ffda Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sun, 18 Sep 2022 16:21:46 +0200 Subject: [PATCH] MDL-75777 phpunit: Move tests to use correct names and ns (take#6) Applied the following changes to various testcase classes: - Namespaced with component[\level2-API] - Moved to level2-API subdirectory when required. - Fixed incorrect use statements with leading backslash. - Remove file phpdoc block - Remove MOODLE_INTERNAL if not needed. - Changed code to point to global scope when needed. - Fix some relative paths and comments here and there. - All them passing individually. - Complete runs passing too. --- question/bank/comment/tests/backup_test.php | 32 +++--- .../customfields/tests/customfield_test.php | 24 ++-- .../tests/question_handler_test.php | 12 +- .../tests/qbank_preview_helper_test.php | 2 +- .../adaptive/tests/mark_display_test.php | 16 +-- .../deferredcbm/tests/question_cbm_test.php | 15 +-- .../missing/tests/missingbehaviour_test.php | 40 +++---- .../tests/datalib_reporting_queries_test.php | 33 +++--- question/engine/tests/datalib_test.php | 29 +++-- .../engine/tests/qubaid_condition_test.php | 17 ++- .../engine/tests/questionattempt_db_test.php | 35 +++--- .../engine/tests/questionattempt_test.php | 23 ++-- .../tests/questionattempt_with_steps_test.php | 30 +++-- .../tests/questionattemptiterator_test.php | 29 ++--- .../tests/questionattemptstep_db_test.php | 17 ++- .../engine/tests/questionattemptstep_test.php | 17 +-- .../questionattemptstepiterator_test.php | 26 ++--- question/engine/tests/questionbank_test.php | 26 ++--- question/engine/tests/questionstate_test.php | 17 +-- .../tests/questionusage_autosave_test.php | 20 ++-- .../questionusagebyactivity_data_test.php | 24 ++-- .../tests/questionusagebyactivity_test.php | 39 +++---- question/engine/tests/questionutils_test.php | 21 ++-- question/engine/tests/unitofwork_test.php | 39 ++++--- .../tests/blackboardformatpool_test.php | 32 +++--- .../tests/blackboardsixformatqti_test.php | 32 +++--- .../format/gift/tests/giftformat_test.php | 21 ++-- .../tests/multianswerformat_test.php | 14 +-- question/format/xml/tests/xmlformat_test.php | 107 ++++++++++-------- question/tests/backup_test.php | 83 +++++++------- question/tests/bank_view_test.php | 39 +++---- .../calculated_question_summary_test.php | 15 +-- question/tests/importexport_test.php | 11 +- .../least_used_variant_strategy_test.php | 41 ++++--- question/tests/question_bank_column_test.php | 26 ++--- .../tests/random_question_loader_test.php | 32 +++--- .../tests/formula_validation_test.php | 23 ++-- .../tests/variablesubstituter_test.php | 22 ++-- question/type/ddmarker/tests/shapes_test.php | 18 ++- question/type/essay/tests/restore_test.php | 15 +-- question/type/match/tests/backup_test.php | 19 ++-- .../missingtype/tests/missingtype_test.php | 29 ++--- .../multichoice/tests/question_multi_test.php | 45 ++++---- .../tests/question_single_test.php | 55 ++++----- question/type/numerical/tests/answer_test.php | 23 ++-- .../numerical/tests/answerprocessor_test.php | 28 +++-- .../type/tests/question_definition_test.php | 14 +-- ..._matching_answer_grading_strategy_test.php | 12 +- question/type/tests/question_hint_test.php | 19 ++-- 49 files changed, 636 insertions(+), 722 deletions(-) diff --git a/question/bank/comment/tests/backup_test.php b/question/bank/comment/tests/backup_test.php index 959f2a020ab..c9ebed300bb 100644 --- a/question/bank/comment/tests/backup_test.php +++ b/question/bank/comment/tests/backup_test.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qbank_comment; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -29,7 +31,7 @@ require_once($CFG->dirroot. '/comment/lib.php'); * @author Matt Porritt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbank_comment_backup_restore_test extends \advanced_testcase { +class backup_test extends \advanced_testcase { /** * @var array Data object for generating a question. @@ -72,7 +74,7 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { // Question initial set up. $this->category = $this->getDataGenerator()->create_category(); $this->course = $this->getDataGenerator()->create_course(['category' => $this->category->id]); - $context = context_coursecat::instance($this->category->id); + $context = \context_coursecat::instance($this->category->id); $this->qgen = $this->getDataGenerator()->get_plugin_generator('core_question'); $qcat = $this->qgen->create_question_category(['contextid' => $context->id]); @@ -83,19 +85,19 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { /** * Makes a backup of the course. * - * @param stdClass $course The course object. + * @param \stdClass $course The course object. * @return string Unique identifier for this backup. */ protected function backup_course(\stdClass $course): string { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do backup with default settings. MODE_IMPORT means it will just // create the directory and not zip it. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, - backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, + \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_IMPORT, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); @@ -117,13 +119,13 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do restore to new course with default settings. - $newcourseid = restore_dbops::create_new_course($fullname, $shortname, $categoryid); - $rc = new restore_controller($backupid, $newcourseid, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, - backup::TARGET_NEW_COURSE); + $newcourseid = \restore_dbops::create_new_course($fullname, $shortname, $categoryid); + $rc = new \restore_controller($backupid, $newcourseid, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id, + \backup::TARGET_NEW_COURSE); $rc->execute_precheck(); $rc->execute_plan(); @@ -151,7 +153,7 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { // Add comments to the questions. $coursecontext = \context_course::instance($this->course->id); - $args = new stdClass; + $args = new \stdClass; $args->context = $coursecontext; $args->course = $this->course; $args->area = 'question'; @@ -164,13 +166,13 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { // Two comments for question 1. $commentobj1 = new \comment($args); - $commentobj1->add('new comment for question 1 _ 1'); - $comment1 = $commentobj1->add('new comment for question 1 _ 2'); + $commentobj1->add('new \comment for question 1 _ 1'); + $comment1 = $commentobj1->add('new \comment for question 1 _ 2'); // One comment for question 2. $args->itemid = $question2->id; $commentobj2 = new \comment($args); - $comment2 = $commentobj2->add('new comment for question 2'); + $comment2 = $commentobj2->add('new \comment for question 2'); // Create a quiz and the questions to that. $quiz = $this->getDataGenerator()->create_module( diff --git a/question/bank/customfields/tests/customfield_test.php b/question/bank/customfields/tests/customfield_test.php index 07c3d86781a..962ba0c8f6a 100644 --- a/question/bank/customfields/tests/customfield_test.php +++ b/question/bank/customfields/tests/customfield_test.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qbank_customfields; + defined('MOODLE_INTERNAL') || die(); global $CFG; @@ -28,7 +30,7 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); * @author Matt Porritt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbank_customfields_customfield_testcase extends advanced_testcase { +class customfield_test extends \advanced_testcase { /** * @var array Data object for generating a question. @@ -89,7 +91,7 @@ class qbank_customfields_customfield_testcase extends advanced_testcase { // Question initial set up. $this->category = $this->getDataGenerator()->create_category(); $this->course = $this->getDataGenerator()->create_course(['category' => $this->category->id]); - $context = context_coursecat::instance($this->category->id); + $context = \context_coursecat::instance($this->category->id); $this->qgen = $this->getDataGenerator()->get_plugin_generator('core_question'); $qcat = $this->qgen->create_question_category(['contextid' => $context->id]); @@ -109,19 +111,19 @@ class qbank_customfields_customfield_testcase extends advanced_testcase { /** * Makes a backup of the course. * - * @param stdClass $course The course object. + * @param \stdClass $course The course object. * @return string Unique identifier for this backup. */ protected function backup_course(\stdClass $course): string { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do backup with default settings. MODE_IMPORT means it will just // create the directory and not zip it. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, - backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, + \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_IMPORT, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); @@ -143,13 +145,13 @@ class qbank_customfields_customfield_testcase extends advanced_testcase { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do restore to new course with default settings. - $newcourseid = restore_dbops::create_new_course($fullname, $shortname, $categoryid); - $rc = new restore_controller($backupid, $newcourseid, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, - backup::TARGET_NEW_COURSE); + $newcourseid = \restore_dbops::create_new_course($fullname, $shortname, $categoryid); + $rc = new \restore_controller($backupid, $newcourseid, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id, + \backup::TARGET_NEW_COURSE); $rc->execute_precheck(); $rc->execute_plan(); diff --git a/question/bank/customfields/tests/question_handler_test.php b/question/bank/customfields/tests/question_handler_test.php index 3d37241dd7b..9ebd0e559e8 100644 --- a/question/bank/customfields/tests/question_handler_test.php +++ b/question/bank/customfields/tests/question_handler_test.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qbank_customfields; + /** * Class qbank_customfields_question_handler_testcase * @@ -22,7 +24,7 @@ * @author Matt Porritt * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbank_customfields_question_handler_testcase extends advanced_testcase { +class question_handler_test extends \advanced_testcase { /** * Question setup helper method. @@ -33,7 +35,7 @@ class qbank_customfields_question_handler_testcase extends advanced_testcase { protected function setup_question(): int { $category = $this->getDataGenerator()->create_category(); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); - $context = context_coursecat::instance($category->id); + $context = \context_coursecat::instance($category->id); $questioncategory = $questiongenerator->create_question_category(['contextid' => $context->id]); $questiondata = ['category' => $questioncategory->id, 'idnumber' => 'q1']; $question = $questiongenerator->create_question('shortanswer', null, $questiondata); @@ -62,7 +64,7 @@ class qbank_customfields_question_handler_testcase extends advanced_testcase { $fieldgenerator->add_instance_data($field, $instanceid, $fieldvalue); // Get the field data. - $customfieldhandler = qbank_customfields\customfield\question_handler::create(); + $customfieldhandler = customfield\question_handler::create(); $fieldinstancedata = $customfieldhandler->get_field_data($field, $instanceid); $this->assertEquals($categorydata->name, $fieldinstancedata->get_field()->get_category()->get('name')); @@ -89,7 +91,7 @@ class qbank_customfields_question_handler_testcase extends advanced_testcase { $fieldgenerator->add_instance_data($field, $instanceid, $fieldvalue); // Get the field data. - $customfieldhandler = qbank_customfields\customfield\question_handler::create(); + $customfieldhandler = customfield\question_handler::create(); $fieldinstancedata = $customfieldhandler->get_field_data($field, $instanceid); $output = $customfieldhandler->display_custom_field_table($fieldinstancedata); @@ -126,7 +128,7 @@ class qbank_customfields_question_handler_testcase extends advanced_testcase { $fieldgenerator->add_instance_data($field3, $instanceid, $field3value); // Get the field data. - $customfieldhandler = qbank_customfields\customfield\question_handler::create(); + $customfieldhandler = customfield\question_handler::create(); $outputdata = $customfieldhandler->get_categories_fields_data($instanceid); $this->assertEquals($field1value, $outputdata['test category'][0]['value']); diff --git a/question/bank/previewquestion/tests/qbank_preview_helper_test.php b/question/bank/previewquestion/tests/qbank_preview_helper_test.php index cdb49edde21..4b0e10acd95 100644 --- a/question/bank/previewquestion/tests/qbank_preview_helper_test.php +++ b/question/bank/previewquestion/tests/qbank_preview_helper_test.php @@ -32,7 +32,7 @@ use stdClass; * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @coversDefaultClass \qbank_previewquestion\helper */ -class helper_test extends \advanced_testcase { +class qbank_preview_helper_test extends \advanced_testcase { /** * @var bool|\context|\context_course $context diff --git a/question/behaviour/adaptive/tests/mark_display_test.php b/question/behaviour/adaptive/tests/mark_display_test.php index f8d7fedcd46..1a6678b7c75 100644 --- a/question/behaviour/adaptive/tests/mark_display_test.php +++ b/question/behaviour/adaptive/tests/mark_display_test.php @@ -14,15 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qbehaviour_adaptive; -/** - * This file contains tests that just test the display mark/penalty information. - * - * @package qbehaviour_adaptive - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - +use qbehaviour_adaptive_mark_details; +use question_display_options; +use question_state; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +26,14 @@ global $CFG; require_once(__DIR__ . '/../../../engine/lib.php'); require_once(__DIR__ . '/../behaviour.php'); - /** * Unit tests for the adaptive behaviour the display of mark/penalty information. * + * @package qbehaviour_adaptive * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbehaviour_adaptive_mark_display_test extends basic_testcase { +class mark_display_test extends \basic_testcase { /** @var qbehaviour_adaptive_renderer the renderer to test. */ protected $renderer; diff --git a/question/behaviour/deferredcbm/tests/question_cbm_test.php b/question/behaviour/deferredcbm/tests/question_cbm_test.php index 20fc6fc71af..d098606c0f7 100644 --- a/question/behaviour/deferredcbm/tests/question_cbm_test.php +++ b/question/behaviour/deferredcbm/tests/question_cbm_test.php @@ -14,30 +14,23 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests that walks a question through the deferred feedback - * with certainty base marking behaviour. - * - * @package qbehaviour - * @subpackage deferredcbm - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qbehaviour_deferredcbm; +use question_cbm; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/../../../engine/lib.php'); - /** * Unit tests for the deferred feedback with certainty base marking behaviour. * + * @package qbehaviour_deferredcbm * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbehaviour_deferredcbm_cbm_test extends basic_testcase { +class question_cbm_test extends \basic_testcase { public function test_adjust_fraction() { $this->assertEqualsWithDelta( 1, question_cbm::adjust_fraction( 1, question_cbm::LOW), 0.0000001); diff --git a/question/behaviour/missing/tests/missingbehaviour_test.php b/question/behaviour/missing/tests/missingbehaviour_test.php index d547e36136a..cc20b64b666 100644 --- a/question/behaviour/missing/tests/missingbehaviour_test.php +++ b/question/behaviour/missing/tests/missingbehaviour_test.php @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the 'missing' behaviour. - * - * @package qbehaviour - * @subpackage missing - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qbehaviour_missing; +use qbehaviour_missing; +use question_attempt; +use question_attempt_pending_step; +use question_attempt_step; +use question_bank; +use question_display_options; +use question_state; +use question_test_recordset; +use question_usage_null_observer; defined('MOODLE_INTERNAL') || die(); @@ -31,40 +33,40 @@ require_once(__DIR__ . '/../../../engine/lib.php'); require_once(__DIR__ . '/../../../engine/tests/helpers.php'); require_once(__DIR__ . '/../behaviour.php'); - /** * Unit tests for the 'missing' behaviour. * + * @package qbehaviour_missing * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qbehaviour_missing_test extends advanced_testcase { +class missingbehaviour_test extends \advanced_testcase { public function test_missing_cannot_start() { - $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); + $qa = new question_attempt(\test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $behaviour->init_first_step(new question_attempt_step(array()), 1); } public function test_missing_cannot_process() { - $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); + $qa = new question_attempt(\test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $behaviour->process_action(new question_attempt_pending_step(array())); } public function test_missing_cannot_get_min_fraction() { - $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); + $qa = new question_attempt(\test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $behaviour->get_min_fraction(); } public function test_missing_cannot_get_max_fraction() { - $qa = new question_attempt(test_question_maker::make_question('truefalse', 'true'), 0); + $qa = new question_attempt(\test_question_maker::make_question('truefalse', 'true'), 0); $behaviour = new qbehaviour_missing($qa, 'deferredfeedback'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $behaviour->get_max_fraction(); } @@ -83,7 +85,7 @@ class qbehaviour_missing_test extends advanced_testcase { 1256233790, 2, 1, 'complete', 0.50, 1256233705, 1, 'choice0', '1'), )); - $question = test_question_maker::make_question('truefalse', 'true'); + $question = \test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); diff --git a/question/engine/tests/datalib_reporting_queries_test.php b/question/engine/tests/datalib_reporting_queries_test.php index 2707f91b6cd..993e8866368 100644 --- a/question/engine/tests/datalib_reporting_queries_test.php +++ b/question/engine/tests/datalib_reporting_queries_test.php @@ -14,6 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_question; + +use qubaid_list; +use question_bank; +use question_engine; +use question_engine_data_mapper; +use question_state; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once(__DIR__ . '/../lib.php'); +require_once(__DIR__ . '/helpers.php'); + /** * Unit tests for the parts of {@link question_engine_data_mapper} related to reporting. * @@ -22,22 +36,7 @@ * @copyright 2013 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once(__DIR__ . '/../lib.php'); -require_once(__DIR__ . '/helpers.php'); - - -/** - * Unit tests for the parts of {@link question_engine_data_mapper} related to reporting. - * - * @copyright 2013 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class question_engine_data_mapper_reporting_testcase extends qbehaviour_walkthrough_test_base { +class datalib_reporting_queries_test extends \qbehaviour_walkthrough_test_base { /** @var question_engine_data_mapper */ protected $dm; @@ -101,7 +100,7 @@ class question_engine_data_mapper_reporting_testcase extends qbehaviour_walkthro // Create the second usage. $this->quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $q = question_bank::load_question($this->sa->id); $this->start_attempt_at_question($q, 'interactive', 5); diff --git a/question/engine/tests/datalib_test.php b/question/engine/tests/datalib_test.php index d00d260759a..192aa24f892 100644 --- a/question/engine/tests/datalib_test.php +++ b/question/engine/tests/datalib_test.php @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for parts of {@link question_engine_data_mapper}. - * - * @package core_question - * @category test - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use qubaid_join; +use qubaid_list; +use question_bank; +use question_engine; +use question_engine_data_mapper; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +28,6 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for parts of {@link question_engine_data_mapper}. * @@ -39,10 +36,12 @@ require_once(__DIR__ . '/helpers.php'); * tested elsewhere, e.g. by {@link question_usage_autosave_test}. We do not * re-test them here. * + * @package core_question + * @category test * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_base { +class datalib_test extends \qbehaviour_walkthrough_test_base { /** * We create two usages, each with two questions, a short-answer marked @@ -81,7 +80,7 @@ class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_b // Create the second usage. $this->quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $q = question_bank::load_question($sa->id); $this->start_attempt_at_question($q, 'interactive', 5); @@ -136,7 +135,7 @@ class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_b $questiondata2 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); $questiondata3 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $question1 = question_bank::load_question($questiondata1->id); $question3 = question_bank::load_question($questiondata3->id); @@ -168,7 +167,7 @@ class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_b $cat = $generator->create_question_category(); $questiondata1 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $quba->add_question(question_bank::load_question($questiondata1->id)); $quba->start_all_questions(); @@ -201,7 +200,7 @@ class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_b $cat = $generator->create_question_category(); $questiondata1 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); - $initquba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $initquba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $initquba->set_preferred_behaviour('deferredfeedback'); $slot = $initquba->add_question(question_bank::load_question($questiondata1->id)); $initquba->start_all_questions(); @@ -238,7 +237,7 @@ class question_engine_data_mapper_testcase extends qbehaviour_walkthrough_test_b $this->resetAfterTest(); // Create a new usage. - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); // Save it. diff --git a/question/engine/tests/qubaid_condition_test.php b/question/engine/tests/qubaid_condition_test.php index 816b8e112cb..5852c7804a5 100644 --- a/question/engine/tests/qubaid_condition_test.php +++ b/question/engine/tests/qubaid_condition_test.php @@ -14,29 +14,26 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for some of the code in ../datalib.php. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use qubaid_condition; +use qubaid_join; +use qubaid_list; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/../lib.php'); - /** * Unit tests for qubaid_condition and subclasses. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qubaid_condition_testcase extends advanced_testcase { +class qubaid_condition_test extends \advanced_testcase { protected function normalize_sql($sql, $params) { $newparams = array(); diff --git a/question/engine/tests/questionattempt_db_test.php b/question/engine/tests/questionattempt_db_test.php index f2a0b511868..779b0efad62 100644 --- a/question/engine/tests/questionattempt_db_test.php +++ b/question/engine/tests/questionattempt_db_test.php @@ -14,18 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt class. - * - * Action methods like start, process_action and finish are assumed to be - * tested by walkthrough tests in the various behaviours. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt; +use question_bank; +use question_engine; +use question_state; +use question_test_recordset; +use question_usage_null_observer; +use testable_question_engine_unit_of_work; defined('MOODLE_INTERNAL') || die(); @@ -33,14 +30,18 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for loading data into the {@link question_attempt} class. * + * Action methods like start, process_action and finish are assumed to be + * tested by walkthrough tests in the various behaviours. + * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_db_test extends data_loading_method_test_base { +class questionattempt_db_test extends \data_loading_method_test_base { public function test_load() { $records = new question_test_recordset(array( array('questionattemptid', 'contextid', 'questionusageid', 'slot', @@ -58,7 +59,7 @@ class question_attempt_db_test extends data_loading_method_test_base { array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0000000, 0.0000000, 1.0000000, 0, '', '', '', 1256233790, 6, 5, 'mangrpartial', 0.5000000, 1256233790, 1, '-maxmark', '2'), )); - $question = test_question_maker::make_question('truefalse', 'true'); + $question = \test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); @@ -154,7 +155,7 @@ class question_attempt_db_test extends data_loading_method_test_base { array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0000000, 0.0000000, 1.0000000, 1, '', '', '', 1256233790, 3, 2, 'complete', null, 1256233710, 1, 'answer', '0'), )); - $question = test_question_maker::make_question('truefalse', 'true'); + $question = \test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); @@ -214,13 +215,13 @@ class question_attempt_db_test extends data_loading_method_test_base { array(1, 123, 1, 1, 'deferredfeedback', -1, 1, 2.0000000, 0.0000000, 1.0000000, 1, '', '', '', 1256233790, 3, 2, 'complete', null, 1256233710, 1, 'answer', '0'), )); - $question = test_question_maker::make_question('truefalse', 'true'); + $question = \test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); question_bank::load_test_question_data($question); $observer = new testable_question_engine_unit_of_work( - question_engine::make_questions_usage_by_activity('unit_test', context_system::instance())); + question_engine::make_questions_usage_by_activity('unit_test', \context_system::instance())); $qa = question_attempt::load_from_records($records, 1, $observer, 'deferredfeedback'); question_bank::end_unit_test(); diff --git a/question/engine/tests/questionattempt_test.php b/question/engine/tests/questionattempt_test.php index 8086a8b84c8..13b11e45785 100644 --- a/question/engine/tests/questionattempt_test.php +++ b/question/engine/tests/questionattempt_test.php @@ -14,18 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt class. - * - * Action methods like start, process_action and finish are assumed to be - * tested by walkthrough tests in the various behaviours. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt; defined('MOODLE_INTERNAL') || die(); @@ -33,16 +24,20 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the {@link question_attempt} class. * + * Action methods like start, process_action and finish are assumed to be + * tested by walkthrough tests in the various behaviours. + * * These are the tests that don't require any steps. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_testcase extends advanced_testcase { +class questionattempt_test extends \advanced_testcase { /** @var question_definition a question that can be used in the tests. */ private $question; /** @var int fake question_usage id used in some tests. */ @@ -51,7 +46,7 @@ class question_attempt_testcase extends advanced_testcase { private $qa; protected function setUp(): void { - $this->question = test_question_maker::make_question('description'); + $this->question = \test_question_maker::make_question('description'); $this->question->defaultmark = 3; $this->usageid = 13; $this->qa = new question_attempt($this->question, $this->usageid); diff --git a/question/engine/tests/questionattempt_with_steps_test.php b/question/engine/tests/questionattempt_with_steps_test.php index 9627758baa5..8ddfb7a5181 100644 --- a/question/engine/tests/questionattempt_with_steps_test.php +++ b/question/engine/tests/questionattempt_with_steps_test.php @@ -14,18 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt class. - * - * Action methods like start, process_action and finish are assumed to be - * tested by walkthrough tests in the various behaviours. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt; +use question_attempt_step; +use question_state; +use testable_question_attempt; defined('MOODLE_INTERNAL') || die(); @@ -33,19 +27,23 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * These tests use a standard fixture of a {@link question_attempt} with three steps. * + * Action methods like start, process_action and finish are assumed to be + * tested by walkthrough tests in the various behaviours. + * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_with_steps_test extends advanced_testcase { +class questionattempt_with_steps_test extends \advanced_testcase { private $question; private $qa; protected function setUp(): void { - $this->question = test_question_maker::make_question('description'); + $this->question = \test_question_maker::make_question('description'); $this->qa = new testable_question_attempt($this->question, 0, null, 2); for ($i = 0; $i < 3; $i++) { $step = new question_attempt_step(array('i' => $i)); @@ -58,7 +56,7 @@ class question_attempt_with_steps_test extends advanced_testcase { } public function test_get_step_before_start() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->qa->get_step(-1); } @@ -73,7 +71,7 @@ class question_attempt_with_steps_test extends advanced_testcase { } public function test_get_step_past_end() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->qa->get_step(3); } diff --git a/question/engine/tests/questionattemptiterator_test.php b/question/engine/tests/questionattemptiterator_test.php index d4ea62b9252..d979be80013 100644 --- a/question/engine/tests/questionattemptiterator_test.php +++ b/question/engine/tests/questionattemptiterator_test.php @@ -14,15 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt_iterator class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_engine; defined('MOODLE_INTERNAL') || die(); @@ -30,27 +24,28 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * This file contains tests for the {@link question_attempt_iterator} class. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_iterator_test extends advanced_testcase { +class questionattemptiterator_test extends \advanced_testcase { private $quba; private $qas = array(); private $iterator; protected function setUp(): void { $this->quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $this->quba->set_preferred_behaviour('deferredfeedback'); - $slot = $this->quba->add_question(test_question_maker::make_question('description')); + $slot = $this->quba->add_question(\test_question_maker::make_question('description')); $this->qas[$slot] = $this->quba->get_question_attempt($slot); - $slot = $this->quba->add_question(test_question_maker::make_question('description')); + $slot = $this->quba->add_question(\test_question_maker::make_question('description')); $this->qas[$slot] = $this->quba->get_question_attempt($slot); $this->iterator = $this->quba->get_attempt_iterator(); @@ -88,7 +83,7 @@ class question_attempt_iterator_test extends advanced_testcase { } public function test_offsetGet_before_start() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->iterator[0]; } @@ -101,17 +96,17 @@ class question_attempt_iterator_test extends advanced_testcase { } public function test_offsetGet_past_end() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->iterator[3]; } public function test_cannot_set() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $this->iterator[0] = null; } public function test_cannot_unset() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); unset($this->iterator[2]); } } diff --git a/question/engine/tests/questionattemptstep_db_test.php b/question/engine/tests/questionattemptstep_db_test.php index 6be65894127..e7982b61ad6 100644 --- a/question/engine/tests/questionattemptstep_db_test.php +++ b/question/engine/tests/questionattemptstep_db_test.php @@ -14,15 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt_step class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt_step; +use question_state; +use question_test_recordset; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +26,15 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the loading data into the {@link question_attempt_step} class. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_step_db_test extends data_loading_method_test_base { +class questionattemptstep_db_test extends \data_loading_method_test_base { public function test_load_with_data() { $records = new question_test_recordset(array( array('attemptstepid', 'questionattemptid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value', 'qtype', 'contextid'), diff --git a/question/engine/tests/questionattemptstep_test.php b/question/engine/tests/questionattemptstep_test.php index 59139df0ade..4b9e149abb1 100644 --- a/question/engine/tests/questionattemptstep_test.php +++ b/question/engine/tests/questionattemptstep_test.php @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt_step class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt_step; +use question_state; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +25,15 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the {@link question_attempt_step} class. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_step_test extends advanced_testcase { +class questionattemptstep_test extends \advanced_testcase { public function test_initial_state_unprocessed() { $step = new question_attempt_step(); $this->assertEquals(question_state::$unprocessed, $step->get_state()); @@ -129,7 +125,6 @@ class question_attempt_step_test extends advanced_testcase { } - /** * Test get_user function. */ diff --git a/question/engine/tests/questionattemptstepiterator_test.php b/question/engine/tests/questionattemptstepiterator_test.php index 03f84d4442e..8ebacfa30ac 100644 --- a/question/engine/tests/questionattemptstepiterator_test.php +++ b/question/engine/tests/questionattemptstepiterator_test.php @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_attempt_step_iterator class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_attempt_step; +use testable_question_attempt; defined('MOODLE_INTERNAL') || die(); @@ -30,19 +25,20 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the {@link question_attempt_step_iterator} class. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_attempt_step_iterator_test extends advanced_testcase { +class questionattemptstepiterator_test extends \advanced_testcase { private $qa; private $iterator; protected function setUp(): void { - $question = test_question_maker::make_question('description'); + $question = \test_question_maker::make_question('description'); $this->qa = new testable_question_attempt($question, 0); for ($i = 0; $i < 3; $i++) { $step = new question_attempt_step(array('i' => $i)); @@ -105,7 +101,7 @@ class question_attempt_step_iterator_test extends advanced_testcase { } public function test_offsetGet_before_start() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->iterator[-1]; } @@ -120,17 +116,17 @@ class question_attempt_step_iterator_test extends advanced_testcase { } public function test_offsetGet_past_end() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $step = $this->iterator[3]; } public function test_cannot_set() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $this->iterator[0] = null; } public function test_cannot_unset() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); unset($this->iterator[2]); } } diff --git a/question/engine/tests/questionbank_test.php b/question/engine/tests/questionbank_test.php index c0b4cb24289..a81aac2a543 100644 --- a/question/engine/tests/questionbank_test.php +++ b/question/engine/tests/questionbank_test.php @@ -14,32 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_bank class. - * - * @package moodlecore - * @subpackage questionbank - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use qubaid_list; +use question_bank; +use question_engine; +use question_finder; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/../lib.php'); - /** - *Unit tests for the {@link question_bank} class. + * Unit tests for the {@see question_bank} class. * + * @package core_question + * @category test * @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_bank_test extends advanced_testcase { +class questionbank_test extends \advanced_testcase { public function test_sort_qtype_array() { - $config = new stdClass(); + $config = new \stdClass(); $config->multichoice_sortorder = '1'; $config->calculated_sortorder = '2'; $qtypes = array( @@ -93,7 +91,7 @@ class question_bank_test extends advanced_testcase { $questiondata2 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); $questiondata3 = $generator->create_question('shortanswer', null, array('category' => $cat->id)); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $question1 = question_bank::load_question($questiondata1->id); $question3 = question_bank::load_question($questiondata3->id); @@ -123,7 +121,7 @@ class question_bank_test extends advanced_testcase { public function test_load_many_for_cache_missing_id() { // Try to load a non-existent question. - $this->expectException('dml_missing_record_exception'); + $this->expectException(\dml_missing_record_exception::class); question_finder::get_instance()->load_many_for_cache([-1]); } } diff --git a/question/engine/tests/questionstate_test.php b/question/engine/tests/questionstate_test.php index 1fc81231587..85178ac8043 100644 --- a/question/engine/tests/questionstate_test.php +++ b/question/engine/tests/questionstate_test.php @@ -14,15 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_state class and subclasses. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_state; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +24,15 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once($CFG->libdir . '/questionlib.php'); - /** * Unit tests for the {@link question_state} class and subclasses. * + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_state_test extends advanced_testcase { +class questionstate_test extends \advanced_testcase { public function test_is_active() { $this->assertFalse(question_state::$notstarted->is_active()); $this->assertFalse(question_state::$unprocessed->is_active()); @@ -159,4 +154,4 @@ class question_state_test extends advanced_testcase { $this->assertEquals(question_state::$mangrright, question_state::$gradedpartial->corresponding_commented_state(1)); } -} \ No newline at end of file +} diff --git a/question/engine/tests/questionusage_autosave_test.php b/question/engine/tests/questionusage_autosave_test.php index a5d9f977293..660744cbd63 100644 --- a/question/engine/tests/questionusage_autosave_test.php +++ b/question/engine/tests/questionusage_autosave_test.php @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the autosave code in the question_usage class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2013 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_bank; +use question_state; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +25,15 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the autosave parts of the {@link question_usage} class. * + * @package core_question + * @category test * @copyright 2013 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_usage_autosave_test extends qbehaviour_walkthrough_test_base { +class questionusage_autosave_test extends \qbehaviour_walkthrough_test_base { public function test_autosave_then_display() { $this->resetAfterTest(); @@ -452,7 +448,7 @@ class question_usage_autosave_test extends qbehaviour_walkthrough_test_base { if (!isset($cfg->dboptions)) { $cfg->dboptions = array(); } - $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary); + $DB2 = \moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary); $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions); // Since we need to commit our transactions in a given order, close the @@ -523,7 +519,7 @@ class question_usage_autosave_test extends qbehaviour_walkthrough_test_base { if (!isset($cfg->dboptions)) { $cfg->dboptions = array(); } - $DB2 = moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary); + $DB2 = \moodle_database::get_driver_instance($cfg->dbtype, $cfg->dblibrary); $DB2->connect($cfg->dbhost, $cfg->dbuser, $cfg->dbpass, $cfg->dbname, $cfg->prefix, $cfg->dboptions); // Since we need to commit our transactions in a given order, close the diff --git a/question/engine/tests/questionusagebyactivity_data_test.php b/question/engine/tests/questionusagebyactivity_data_test.php index 553c6b22d84..0ee53471d70 100644 --- a/question/engine/tests/questionusagebyactivity_data_test.php +++ b/question/engine/tests/questionusagebyactivity_data_test.php @@ -14,14 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_usage_by_activity class. - * - * @package core_question - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_bank; +use question_state; +use question_test_recordset; +use question_usage_by_activity; defined('MOODLE_INTERNAL') || die(); @@ -29,16 +27,16 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for loading data into the {@link question_usage_by_activity} class. * + * @package core_question * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_usage_db_test extends data_loading_method_test_base { +class questionusagebyactivity_data_test extends \data_loading_method_test_base { public function test_load() { - $scid = context_system::instance()->id; + $scid = \context_system::instance()->id; $records = new question_test_recordset(array( array('qubaid', 'contextid', 'component', 'preferredbehaviour', 'questionattemptid', 'questionusageid', 'slot', @@ -51,7 +49,7 @@ class question_usage_db_test extends data_loading_method_test_base { array(1, $scid, 'unit_test', 'interactive', 1, 1, 1, 'interactive', -1, 1, 2.0000000, 0.0000000, 1.0000000, 0, '', '', '', 1256233790, 5, 2, 'gradedright', 1.0000000, 1256233720, 1, '-finish', '1'), )); - $question = test_question_maker::make_question('truefalse', 'true'); + $question = \test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); @@ -96,7 +94,7 @@ class question_usage_db_test extends data_loading_method_test_base { // The code had a bug where if one question_attempt had no steps, // load_from_records got stuck in an infinite loop. This test is to // verify that no longer happens. - $scid = context_system::instance()->id; + $scid = \context_system::instance()->id; $records = new question_test_recordset(array( array('qubaid', 'contextid', 'component', 'preferredbehaviour', 'questionattemptid', 'questionusageid', 'slot', @@ -128,7 +126,7 @@ class question_usage_db_test extends data_loading_method_test_base { // The code had a bug where if a question_usage had no question_attempts, // load_from_records got stuck in an infinite loop. This test is to // verify that no longer happens. - $scid = context_system::instance()->id; + $scid = \context_system::instance()->id; $records = new question_test_recordset(array( array('qubaid', 'contextid', 'component', 'preferredbehaviour', 'questionattemptid', 'questionusageid', 'slot', diff --git a/question/engine/tests/questionusagebyactivity_test.php b/question/engine/tests/questionusagebyactivity_test.php index f69198a0299..476e11abc85 100644 --- a/question/engine/tests/questionusagebyactivity_test.php +++ b/question/engine/tests/questionusagebyactivity_test.php @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_usage_by_activity class. - * - * @package core_question - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_bank; +use question_engine; +use question_state; defined('MOODLE_INTERNAL') || die(); @@ -29,19 +26,19 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the question_usage_by_activity class. * + * @package core_question * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_usage_by_activity_test extends advanced_testcase { +class questionusagebyactivity_test extends \advanced_testcase { public function test_set_get_preferred_model() { // Set up $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); // Exercise SUT and verify. $quba->set_preferred_behaviour('deferredfeedback'); @@ -51,7 +48,7 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_set_get_id() { // Set up $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); // Exercise SUT and verify $quba->set_id_from_database(123); @@ -61,7 +58,7 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_fake_id() { // Set up $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); // Exercise SUT and verify $this->assertNotEmpty($quba->get_id()); @@ -69,10 +66,10 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_create_usage_and_add_question() { // Exercise SUT - $context = context_system::instance(); + $context = \context_system::instance(); $quba = question_engine::make_questions_usage_by_activity('unit_test', $context); $quba->set_preferred_behaviour('deferredfeedback'); - $tf = test_question_maker::make_question('truefalse', 'true'); + $tf = \test_question_maker::make_question('truefalse', 'true'); $slot = $quba->add_question($tf); // Verify. @@ -86,9 +83,9 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_get_question() { // Set up. $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); - $tf = test_question_maker::make_question('truefalse', 'true'); + $tf = \test_question_maker::make_question('truefalse', 'true'); $slot = $quba->add_question($tf); // Exercise SUT and verify. @@ -100,9 +97,9 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_extract_responses() { // Start a deferred feedback attempt with CBM and add the question to it. - $tf = test_question_maker::make_question('truefalse', 'true'); + $tf = \test_question_maker::make_question('truefalse', 'true'); $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $quba->set_preferred_behaviour('deferredcbm'); $slot = $quba->add_question($tf); $quba->start_all_questions(); @@ -126,9 +123,9 @@ class question_usage_by_activity_test extends advanced_testcase { public function test_access_out_of_sequence_throws_exception() { // Start a deferred feedback attempt with CBM and add the question to it. - $tf = test_question_maker::make_question('truefalse', 'true'); + $tf = \test_question_maker::make_question('truefalse', 'true'); $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); $quba->set_preferred_behaviour('deferredcbm'); $slot = $quba->add_question($tf); $quba->start_all_questions(); @@ -167,7 +164,7 @@ class question_usage_by_activity_test extends advanced_testcase { $this->setAdminUser(); // Set up. $quba = question_engine::make_questions_usage_by_activity('unit_test', - context_system::instance()); + \context_system::instance()); // Create an essay question in the DB. $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); diff --git a/question/engine/tests/questionutils_test.php b/question/engine/tests/questionutils_test.php index be65ddc73dd..cb8fa7e3270 100644 --- a/question/engine/tests/questionutils_test.php +++ b/question/engine/tests/questionutils_test.php @@ -14,29 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the {@link question_utils} class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_utils; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once(__DIR__ . '/../lib.php'); - /** * Unit tests for the {@link question_utils} class. * + * @package core_question + * @category test * @copyright 2010 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_utils_test extends advanced_testcase { +class questionutils_test extends \advanced_testcase { public function test_arrays_have_same_keys_and_values() { $this->assertTrue(question_utils::arrays_have_same_keys_and_values( array(), @@ -207,17 +202,17 @@ class question_utils_test extends advanced_testcase { } public function test_int_to_roman_too_small() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); question_utils::int_to_roman(0); } public function test_int_to_roman_too_big() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); question_utils::int_to_roman(4000); } public function test_int_to_roman_not_int() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); question_utils::int_to_roman(1.5); } diff --git a/question/engine/tests/unitofwork_test.php b/question/engine/tests/unitofwork_test.php index e7ee5579e19..7c85f348aa9 100644 --- a/question/engine/tests/unitofwork_test.php +++ b/question/engine/tests/unitofwork_test.php @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question_engine_unit_of_work class. - * - * @package moodlecore - * @subpackage questionengine - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; +use question_bank; +use question_hint; +use question_test_recordset; +use question_usage_by_activity; +use testable_question_engine_unit_of_work; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +28,15 @@ global $CFG; require_once(__DIR__ . '/../lib.php'); require_once(__DIR__ . '/helpers.php'); - /** * Unit tests for the {@link question_engine_unit_of_work} class. * + * @package core_question + * @category test * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_engine_unit_of_work_test extends data_loading_method_test_base { +class unitofwork_test extends \data_loading_method_test_base { /** @var question_usage_by_activity the test question usage. */ protected $quba; @@ -52,7 +51,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { // and attempted in interactive mode submitted responses 'toad' then 'frog'. // Then set it to use a new unit of work for any subsequent changes. // Create a short answer question. - $question = test_question_maker::make_question('shortanswer'); + $question = \test_question_maker::make_question('shortanswer'); $question->hints = array( new question_hint(0, 'This is the first hint.', FORMAT_HTML), new question_hint(0, 'This is the second hint.', FORMAT_HTML), @@ -116,7 +115,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_add_question() { - $slot = $this->quba->add_question(test_question_maker::make_question('truefalse')); + $slot = $this->quba->add_question(\test_question_maker::make_question('truefalse')); $newattempts = $this->observer->get_attempts_added(); $this->assertEquals(1, count($newattempts)); @@ -129,7 +128,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_add_and_start_question() { - $slot = $this->quba->add_question(test_question_maker::make_question('truefalse')); + $slot = $this->quba->add_question(\test_question_maker::make_question('truefalse')); $this->quba->start_question($slot); // The point here is that, although we have added a step, it is not listed @@ -282,7 +281,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_move_question() { - $q = test_question_maker::make_question('truefalse'); + $q = \test_question_maker::make_question('truefalse'); $newslot = $this->quba->add_question_in_place_of_other($this->slot, $q); $this->quba->start_question($this->slot); @@ -306,7 +305,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_move_question_then_modify() { - $q = test_question_maker::make_question('truefalse'); + $q = \test_question_maker::make_question('truefalse'); $newslot = $this->quba->add_question_in_place_of_other($this->slot, $q); $this->quba->start_question($this->slot); $this->quba->process_action($this->slot, array('answer' => 'frog', '-submit' => 1)); @@ -337,11 +336,11 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_move_question_then_move_again() { $originalqa = $this->quba->get_question_attempt($this->slot); - $q1 = test_question_maker::make_question('truefalse'); + $q1 = \test_question_maker::make_question('truefalse'); $newslot = $this->quba->add_question_in_place_of_other($this->slot, $q1); $this->quba->start_question($this->slot); - $q2 = test_question_maker::make_question('truefalse'); + $q2 = \test_question_maker::make_question('truefalse'); $newslot2 = $this->quba->add_question_in_place_of_other($newslot, $q2); $this->quba->start_question($newslot); @@ -451,7 +450,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { } public function test_set_metadata_in_new_question() { - $newslot = $this->quba->add_question(test_question_maker::make_question('truefalse')); + $newslot = $this->quba->add_question(\test_question_maker::make_question('truefalse')); $this->quba->start_question($newslot); $this->quba->set_question_attempt_metadata($newslot, 'metathingy', 'a value'); $this->assertEquals('a value', $this->quba->get_question_attempt_metadata($newslot, 'metathingy')); @@ -470,7 +469,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { public function test_set_metadata_then_move() { $this->quba->set_question_attempt_metadata($this->slot, 'metathingy', 'a value'); - $q = test_question_maker::make_question('truefalse'); + $q = \test_question_maker::make_question('truefalse'); $newslot = $this->quba->add_question_in_place_of_other($this->slot, $q); $this->quba->start_question($this->slot); $this->assertEquals('a value', $this->quba->get_question_attempt_metadata($newslot, 'metathingy')); @@ -490,7 +489,7 @@ class question_engine_unit_of_work_test extends data_loading_method_test_base { } public function test_move_then_set_metadata() { - $q = test_question_maker::make_question('truefalse'); + $q = \test_question_maker::make_question('truefalse'); $newslot = $this->quba->add_question_in_place_of_other($this->slot, $q); $this->quba->start_question($this->slot); $this->quba->set_question_attempt_metadata($newslot, 'metathingy', 'a value'); diff --git a/question/format/blackboard_six/tests/blackboardformatpool_test.php b/question/format/blackboard_six/tests/blackboardformatpool_test.php index 51731e776e2..9917ebadec6 100644 --- a/question/format/blackboard_six/tests/blackboardformatpool_test.php +++ b/question/format/blackboard_six/tests/blackboardformatpool_test.php @@ -14,14 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the Moodle Blackboard V6+ format. - * - * @package qformat_blackboard_six - * @copyright 2012 Jean-Michel Vedrine - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qformat_blackboard_six; +use qformat_blackboard_six; +use qformat_blackboard_six_file; +use question_bank; +use question_check_specified_fields_expectation; defined('MOODLE_INTERNAL') || die(); @@ -31,14 +29,14 @@ require_once($CFG->dirroot . '/question/format.php'); require_once($CFG->dirroot . '/question/format/blackboard_six/format.php'); require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** - * Unit tests for the blackboard question import format. + * Unit tests for the blackboard v6+ question import format. * + * @package qformat_blackboard_six * @copyright 2012 Jean-Michel Vedrine * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_blackboard_six_pool_test extends question_testcase { +class blackboardformatpool_test extends \question_testcase { public function make_test_xml() { $xmlfile = new qformat_blackboard_six_file(); @@ -60,7 +58,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { // qtypes, not match ones. $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch'); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = $ddmatchisinstalled ? 'ddmatch' : 'match'; $expectedq->name = 'Classify the animals.'; $expectedq->questiontext = 'Classify the animals.'; @@ -104,7 +102,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[2]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'multichoice'; $expectedq->single = 1; $expectedq->name = 'What\'s between orange and green in the spectrum?'; @@ -163,7 +161,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[3]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'multichoice'; $expectedq->single = 0; $expectedq->name = 'What\'s between orange and green in the spectrum?'; @@ -236,7 +234,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[1]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'truefalse'; $expectedq->name = '42 is the Absolute Answer to everything.'; $expectedq->questiontext = '42 is the Absolute Answer to everything.'; @@ -265,7 +263,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[4]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'shortanswer'; $expectedq->name = 'Name an amphibian: __________.'; $expectedq->questiontext = 'Name an amphibian: __________.'; @@ -299,7 +297,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[6]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'essay'; $expectedq->name = 'How are you?'; $expectedq->questiontext = 'How are you?'; @@ -327,7 +325,7 @@ class qformat_blackboard_six_pool_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[0]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'category'; $expectedq->category = 'exam 3 2008-9'; diff --git a/question/format/blackboard_six/tests/blackboardsixformatqti_test.php b/question/format/blackboard_six/tests/blackboardsixformatqti_test.php index 0f48ffef385..6573b50e989 100644 --- a/question/format/blackboard_six/tests/blackboardsixformatqti_test.php +++ b/question/format/blackboard_six/tests/blackboardsixformatqti_test.php @@ -14,14 +14,12 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the Moodle Blackboard V6+ format. - * - * @package qformat_blackboard_six - * @copyright 2012 Jean-Michel Vedrine - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qformat_blackboard_six; +use qformat_blackboard_six; +use qformat_blackboard_six_file; +use question_bank; +use question_check_specified_fields_expectation; defined('MOODLE_INTERNAL') || die(); @@ -31,14 +29,14 @@ require_once($CFG->dirroot . '/question/format.php'); require_once($CFG->dirroot . '/question/format/blackboard_six/format.php'); require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** - * Unit tests for the blackboard question import format. + * Unit tests for the blackboard v6+ question import format. * + * @package qformat_blackboard_six * @copyright 2012 Jean-Michel Vedrine * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_blackboard_six_qti_test extends question_testcase { +class blackboardsixformatqti_test extends \question_testcase { public function make_test_xml() { $xmlfile = new qformat_blackboard_six_file(); @@ -57,7 +55,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { // qtypes, not match ones. $ddmatchisinstalled = question_bank::is_qtype_installed('ddmatch'); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = $ddmatchisinstalled ? 'ddmatch' : 'match'; $expectedq->name = 'Classify the animals.'; $expectedq->questiontext = 'Classify the animals.'; @@ -100,7 +98,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[2]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'multichoice'; $expectedq->single = 1; $expectedq->name = 'What\'s between orange and green in the spectrum?'; @@ -159,7 +157,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[3]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'multichoice'; $expectedq->single = 0; $expectedq->name = 'What\'s between orange and green in the spectrum?'; @@ -235,7 +233,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[1]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'truefalse'; $expectedq->name = '42 is the Absolute Answer to everything.'; $expectedq->questiontext = '42 is the Absolute Answer to everything.'; @@ -265,7 +263,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[5]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'shortanswer'; $expectedq->name = 'Name an amphibian: __________.'; $expectedq->questiontext = 'Name an amphibian: __________.'; @@ -299,7 +297,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[6]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'essay'; $expectedq->name = 'How are you?'; $expectedq->questiontext = 'How are you?'; @@ -327,7 +325,7 @@ class qformat_blackboard_six_qti_test extends question_testcase { $questions = $importer->readquestions($xml); $q = $questions[0]; - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'category'; $expectedq->category = 'sample_blackboard_six'; diff --git a/question/format/gift/tests/giftformat_test.php b/question/format/gift/tests/giftformat_test.php index 9af5a05268c..ef0321b2ee7 100644 --- a/question/format/gift/tests/giftformat_test.php +++ b/question/format/gift/tests/giftformat_test.php @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the Moodle GIFT format. - * - * @package qformat_gift - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qformat_gift; +use qformat_gift; +use question_bank; +use question_check_specified_fields_expectation; defined('MOODLE_INTERNAL') || die(); @@ -31,14 +28,14 @@ require_once($CFG->dirroot . '/question/format.php'); require_once($CFG->dirroot . '/question/format/gift/format.php'); require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Unit tests for the GIFT import/export format. * + * @package qformat_gift * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_gift_test extends question_testcase { +class giftformat_test extends \question_testcase { public function assert_same_gift($expectedtext, $text) { $this->assertEquals(str_replace("\r\n", "\n", $expectedtext), str_replace("\r\n", "\n", $text)); @@ -1373,8 +1370,8 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}"; $category = $generator->create_question_category(); $question = $generator->create_question('truefalse', null, ['category' => $category->id, 'idnumber' => 'myid']); - core_tag_tag::set_item_tags('core_question', 'question', $question->id, - context::instance_by_id($category->contextid), ['tag1', 'tag2'], 0); + \core_tag_tag::set_item_tags('core_question', 'question', $question->id, + \context::instance_by_id($category->contextid), ['tag1', 'tag2'], 0); // Export it. $questiondata = question_bank::load_question_data($question->id); diff --git a/question/format/multianswer/tests/multianswerformat_test.php b/question/format/multianswer/tests/multianswerformat_test.php index d32ecad7eff..debf40d0d55 100644 --- a/question/format/multianswer/tests/multianswerformat_test.php +++ b/question/format/multianswer/tests/multianswerformat_test.php @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the Embedded answer (Cloze) question importer. - * - * @package qformat_multianswer - * @copyright 2012 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qformat_multianswer; +use qformat_multianswer; +use question_check_specified_fields_expectation; defined('MOODLE_INTERNAL') || die(); @@ -31,14 +27,14 @@ require_once($CFG->dirroot . '/question/format.php'); require_once($CFG->dirroot . '/question/format/multianswer/format.php'); require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Unit tests for the Embedded answer (Cloze) question importer. * + * @package qformat_multianswer * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_multianswer_test extends question_testcase { +class multianswerformat_test extends \question_testcase { public function test_import() { $lines = file(__DIR__ . '/fixtures/questions.multianswer.txt'); diff --git a/question/format/xml/tests/xmlformat_test.php b/question/format/xml/tests/xmlformat_test.php index ce1daba75ab..0101066a3e1 100644 --- a/question/format/xml/tests/xmlformat_test.php +++ b/question/format/xml/tests/xmlformat_test.php @@ -22,6 +22,15 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace qformat_xml; + +use qformat_xml; +use qtype_numerical_answer; +use question_answer; +use question_bank; +use question_check_specified_fields_expectation; +use question_hint; +use question_hint_with_parts; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +39,14 @@ require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot . '/question/format/xml/format.php'); require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Unit tests for the matching question definition class. * + * @package qformat_xml * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_xml_test extends question_testcase { +class xmlformat_test extends \question_testcase { public function assert_same_xml($expectedxml, $xml) { $this->assertEquals(str_replace("\r\n", "\n", $expectedxml), str_replace("\r\n", "\n", $xml)); @@ -45,7 +54,7 @@ class qformat_xml_test extends question_testcase { public function make_test_question() { global $USER; - $q = new stdClass(); + $q = new \stdClass(); $q->id = 0; $q->contextid = 0; $q->idnumber = null; @@ -69,7 +78,7 @@ class qformat_xml_test extends question_testcase { * The data the XML import format sends to save_question is not exactly * the same as the data returned from the editing form, so this method * makes necessary changes to the return value of - * test_question_maker::get_question_form_data so that the tests can work. + * \test_question_maker::get_question_form_data so that the tests can work. * @param object $expectedq as returned by get_question_form_data. * @return object one more likely to match the return value of import_...(). */ @@ -80,7 +89,7 @@ class qformat_xml_test extends question_testcase { /** * Becuase XML import uses a files array instead of an itemid integer to * handle saving files with a question, we need to covert the output of - * test_question_maker::get_question_form_data to match. This method recursively + * \test_question_maker::get_question_form_data to match. This method recursively * replaces all array elements with key itemid with an array entry with * key files and value an empty array. * @@ -89,7 +98,7 @@ class qformat_xml_test extends question_testcase { */ protected function itemid_to_files($var) { if (is_object($var)) { - $newvar = new stdClass(); + $newvar = new \stdClass(); foreach (get_object_vars($var) as $field => $value) { $newvar->$field = $this->itemid_to_files($value); } @@ -152,7 +161,7 @@ class qformat_xml_test extends question_testcase { $q->questiontext = 'Name an amphibian: __________'; $q->generalfeedback = 'Generalfeedback: frog or toad would have been OK.'; if (!isset($q->options)) { - $q->options = new stdClass(); + $q->options = new \stdClass(); } $q->options->usecase = false; $q->options->answers = array( @@ -184,7 +193,7 @@ class qformat_xml_test extends question_testcase { $q->qtype = 'match'; if (!isset($q->options)) { - $q->options = new stdClass(); + $q->options = new \stdClass(); } $q->options->shuffleanswers = 1; $q->options->correctfeedback = ''; @@ -230,7 +239,7 @@ class qformat_xml_test extends question_testcase { END; $questionxml = xmlize($xml); - $qo = new stdClass(); + $qo = new \stdClass(); $importer = new qformat_xml(); $importer->import_hints($qo, $questionxml['question'], false, false, 'html'); @@ -260,7 +269,7 @@ END; END; $questionxml = xmlize($xml); - $qo = new stdClass(); + $qo = new \stdClass(); $importer = new qformat_xml(); $importer->import_hints($qo, $questionxml['question'], true, true, 'html'); @@ -282,7 +291,7 @@ END; END; $questionxml = xmlize($xml); - $qo = new stdClass(); + $qo = new \stdClass(); $importer = new qformat_xml(); $importer->import_hints($qo, $questionxml['question'], 'html'); @@ -314,7 +323,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_description($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'description'; $expectedq->name = 'A description'; $expectedq->questiontext = 'The question text.'; @@ -329,7 +338,7 @@ END; } public function test_export_description() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'description'; @@ -393,7 +402,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_essay($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'essay'; $expectedq->name = 'An essay'; $expectedq->questiontext = 'Write something.'; @@ -458,7 +467,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_essay($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'essay'; $expectedq->name = 'An essay'; $expectedq->questiontext = 'Write something.'; @@ -527,7 +536,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_essay($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'essay'; $expectedq->name = 'An essay'; $expectedq->questiontext = 'Write something.'; @@ -557,7 +566,7 @@ END; } public function test_export_essay() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'essay'; @@ -571,7 +580,7 @@ END; $qdata->penalty = 0; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->id = 456; $qdata->options->questionid = 123; $qdata->options->responseformat = 'monospaced'; @@ -693,7 +702,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_match($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'match'; $expectedq->name = 'Matching question'; $expectedq->questiontext = 'Match the upper and lower case letters.'; @@ -729,7 +738,7 @@ END; } public function test_export_match() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'match'; @@ -744,7 +753,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->shuffleanswers = 1; $qdata->options->correctfeedback = 'Well done.'; $qdata->options->correctfeedbackformat = FORMAT_HTML; @@ -754,25 +763,25 @@ END; $qdata->options->incorrectfeedback = 'Completely wrong!'; $qdata->options->incorrectfeedbackformat = FORMAT_HTML; - $subq1 = new stdClass(); + $subq1 = new \stdClass(); $subq1->id = -4; $subq1->questiontext = 'A'; $subq1->questiontextformat = FORMAT_HTML; $subq1->answertext = 'a'; - $subq2 = new stdClass(); + $subq2 = new \stdClass(); $subq2->id = -3; $subq2->questiontext = 'B'; $subq2->questiontextformat = FORMAT_HTML; $subq2->answertext = 'b'; - $subq3 = new stdClass(); + $subq3 = new \stdClass(); $subq3->id = -2; $subq3->questiontext = 'C'; $subq3->questiontextformat = FORMAT_HTML; $subq3->answertext = 'c'; - $subq4 = new stdClass(); + $subq4 = new \stdClass(); $subq4->id = -1; $subq4->questiontext = ''; $subq4->questiontextformat = FORMAT_HTML; @@ -916,7 +925,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_multichoice($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'multichoice'; $expectedq->name = 'Multiple choice question'; $expectedq->questiontext = 'Which are the even numbers?'; @@ -962,7 +971,7 @@ END; } public function test_export_multichoice() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'multichoice'; @@ -977,7 +986,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->single = 0; $qdata->options->shuffleanswers = 0; $qdata->options->answernumbering = 'abc'; @@ -1111,7 +1120,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_numerical($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'numerical'; $expectedq->name = 'Numerical question'; $expectedq->questiontext = 'What is the answer?'; @@ -1139,7 +1148,7 @@ END; public function test_export_numerical() { question_bank::load_question_definition_classes('numerical'); - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'numerical'; @@ -1154,7 +1163,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->answers = array( 13 => new qtype_numerical_answer(13, '42', 1, 'Well done!', FORMAT_HTML, 0.001), @@ -1250,7 +1259,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_shortanswer($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'shortanswer'; $expectedq->name = 'Short answer question'; $expectedq->questiontext = 'Fill in the gap in this sequence: Alpha, ________, Gamma.'; @@ -1271,7 +1280,7 @@ END; } public function test_export_shortanswer() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 123; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'shortanswer'; @@ -1286,7 +1295,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->usecase = 0; $qdata->options->answers = array( @@ -1374,7 +1383,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_truefalse($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'truefalse'; $expectedq->name = 'True false question'; $expectedq->questiontext = 'The answer is true.'; @@ -1426,7 +1435,7 @@ END; $importer = new qformat_xml(); $q = $importer->import_truefalse($xmldata['question']); - $expectedq = new stdClass(); + $expectedq = new \stdClass(); $expectedq->qtype = 'truefalse'; $expectedq->name = 'True false question'; $expectedq->questiontext = 'The answer is true.'; @@ -1447,7 +1456,7 @@ END; } public function test_export_truefalse() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 12; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'truefalse'; @@ -1462,7 +1471,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = null; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->answers = array( 1 => new question_answer(1, 'True', 1, 'Well done!', FORMAT_HTML), 2 => new question_answer(2, 'False', 0, 'Doh!', FORMAT_HTML), @@ -1507,7 +1516,7 @@ END; } public function test_export_truefalse_with_idnumber() { - $qdata = new stdClass(); + $qdata = new \stdClass(); $qdata->id = 12; $qdata->contextid = \context_system::instance()->id; $qdata->qtype = 'truefalse'; @@ -1522,7 +1531,7 @@ END; $qdata->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY; $qdata->idnumber = 'TestIDNum2'; - $qdata->options = new stdClass(); + $qdata->options = new \stdClass(); $qdata->options->answers = array( 1 => new question_answer(1, 'True', 1, 'Well done!', FORMAT_HTML), 2 => new question_answer(2, 'False', 0, 'Doh!', FORMAT_HTML), @@ -1598,8 +1607,8 @@ END; // Annoyingly, import works in a weird way (it duplicates code, rather // than just calling save_question) so we cannot use - // test_question_maker::get_question_form_data('multianswer', 'twosubq'). - $expectedqa = new stdClass(); + // \test_question_maker::get_question_form_data('multianswer', 'twosubq'). + $expectedqa = new \stdClass(); $expectedqa->name = 'Simple multianswer'; $expectedqa->qtype = 'multianswer'; $expectedqa->questiontext = 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".'; @@ -1613,7 +1622,7 @@ END; array('text' => 'Hint 2', 'format' => FORMAT_HTML), ); - $sa = new stdClass(); + $sa = new \stdClass(); $sa->questiontext = array('text' => '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}', 'format' => FORMAT_HTML, 'itemid' => null); @@ -1630,7 +1639,7 @@ END; array('text' => 'Wrong answer', 'format' => FORMAT_HTML, 'itemid' => null), ); - $mc = new stdClass(); + $mc = new \stdClass(); $mc->generalfeedback = ''; $mc->questiontext = array('text' => '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~' . @@ -1660,7 +1669,7 @@ END; array('text' => 'Well done!', 'format' => FORMAT_HTML, 'itemid' => null), ); - $expectedqa->options = new stdClass(); + $expectedqa->options = new \stdClass(); $expectedqa->options->questions = array( 1 => $sa, 2 => $mc, @@ -1674,7 +1683,7 @@ END; } public function test_export_multianswer() { - $qdata = test_question_maker::get_question_data('multianswer', 'twosubq'); + $qdata = \test_question_maker::get_question_data('multianswer', 'twosubq'); $qdata->contextid = \context_system::instance()->id; $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); @@ -1706,7 +1715,7 @@ END; } public function test_export_multianswer_withdollars() { - $qdata = test_question_maker::get_question_data('multianswer', 'dollarsigns'); + $qdata = \test_question_maker::get_question_data('multianswer', 'dollarsigns'); $qdata->contextid = \context_system::instance()->id; $exporter = new qformat_xml(); $xml = $exporter->writequestion($qdata); @@ -1743,7 +1752,7 @@ END; END; $textxml = xmlize($xml); - $qo = new stdClass(); + $qo = new \stdClass(); $importer = new qformat_xml(); $draftitemid = $importer->import_files_as_draft($textxml['questiontext']['#']['file']); @@ -1808,7 +1817,7 @@ END; $testobject = new mock_qformat_xml(); $categoryname = 'name1'; - $categoryinfo = new stdClass(); + $categoryinfo = new \stdClass(); $categoryinfo->info = 'info1'; $categoryinfo->infoformat = 'infoformat1'; $categoryinfo->idnumber = null; diff --git a/question/tests/backup_test.php b/question/tests/backup_test.php index d2291b51803..2f54ee10e1e 100644 --- a/question/tests/backup_test.php +++ b/question/tests/backup_test.php @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for question backup and restore. - * - * @package core_question - * @category test - * @copyright 2018 Shamim Rezaie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; defined('MOODLE_INTERNAL') || die(); @@ -32,27 +25,29 @@ require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); /** * Class core_question_backup_testcase * + * @package core_question + * @category test * @copyright 2018 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_question_backup_testcase extends advanced_testcase { +class backup_test extends \advanced_testcase { /** * Makes a backup of the course. * - * @param stdClass $course The course object. + * @param \stdClass $course The course object. * @return string Unique identifier for this backup. */ protected function backup_course($course) { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do backup with default settings. MODE_IMPORT means it will just // create the directory and not zip it. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, - backup::FORMAT_MOODLE, backup::INTERACTIVE_NO, backup::MODE_IMPORT, + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, + \backup::FORMAT_MOODLE, \backup::INTERACTIVE_NO, \backup::MODE_IMPORT, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); @@ -75,13 +70,13 @@ class core_question_backup_testcase extends advanced_testcase { global $CFG, $USER; // Turn off file logging, otherwise it can't delete the file (Windows). - $CFG->backup_file_logger_level = backup::LOG_NONE; + $CFG->backup_file_logger_level = \backup::LOG_NONE; // Do restore to new course with default settings. - $newcourseid = restore_dbops::create_new_course($fullname, $shortname, $categoryid); - $rc = new restore_controller($backupid, $newcourseid, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id, - backup::TARGET_NEW_COURSE); + $newcourseid = \restore_dbops::create_new_course($fullname, $shortname, $categoryid); + $rc = new \restore_controller($backupid, $newcourseid, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id, + \backup::TARGET_NEW_COURSE); $precheck = $rc->execute_precheck(); if (!$expectedprecheckwarning) { @@ -113,18 +108,18 @@ class core_question_backup_testcase extends advanced_testcase { // Create 2 questions. $qgen = $this->getDataGenerator()->get_plugin_generator('core_question'); - $context = context_coursecat::instance($category1->id); + $context = \context_coursecat::instance($category1->id); $qcat = $qgen->create_question_category(['contextid' => $context->id]); $question1 = $qgen->create_question('shortanswer', null, ['category' => $qcat->id, 'idnumber' => 'q1']); $question2 = $qgen->create_question('shortanswer', null, ['category' => $qcat->id, 'idnumber' => 'q2']); // Tag the questions with 2 question tags and 2 course level question tags. - $qcontext = context::instance_by_id($qcat->contextid); - $coursecontext = context_course::instance($course->id); - core_tag_tag::set_item_tags('core_question', 'question', $question1->id, $qcontext, ['qtag1', 'qtag2']); - core_tag_tag::set_item_tags('core_question', 'question', $question2->id, $qcontext, ['qtag3', 'qtag4']); - core_tag_tag::set_item_tags('core_question', 'question', $question1->id, $coursecontext, ['ctag1', 'ctag2']); - core_tag_tag::set_item_tags('core_question', 'question', $question2->id, $coursecontext, ['ctag3', 'ctag4']); + $qcontext = \context::instance_by_id($qcat->contextid); + $coursecontext = \context_course::instance($course->id); + \core_tag_tag::set_item_tags('core_question', 'question', $question1->id, $qcontext, ['qtag1', 'qtag2']); + \core_tag_tag::set_item_tags('core_question', 'question', $question2->id, $qcontext, ['qtag3', 'qtag4']); + \core_tag_tag::set_item_tags('core_question', 'question', $question1->id, $coursecontext, ['ctag1', 'ctag2']); + \core_tag_tag::set_item_tags('core_question', 'question', $question2->id, $coursecontext, ['ctag3', 'ctag4']); // Create a quiz and add one of the questions to that. $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); @@ -157,14 +152,14 @@ class core_question_backup_testcase extends advanced_testcase { // Retrieve tags for each question and check if they are assigned at the right context. $qcount = 1; foreach ($questions as $question) { - $tags = core_tag_tag::get_item_tags('core_question', 'question', $question->id); + $tags = \core_tag_tag::get_item_tags('core_question', 'question', $question->id); // Each question is tagged with 4 tags (2 question tags + 2 course tags). $this->assertCount(4, $tags); foreach ($tags as $tag) { if (in_array($tag->name, ['ctag1', 'ctag2', 'ctag3', 'ctag4'])) { - $expected = context_course::instance($courseid2)->id; + $expected = \context_course::instance($courseid2)->id; } else if (in_array($tag->name, ['qtag1', 'qtag2', 'qtag3', 'qtag4'])) { $expected = $qcontext->id; } @@ -193,7 +188,7 @@ class core_question_backup_testcase extends advanced_testcase { // Restore to a new course in the new course category. $courseid3 = $this->restore_course($backupid2, $coursefullname, $courseshortname . '_3', $category2->id, $expectedwarnings); - $coursecontext3 = context_course::instance($courseid3); + $coursecontext3 = \context_course::instance($courseid3); // The questions should have been moved to a question category that belongs to a course context. $questions = $DB->get_records_sql("SELECT q.* @@ -206,7 +201,7 @@ class core_question_backup_testcase extends advanced_testcase { // Now, retrieve tags for each question and check if they are assigned at the right context. foreach ($questions as $question) { - $tags = core_tag_tag::get_item_tags('core_question', 'question', $question->id); + $tags = \core_tag_tag::get_item_tags('core_question', 'question', $question->id); // Each question is tagged with 4 tags (all are course tags now). $this->assertCount(4, $tags); @@ -247,8 +242,8 @@ class core_question_backup_testcase extends advanced_testcase { $this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id, 'manual'); // Backup the course. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id); + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); $results = $bc->get_results(); @@ -263,9 +258,9 @@ class core_question_backup_testcase extends advanced_testcase { question_delete_question($question->id); // Restore the course. - $restoredcourseid = restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); - $rc = new restore_controller($backupid, $restoredcourseid, backup::INTERACTIVE_NO, - backup::MODE_GENERAL, $USER->id, backup::TARGET_NEW_COURSE); + $restoredcourseid = \restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); + $rc = new \restore_controller($backupid, $restoredcourseid, \backup::INTERACTIVE_NO, + \backup::MODE_GENERAL, $USER->id, \backup::TARGET_NEW_COURSE); $rc->execute_precheck(); $rc->execute_plan(); $rc->destroy(); @@ -304,8 +299,8 @@ class core_question_backup_testcase extends advanced_testcase { quiz_add_quiz_question($question->id, $quiz); // Backup the course. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, - backup::INTERACTIVE_NO, backup::MODE_GENERAL, $USER->id); + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, + \backup::INTERACTIVE_NO, \backup::MODE_GENERAL, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); $results = $bc->get_results(); @@ -320,9 +315,9 @@ class core_question_backup_testcase extends advanced_testcase { question_delete_question($question->id); // Restore the course. - $restoredcourseid = restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); - $rc = new restore_controller($backupid, $restoredcourseid, backup::INTERACTIVE_NO, - backup::MODE_GENERAL, $USER->id, backup::TARGET_NEW_COURSE); + $restoredcourseid = \restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); + $rc = new \restore_controller($backupid, $restoredcourseid, \backup::INTERACTIVE_NO, + \backup::MODE_GENERAL, $USER->id, \backup::TARGET_NEW_COURSE); $rc->execute_precheck(); $rc->execute_plan(); $rc->destroy(); @@ -361,8 +356,8 @@ class core_question_backup_testcase extends advanced_testcase { quiz_add_quiz_question($question->id, $quiz); // Backup the course. - $bc = new backup_controller(backup::TYPE_1COURSE, $course->id, backup::FORMAT_MOODLE, - backup::INTERACTIVE_NO, backup::MODE_SAMESITE, $USER->id); + $bc = new \backup_controller(\backup::TYPE_1COURSE, $course->id, \backup::FORMAT_MOODLE, + \backup::INTERACTIVE_NO, \backup::MODE_SAMESITE, $USER->id); $backupid = $bc->get_backupid(); $bc->execute_plan(); $results = $bc->get_results(); @@ -380,9 +375,9 @@ class core_question_backup_testcase extends advanced_testcase { set_config('siteidentifier', random_string(32) . 'not the same site'); // Restore the course. - $restoredcourseid = restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); - $rc = new restore_controller($backupid, $restoredcourseid, backup::INTERACTIVE_NO, - backup::MODE_SAMESITE, $USER->id, backup::TARGET_NEW_COURSE); + $restoredcourseid = \restore_dbops::create_new_course($course->fullname, $course->shortname . '_1', $category->id); + $rc = new \restore_controller($backupid, $restoredcourseid, \backup::INTERACTIVE_NO, + \backup::MODE_SAMESITE, $USER->id, \backup::TARGET_NEW_COURSE); $rc->execute_precheck(); $rc->execute_plan(); $rc->destroy(); diff --git a/question/tests/bank_view_test.php b/question/tests/bank_view_test.php index d1dfc0556a9..d831370afff 100644 --- a/question/tests/bank_view_test.php +++ b/question/tests/bank_view_test.php @@ -14,6 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_question; + +use core_question\local\bank\question_edit_contexts; +use core_question\local\bank\view; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/question/editlib.php'); + /** * Unit tests for the question bank view class. * @@ -22,20 +32,7 @@ * @copyright 2018 the Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->dirroot . '/question/editlib.php'); - - -/** - * Unit tests for the question bank view class. - * - * @copyright 2018 the Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class core_question_bank_view_testcase extends advanced_testcase { +class bank_view_test extends \advanced_testcase { public function test_viewing_question_bank_should_not_load_individual_questions() { $this->resetAfterTest(); @@ -46,20 +43,20 @@ class core_question_bank_view_testcase extends advanced_testcase { // Create a course. $course = $generator->create_course(); - $context = context_course::instance($course->id); + $context = \context_course::instance($course->id); // Create a question in the default category. - $contexts = new core_question\local\bank\question_edit_contexts($context); + $contexts = new question_edit_contexts($context); $cat = question_make_default_categories($contexts->all()); $questiondata = $questiongenerator->create_question('numerical', null, ['name' => 'Example question', 'category' => $cat->id]); // Ensure the question is not in the cache. - $cache = cache::make('core', 'questiondata'); + $cache = \cache::make('core', 'questiondata'); $cache->delete($questiondata->id); // Generate the view. - $view = new core_question\local\bank\view($contexts, new moodle_url('/'), $course); + $view = new view($contexts, new \moodle_url('/'), $course); ob_start(); $pagevars = [ 'qpage' => 0, @@ -90,17 +87,17 @@ class core_question_bank_view_testcase extends advanced_testcase { // Create a course. $course = $generator->create_course(); - $context = context_course::instance($course->id); + $context = \context_course::instance($course->id); // Create a question in the default category. - $contexts = new core_question\local\bank\question_edit_contexts($context); + $contexts = new question_edit_contexts($context); $cat = question_make_default_categories($contexts->all()); $questiondata = $questiongenerator->create_question('numerical', null, ['name' => 'Example question', 'category' => $cat->id]); $DB->set_field('question', 'qtype', 'unknownqtype', ['id' => $questiondata->id]); // Generate the view. - $view = new core_question\local\bank\view($contexts, new moodle_url('/'), $course); + $view = new view($contexts, new \moodle_url('/'), $course); ob_start(); $pagevars = [ 'qpage' => 0, diff --git a/question/tests/calculated_question_summary_test.php b/question/tests/calculated_question_summary_test.php index b52c06f2405..5717f1caf7a 100644 --- a/question/tests/calculated_question_summary_test.php +++ b/question/tests/calculated_question_summary_test.php @@ -14,26 +14,19 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the calculated_random_question_summary class. - * - * @package core_question - * @category test - * @copyright 2018 Shamim Rezaie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); +namespace core_question; use core_question\statistics\questions\calculated_question_summary; /** * Class core_question_calculated_question_summary_testcase * + * @package core_question + * @category test * @copyright 2018 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class core_question_calculated_question_summary_testcase extends advanced_testcase { +class calculated_question_summary_test extends \advanced_testcase { /** * Provider for test_get_min_max_of. diff --git a/question/tests/importexport_test.php b/question/tests/importexport_test.php index b0b0b2725f6..a3cd0e064d4 100644 --- a/question/tests/importexport_test.php +++ b/question/tests/importexport_test.php @@ -17,12 +17,15 @@ /** * Unit tests for the question import and export system. * - * @package moodlecore - * @subpackage questionbank + * @package core_question + * @category test * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core_question; + +use qformat_default; defined('MOODLE_INTERNAL') || die(); @@ -30,7 +33,6 @@ global $CFG; require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->dirroot . '/question/format.php'); - /** * Subclass to make it easier to test qformat_default. * @@ -47,14 +49,13 @@ class testable_qformat extends qformat_default { } } - /** * Unit tests for the matching question definition class. * * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qformat_default_test extends advanced_testcase { +class importexport_test extends \advanced_testcase { public function test_assemble_category_path() { $format = new testable_qformat(); $pathsections = [ diff --git a/question/tests/least_used_variant_strategy_test.php b/question/tests/least_used_variant_strategy_test.php index d86a521ec61..4a76d11e65f 100644 --- a/question/tests/least_used_variant_strategy_test.php +++ b/question/tests/least_used_variant_strategy_test.php @@ -14,46 +14,45 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for the {@link core_question\engine\variants\least_used_strategy} class. - * - * @package core_question - * @copyright 2015 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; + +use core_question\engine\variants\least_used_strategy; +use qubaid_list; +use question_bank; +use question_engine; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Tests for the {@link core_question\engine\variants\least_used_strategy} class. * + * @package core_question * @copyright 2015 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class least_used_variant_strategy_testcase extends advanced_testcase { +class least_used_variant_strategy_test extends \advanced_testcase { public function test_question_with_one_variant_always_picks_that() { - $question = test_question_maker::make_question('shortanswer'); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $question = \test_question_maker::make_question('shortanswer'); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $slot = $quba->add_question($question); - $quba->start_all_questions(new core_question\engine\variants\least_used_strategy( + $quba->start_all_questions(new least_used_strategy( $quba, new qubaid_list([]))); $this->assertEquals(1, $quba->get_variant($slot)); } public function test_synchronised_question_should_use_the_same_dataset() { // Actually, we cheat here. We use the same question twice, not two different synchronised questions. - $question = test_question_maker::make_question('calculated'); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $question = \test_question_maker::make_question('calculated'); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $slot1 = $quba->add_question($question); $slot2 = $quba->add_question($question); - $quba->start_all_questions(new core_question\engine\variants\least_used_strategy( + $quba->start_all_questions(new least_used_strategy( $quba, new qubaid_list([]))); $this->assertEquals($quba->get_variant($slot1), $quba->get_variant($slot2)); } @@ -92,19 +91,19 @@ class least_used_variant_strategy_testcase extends advanced_testcase { $question = question_bank::load_question($questiondata->id); - $quba1 = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba1 = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba1->set_preferred_behaviour('deferredfeedback'); $slot1 = $quba1->add_question($question); - $quba1->start_all_questions(new core_question\engine\variants\least_used_strategy( + $quba1->start_all_questions(new least_used_strategy( $quba1, new qubaid_list([]))); question_engine::save_questions_usage_by_activity($quba1); $variant1 = $quba1->get_variant($slot1); // Second attempt should use the other variant. - $quba2 = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba2 = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba2->set_preferred_behaviour('deferredfeedback'); $slot2 = $quba2->add_question($question); - $quba2->start_all_questions(new core_question\engine\variants\least_used_strategy( + $quba2->start_all_questions(new least_used_strategy( $quba1, new qubaid_list([$quba1->get_id()]))); question_engine::save_questions_usage_by_activity($quba2); $variant2 = $quba2->get_variant($slot2); @@ -112,10 +111,10 @@ class least_used_variant_strategy_testcase extends advanced_testcase { $this->assertNotEquals($variant1, $variant2); // Third attempt uses either variant at random. - $quba3 = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba3 = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba3->set_preferred_behaviour('deferredfeedback'); $slot3 = $quba3->add_question($question); - $quba3->start_all_questions(new core_question\engine\variants\least_used_strategy( + $quba3->start_all_questions(new least_used_strategy( $quba1, new qubaid_list([$quba1->get_id(), $quba2->get_id()]))); $variant3 = $quba3->get_variant($slot3); diff --git a/question/tests/question_bank_column_test.php b/question/tests/question_bank_column_test.php index 51b0b9ea1eb..ea8bfce8445 100644 --- a/question/tests/question_bank_column_test.php +++ b/question/tests/question_bank_column_test.php @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the question bank column class. - * - * @package core_question - * @copyright 2018 Huong Nguyen - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; + +use core_question\local\bank\question_edit_contexts; +use core_question\local\bank\view; +use testable_core_question_column; defined('MOODLE_INTERNAL') || die(); @@ -35,7 +33,7 @@ require_once($CFG->dirroot . '/question/tests/fixtures/testable_core_question_co * @copyright 2018 Huong Nguyen * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_bank_column_testcase extends advanced_testcase { +class question_bank_column_test extends \advanced_testcase { /** * Test function display_header multiple sorts with no custom tooltips. @@ -44,9 +42,9 @@ class question_bank_column_testcase extends advanced_testcase { public function test_column_header_multi_sort_no_tooltips() { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); - $questionbank = new core_question\local\bank\view( - new core_question\local\bank\question_edit_contexts(context_course::instance($course->id)), - new moodle_url('/'), + $questionbank = new view( + new question_edit_contexts(\context_course::instance($course->id)), + new \moodle_url('/'), $course ); $columnbase = new testable_core_question_column($questionbank); @@ -78,9 +76,9 @@ class question_bank_column_testcase extends advanced_testcase { public function test_column_header_multi_sort_with_tooltips() { $this->resetAfterTest(); $course = $this->getDataGenerator()->create_course(); - $questionbank = new core_question\local\bank\view( - new core_question\local\bank\question_edit_contexts(context_course::instance($course->id)), - new moodle_url('/'), + $questionbank = new view( + new question_edit_contexts(\context_course::instance($course->id)), + new \moodle_url('/'), $course ); $columnbase = new testable_core_question_column($questionbank); diff --git a/question/tests/random_question_loader_test.php b/question/tests/random_question_loader_test.php index a34fdc6ca6f..8e706765ef3 100644 --- a/question/tests/random_question_loader_test.php +++ b/question/tests/random_question_loader_test.php @@ -14,24 +14,20 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace core_question; + +use qubaid_list; +use question_bank; +use question_engine; + /** * Tests for the {@see core_question\local\bank\random_question_loader} class. * * @package core_question - * @copyright 2015 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - - -/** - * Tests for the {@see core_question\local\bank\random_question_loader} class. - * * @copyright 2015 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class random_question_loader_testcase extends advanced_testcase { +class random_question_loader_test extends \advanced_testcase { public function test_empty_category_gives_null() { $this->resetAfterTest(); @@ -168,7 +164,7 @@ class random_question_loader_testcase extends advanced_testcase { $cat = $generator->create_question_category(); $question1 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); $question2 = $generator->create_question('shortanswer', null, ['category' => $cat->id]); - $quba = question_engine::make_questions_usage_by_activity('test', context_system::instance()); + $quba = question_engine::make_questions_usage_by_activity('test', \context_system::instance()); $quba->set_preferred_behaviour('deferredfeedback'); $question = question_bank::load_question($question2->id); $quba->add_question($question); @@ -317,8 +313,8 @@ class random_question_loader_testcase extends advanced_testcase { 'subcat', 'foo' ]; - $collid = core_tag_collection::get_default(); - $tags = core_tag_tag::create_if_missing($collid, $tagnames); + $collid = \core_tag_collection::get_default(); + $tags = \core_tag_tag::create_if_missing($collid, $tagnames); $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); // First category and questions. @@ -527,8 +523,8 @@ class random_question_loader_testcase extends advanced_testcase { 'subcat', 'foo' ]; - $collid = core_tag_collection::get_default(); - $tags = core_tag_tag::create_if_missing($collid, $tagnames); + $collid = \core_tag_collection::get_default(); + $tags = \core_tag_tag::create_if_missing($collid, $tagnames); $generator = $this->getDataGenerator()->get_plugin_generator('core_question'); // First category and questions. @@ -589,8 +585,8 @@ class random_question_loader_testcase extends advanced_testcase { } if (!empty($tagnames) && !empty($questions)) { - $context = context::instance_by_id($category->contextid); - core_tag_tag::set_item_tags('core_question', 'question', $questions[0]->id, $context, $tagnames); + $context = \context::instance_by_id($category->contextid); + \core_tag_tag::set_item_tags('core_question', 'question', $questions[0]->id, $context, $tagnames); } return [$category, $questions]; diff --git a/question/type/calculated/tests/formula_validation_test.php b/question/type/calculated/tests/formula_validation_test.php index 3e87ccd169b..a0bbc88460b 100644 --- a/question/type/calculated/tests/formula_validation_test.php +++ b/question/type/calculated/tests/formula_validation_test.php @@ -14,6 +14,13 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qtype_calculated; + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; +require_once($CFG->dirroot . '/question/type/calculated/questiontype.php'); + /** * Unit tests for formula validation code. * @@ -21,21 +28,7 @@ * @copyright 2014 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - - -defined('MOODLE_INTERNAL') || die(); - -global $CFG; -require_once($CFG->dirroot . '/question/type/calculated/questiontype.php'); - - -/** - * Unit tests for formula validation code. - * - * @copyright 2014 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class qtype_calculated_formula_validation_testcase extends basic_testcase { +class formula_validation_test extends \basic_testcase { protected function assert_nonempty_string($actual) { $this->assertIsString($actual); $this->assertNotEquals('', $actual); diff --git a/question/type/calculated/tests/variablesubstituter_test.php b/question/type/calculated/tests/variablesubstituter_test.php index 4c813dae78d..453f8b490ef 100644 --- a/question/type/calculated/tests/variablesubstituter_test.php +++ b/question/type/calculated/tests/variablesubstituter_test.php @@ -14,15 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for qtype_calculated_variable_substituter. - * - * @package qtype - * @subpackage calculated - * @copyright 2011 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_calculated; +use qtype_calculated_variable_substituter; defined('MOODLE_INTERNAL') || die(); @@ -30,14 +24,14 @@ global $CFG; require_once($CFG->dirroot . '/question/type/calculated/question.php'); require_once($CFG->dirroot . '/question/type/calculated/questiontype.php'); - /** * Unit tests for {@link qtype_calculated_variable_substituter}. * + * @package qtype_calculated * @copyright 2011 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qtype_calculated_variable_substituter_test extends advanced_testcase { +class variablesubstituter_test extends \advanced_testcase { public function test_simple_expression() { $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.'); $this->assertEquals(3, $vs->calculate('{a} + {b}')); @@ -49,19 +43,19 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase { } public function test_cannot_use_nonnumbers() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $vs = new qtype_calculated_variable_substituter(array('a' => 'frog', 'b' => -2), '.'); } public function test_invalid_expression() { $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $vs->calculate('{a} + {b}?'); } public function test_tricky_invalid_expression() { $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 2), '.'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $vs->calculate('{a}{b}'); // Have to make sure this does not just evaluate to 12. } @@ -72,7 +66,7 @@ class qtype_calculated_variable_substituter_test extends advanced_testcase { } $vs = new qtype_calculated_variable_substituter(array('a' => 1, 'b' => 0), '.'); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $vs->calculate('{a} / {b}'); } diff --git a/question/type/ddmarker/tests/shapes_test.php b/question/type/ddmarker/tests/shapes_test.php index d226a7a30ad..5a43282c8ab 100644 --- a/question/type/ddmarker/tests/shapes_test.php +++ b/question/type/ddmarker/tests/shapes_test.php @@ -14,29 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the drag-and-drop words shape code. - * - * @package qtype_ddmarker - * @copyright 2012 The Open University - * @author Jamie Pratt - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_ddmarker; +use qtype_ddmarker_shape_circle; +use qtype_ddmarker_shape_polygon; +use qtype_ddmarker_shape_rectangle; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/type/ddmarker/shapes.php'); - /** - * Unit tests for shape code + * Unit tests for the drag-and-drop words shape code. * + * @package qtype_ddmarker * @copyright 2012 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qtype_ddmarker_shapes_test extends basic_testcase { +class shapes_test extends \basic_testcase { public function test_polygon_valdiation_test_ok() { $shape = new qtype_ddmarker_shape_polygon('10, 10; 20, 10; 20, 20; 10, 20'); diff --git a/question/type/essay/tests/restore_test.php b/question/type/essay/tests/restore_test.php index ab27f7c994a..5269fe00dc5 100644 --- a/question/type/essay/tests/restore_test.php +++ b/question/type/essay/tests/restore_test.php @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Test restore logic. - * - * @package qtype_essay - * @copyright 2019 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_essay; defined('MOODLE_INTERNAL') || die(); @@ -30,10 +24,11 @@ require_once($CFG->libdir . "/phpunit/classes/restore_date_testcase.php"); /** * Test restore logic. * + * @package qtype_essay * @copyright 2019 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qtype_essay_restore_testcase extends restore_date_testcase { +class restore_test extends \restore_date_testcase { /** * Test missing qtype_essay_options creation. @@ -48,7 +43,7 @@ class qtype_essay_restore_testcase extends restore_date_testcase { // Create a course with one essay question in its question bank. $generator = $this->getDataGenerator(); $course = $generator->create_course(); - $contexts = new core_question\local\bank\question_edit_contexts(context_course::instance($course->id)); + $contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($course->id)); $category = question_make_default_categories($contexts->all()); $questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question'); $essay = $questiongenerator->create_question('essay', null, array('category' => $category->id)); @@ -60,7 +55,7 @@ class qtype_essay_restore_testcase extends restore_date_testcase { $newcourseid = $this->backup_and_restore($course); // Verify that the restored question has options. - $contexts = new core_question\local\bank\question_edit_contexts(context_course::instance($newcourseid)); + $contexts = new \core_question\local\bank\question_edit_contexts(\context_course::instance($newcourseid)); $newcategory = question_make_default_categories($contexts->all()); $newessay = $DB->get_record_sql('SELECT q.* FROM {question} q diff --git a/question/type/match/tests/backup_test.php b/question/type/match/tests/backup_test.php index ec34d0b085a..3673cb42ff3 100644 --- a/question/type/match/tests/backup_test.php +++ b/question/type/match/tests/backup_test.php @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Tests for the matching question type backup and restore logic. - * - * @package qtype_match - * @copyright 2020 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. - */ +namespace qtype_match; + +use question_bank; defined('MOODLE_INTERNAL') || die(); @@ -29,11 +25,14 @@ require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); require_once($CFG->dirroot . '/course/externallib.php'); - /** * Tests for the matching question type backup and restore logic. + * + * @package qtype_match + * @copyright 2020 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. */ -class qtype_match_backup_testcase extends advanced_testcase { +class backup_test extends \advanced_testcase { /** * Duplicate quiz with a matching question, and check it worked. @@ -49,7 +48,7 @@ class qtype_match_backup_testcase extends advanced_testcase { // Create a course with a page that embeds a question. $course = $coregenerator->create_course(); $quiz = $coregenerator->create_module('quiz', ['course' => $course->id]); - $quizcontext = context_module::instance($quiz->cmid); + $quizcontext = \context_module::instance($quiz->cmid); $cat = $questiongenerator->create_question_category(['contextid' => $quizcontext->id]); $question = $questiongenerator->create_question('match', 'trickynums', ['category' => $cat->id]); diff --git a/question/type/missingtype/tests/missingtype_test.php b/question/type/missingtype/tests/missingtype_test.php index 448a6e3efff..44ab9e414c3 100644 --- a/question/type/missingtype/tests/missingtype_test.php +++ b/question/type/missingtype/tests/missingtype_test.php @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * This file contains tests for the 'missing' question type. - * - * @package qtype - * @subpackage missingtype - * @copyright 2010 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_missingtype; +use qbehaviour_deferredfeedback; +use qtype_missingtype; +use qtype_missingtype_question; +use question_attempt_step; +use question_bank; +use question_contains_tag_with_attribute; +use question_display_options; +use question_state; +use testable_question_attempt; defined('MOODLE_INTERNAL') || die(); @@ -35,13 +37,14 @@ require_once($CFG->dirroot . '/question/type/missingtype/questiontype.php'); /** * Unit tests for the 'missing' question type. * + * @package qtype_missingtype * @copyright 2010 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class qtype_missing_test extends question_testcase { +class missingtype_test extends \question_testcase { protected function get_unknown_questiondata() { - $questiondata = new stdClass(); + $questiondata = new \stdClass(); $questiondata->id = 0; $questiondata->category = 0; $questiondata->contextid = 0; @@ -71,12 +74,12 @@ class qtype_missing_test extends question_testcase { public function test_cannot_grade() { $q = new qtype_missingtype_question(); - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $q->grade_response(array()); } public function test_load_qtype_strict() { - $this->expectException(moodle_exception::class); + $this->expectException(\moodle_exception::class); $qtype = question_bank::get_qtype('strange_unknown'); } @@ -89,7 +92,7 @@ class qtype_missing_test extends question_testcase { $questiondata = $this->get_unknown_questiondata(); $q = question_bank::make_question($questiondata); $this->assertInstanceOf('qtype_missingtype_question', $q); - $this->assertEquals($q->questiontext, html_writer::tag('div', + $this->assertEquals($q->questiontext, \html_writer::tag('div', get_string('missingqtypewarning', 'qtype_missingtype'), array('class' => 'warning missingqtypewarning')) . $questiondata->questiontext); diff --git a/question/type/multichoice/tests/question_multi_test.php b/question/type/multichoice/tests/question_multi_test.php index 7ca1012495a..99ff5165d3b 100644 --- a/question/type/multichoice/tests/question_multi_test.php +++ b/question/type/multichoice/tests/question_multi_test.php @@ -14,31 +14,30 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the multiple choice, multi-response question definition classes. - * - * @package qtype_multichoice - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_multichoice; + +use question_attempt_step; +use question_classified_response; +use question_display_options; +use question_state; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Unit tests for the multiple choice, multi-response question definition class. * + * @package qtype_multichoice * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \qtype_multichoice_multi_question */ -class qtype_multichoice_multi_question_test extends advanced_testcase { +class question_multi_test extends \advanced_testcase { public function test_get_expected_data() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array('choice0' => PARAM_BOOL, 'choice1' => PARAM_BOOL, @@ -46,7 +45,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_is_complete_response() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertFalse($question->is_complete_response(array())); @@ -58,7 +57,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_is_gradable_response() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertFalse($question->is_gradable_response(array())); @@ -70,7 +69,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_is_same_response() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertTrue($question->is_same_response( @@ -91,7 +90,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_grading() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(1, question_state::$gradedright), @@ -105,14 +104,14 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_get_correct_response() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals($question->prepare_simulated_post_data(array('A' => 1, 'C' => 1)), $question->get_correct_response()); } public function test_get_question_summary() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $mc->start_attempt(new question_attempt_step(), 1); $qsummary = $mc->get_question_summary(); @@ -124,7 +123,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_summarise_response() { - $mc = test_question_maker::make_a_multichoice_multi_question(); + $mc = \test_question_maker::make_a_multichoice_multi_question(); $mc->shuffleanswers = false; $mc->start_attempt(new question_attempt_step(), 1); @@ -134,7 +133,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_summarise_response_clearchoice() { - $mc = test_question_maker::make_a_multichoice_multi_question(); + $mc = \test_question_maker::make_a_multichoice_multi_question(); $mc->shuffleanswers = false; $mc->start_attempt(new question_attempt_step(), 1); @@ -144,7 +143,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_un_summarise_response() { - $mc = test_question_maker::make_a_multichoice_multi_question(); + $mc = \test_question_maker::make_a_multichoice_multi_question(); $mc->shuffleanswers = false; $mc->start_attempt(new question_attempt_step(), 1); @@ -154,7 +153,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_classify_response() { - $mc = test_question_maker::make_a_multichoice_multi_question(); + $mc = \test_question_maker::make_a_multichoice_multi_question(); $mc->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array( @@ -166,7 +165,7 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { } public function test_prepare_simulated_post_data() { - $mc = test_question_maker::make_a_multichoice_multi_question(); + $mc = \test_question_maker::make_a_multichoice_multi_question(); $mc->start_attempt(new question_attempt_step(), 1); $correctanswers = array( array(), @@ -188,9 +187,9 @@ class qtype_multichoice_multi_question_test extends advanced_testcase { * test_get_question_definition_for_external_rendering */ public function test_get_question_definition_for_external_rendering() { - $question = test_question_maker::make_a_multichoice_multi_question(); + $question = \test_question_maker::make_a_multichoice_multi_question(); $question->start_attempt(new question_attempt_step(), 1); - $qa = test_question_maker::get_a_qa($question); + $qa = \test_question_maker::get_a_qa($question); $displayoptions = new question_display_options(); $options = $question->get_question_definition_for_external_rendering($qa, $displayoptions); diff --git a/question/type/multichoice/tests/question_single_test.php b/question/type/multichoice/tests/question_single_test.php index 2a2c6647f43..7a7c370bfdb 100644 --- a/question/type/multichoice/tests/question_single_test.php +++ b/question/type/multichoice/tests/question_single_test.php @@ -14,36 +14,37 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the multiple choice, single response question definition classes. - * - * @package qtype_multichoice - * @copyright 2009 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace qtype_multichoice; + +use qtype_multichoice_multi_question; +use question_answer; +use question_attempt_step; +use question_bank; +use question_classified_response; +use question_state; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Unit tests for the multiple choice, single response question definition class. * + * @package qtype_multichoice * @copyright 2009 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @covers \qtype_multichoice_single_question */ -class qtype_multichoice_single_question_test extends advanced_testcase { +class question_single_test extends \advanced_testcase { public function test_get_expected_data() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $this->assertEquals(array('answer' => PARAM_INT), $question->get_expected_data()); } public function test_is_complete_response() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $this->assertFalse($question->is_complete_response(array())); $this->assertTrue($question->is_complete_response(array('answer' => '0'))); @@ -53,7 +54,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_is_gradable_response() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $this->assertFalse($question->is_gradable_response(array())); $this->assertTrue($question->is_gradable_response(array('answer' => '0'))); @@ -62,7 +63,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_is_same_response() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertTrue($question->is_same_response( @@ -103,7 +104,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_grading() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array(1, question_state::$gradedright), @@ -117,7 +118,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { public function test_grading_rounding_three_right() { question_bank::load_question_definition_classes('multichoice'); $mc = new qtype_multichoice_multi_question(); - test_question_maker::initialise_a_question($mc); + \test_question_maker::initialise_a_question($mc); $mc->name = 'Odd numbers'; $mc->questiontext = 'Which are the odd numbers?'; $mc->generalfeedback = '1, 3 and 5 are the odd numbers.'; @@ -126,7 +127,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { $mc->answernumbering = 'abc'; $mc->showstandardinstruction = 0; - test_question_maker::set_standard_combined_feedback_fields($mc); + \test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array( 11 => new question_answer(11, '1', 0.3333333, '', FORMAT_HTML), @@ -145,18 +146,18 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_get_correct_response() { - $question = test_question_maker::make_a_multichoice_single_question(); + $question = \test_question_maker::make_a_multichoice_single_question(); $question->start_attempt(new question_attempt_step(), 1); $this->assertEquals($question->prepare_simulated_post_data(array('answer' => 'A')), $question->get_correct_response()); } public function test_summarise_response() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $mc->start_attempt(new question_attempt_step(), 1); $summary = $mc->summarise_response($mc->prepare_simulated_post_data(array('answer' => 'A')), - test_question_maker::get_a_qa($mc)); + \test_question_maker::get_a_qa($mc)); $this->assertEquals('A', $summary); @@ -165,7 +166,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_un_summarise_response() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $mc->shuffleanswers = false; $mc->start_attempt(new question_attempt_step(), 1); @@ -175,7 +176,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_classify_response() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $mc->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array($mc->id => new question_classified_response(14, 'B', -0.3333333)), @@ -191,7 +192,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_make_html_inline() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $this->assertEquals('Frog', $mc->make_html_inline('

Frog

')); $this->assertEquals('Frog
Toad', $mc->make_html_inline("

Frog

\n

Toad

")); $this->assertEquals('Graph', @@ -205,7 +206,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_simulated_post_data() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $mc->shuffleanswers = false; $mc->answers[13]->answer = '

A

'; $mc->answers[14]->answer = '

B

'; @@ -222,7 +223,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_validate_can_regrade_with_other_version_bad() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $newmc = clone($mc); $newmc->answers = array( @@ -235,7 +236,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_validate_can_regrade_with_other_version_ok() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $newmc = clone($mc); $newmc->answers = array( @@ -248,7 +249,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_update_attempt_state_date_from_old_version_bad() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $newmc = clone($mc); $newmc->answers = array( @@ -263,7 +264,7 @@ class qtype_multichoice_single_question_test extends advanced_testcase { } public function test_update_attempt_state_date_from_old_version_ok() { - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $newmc = clone($mc); $newmc->answers = array( diff --git a/question/type/numerical/tests/answer_test.php b/question/type/numerical/tests/answer_test.php index a74fed3c924..6aad7d975d6 100644 --- a/question/type/numerical/tests/answer_test.php +++ b/question/type/numerical/tests/answer_test.php @@ -14,22 +14,25 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace qtype_numerical; -/** - * Unit tests for the numerical question definition class. - * - * @package moodlecore - * @subpackage questiontypes - * @copyright 2008 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +use qtype_numerical_answer; + +defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); require_once($CFG->dirroot . '/question/type/numerical/question.php'); - -class qtype_numerical_answer_test extends advanced_testcase { +/** + * Unit tests for the numerical question definition class. + * + * @package qtype_numerical + * @category test + * @copyright 2008 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class answer_test extends \advanced_testcase { public function test_within_tolerance_nominal() { $answer = new qtype_numerical_answer(13, 7.0, 1.0, '', FORMAT_MOODLE, 1.0); diff --git a/question/type/numerical/tests/answerprocessor_test.php b/question/type/numerical/tests/answerprocessor_test.php index 8f1dbe595bd..e50bfc56829 100644 --- a/question/type/numerical/tests/answerprocessor_test.php +++ b/question/type/numerical/tests/answerprocessor_test.php @@ -14,16 +14,21 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . - /** - * Unit tests for the numerical question definition class. + * Unit tests for the numerical questions answers processor. * - * @package moodlecore - * @subpackage questiontypes - * @copyright 2008 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package qtype_numerical + * @category test + * @copyright 2008 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace qtype_numerical; + +use qtype_numerical_answer_processor; + +defined('MOODLE_INTERNAL') || die(); + global $CFG; require_once($CFG->dirroot . '/question/type/numerical/questiontype.php'); @@ -33,7 +38,15 @@ class testable_qtype_numerical_answer_processor extends qtype_numerical_answer_p } } -class qtype_numerical_answer_processor_test extends advanced_testcase { +/** + * Unit test for the numerical questions answers processor. + * + * @package qtype_numerical + * @category test + * @copyright 2008 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class answerprocessor_test extends \advanced_testcase { public function test_parse_response() { $ap = new testable_qtype_numerical_answer_processor( array('m' => 1, 'cm' => 100), false, '.', ','); @@ -142,7 +155,6 @@ class qtype_numerical_answer_processor_test extends advanced_testcase { $this->assertEquals(array('100', '', null), $ap->apply_units('100')); } - public function test_currency() { $ap = new qtype_numerical_answer_processor(array('$' => 1, '£' => 1), true, '.', ','); diff --git a/question/type/tests/question_definition_test.php b/question/type/tests/question_definition_test.php index 3bcd50f531c..aeafe70fa86 100644 --- a/question/type/tests/question_definition_test.php +++ b/question/type/tests/question_definition_test.php @@ -14,30 +14,24 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the question_definition base classes. - * - * @package core_question - * @copyright 2015 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); - /** * Test for question_definition base classes. * + * @package core_question * @copyright 2015 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_definition_testcase extends advanced_testcase { +class question_definition_test extends \advanced_testcase { public function test_make_html_inline() { // Base class is abstract, so we need to pick one qusetion type to test this method. - $mc = test_question_maker::make_a_multichoice_single_question(); + $mc = \test_question_maker::make_a_multichoice_single_question(); $this->assertEquals('Frog', $mc->make_html_inline('

Frog

')); $this->assertEquals('Frog', $mc->make_html_inline('

Frog

')); $this->assertEquals('Frog
Toad', $mc->make_html_inline("

Frog

\n

Toad

")); diff --git a/question/type/tests/question_first_matching_answer_grading_strategy_test.php b/question/type/tests/question_first_matching_answer_grading_strategy_test.php index 5f1967f6e7b..b515c943438 100644 --- a/question/type/tests/question_first_matching_answer_grading_strategy_test.php +++ b/question/type/tests/question_first_matching_answer_grading_strategy_test.php @@ -22,19 +22,23 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +namespace core_question; + +use question_answer; +use question_first_matching_answer_grading_strategy; + defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/type/questiontypebase.php'); - /** * Helper used by the testcases in this file. * * @copyright 2008 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class test_response_answer_comparer implements question_response_answer_comparer { +class test_response_answer_comparer implements \question_response_answer_comparer { protected $answers = array(); public function __construct($answers) { @@ -50,14 +54,14 @@ class test_response_answer_comparer implements question_response_answer_comparer } } - /** * Tests for {@link question_first_matching_answer_grading_strategy}. * + * @package core_question * @copyright 2008 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_first_matching_answer_grading_strategy_testcase extends advanced_testcase { +class question_first_matching_answer_grading_strategy_test extends \advanced_testcase { protected function setUp(): void { } diff --git a/question/type/tests/question_hint_test.php b/question/type/tests/question_hint_test.php index 8f6e6b2ee81..7978764e1fe 100644 --- a/question/type/tests/question_hint_test.php +++ b/question/type/tests/question_hint_test.php @@ -14,29 +14,26 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Unit tests for the question_hint and subclasses. - * - * @package core_question - * @copyright 2008 The Open University - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ +namespace core_question; + +use question_hint; +use question_hint_with_parts; defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/question/type/questiontypebase.php'); - /** * Test for question_hint and subclasses. * + * @package core_question * @copyright 2010 The Open University * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class question_hint_testcase extends advanced_testcase { +class question_hint_test extends \advanced_testcase { public function test_basic() { - $row = new stdClass(); + $row = new \stdClass(); $row->id = 123; $row->hint = 'A hint'; $row->hintformat = FORMAT_HTML; @@ -47,7 +44,7 @@ class question_hint_testcase extends advanced_testcase { } public function test_with_parts() { - $row = new stdClass(); + $row = new \stdClass(); $row->id = 123; $row->hint = 'A hint'; $row->hintformat = FORMAT_HTML;