MDL-61364 question: adjust code and fix phpunit errors

This commit is contained in:
Simey Lameze 2018-03-26 11:31:24 +08:00
parent e7329cd026
commit 2cf7bde8e9
5 changed files with 7 additions and 1 deletions

View file

@ -929,7 +929,7 @@ class view {
if (preg_match('!^q([0-9]+)$!', $key, $matches)) { if (preg_match('!^q([0-9]+)$!', $key, $matches)) {
$key = $matches[1]; $key = $matches[1];
$questionlist .= $key.','; $questionlist .= $key.',';
question_require_capability_on($key, 'edit'); question_require_capability_on((int)$key, 'edit');
if (questions_in_use(array($key))) { if (questions_in_use(array($key))) {
$questionnames .= '* '; $questionnames .= '* ';
$inuse = true; $inuse = true;

View file

@ -119,6 +119,7 @@ abstract class question_test_helper {
$catcontext = context::instance_by_id($cat->contextid, MUST_EXIST); $catcontext = context::instance_by_id($cat->contextid, MUST_EXIST);
$contexts = new question_edit_contexts($catcontext); $contexts = new question_edit_contexts($catcontext);
$dataforformconstructor = new stdClass(); $dataforformconstructor = new stdClass();
$dataforformconstructor->createdby = $questiondata->createdby;
$dataforformconstructor->qtype = $questiondata->qtype; $dataforformconstructor->qtype = $questiondata->qtype;
$dataforformconstructor->contextid = $questiondata->contextid = $catcontext->id; $dataforformconstructor->contextid = $questiondata->contextid = $catcontext->id;
$dataforformconstructor->category = $questiondata->category = $cat->id; $dataforformconstructor->category = $questiondata->category = $cat->id;

View file

@ -162,6 +162,7 @@ if (isset($question->categoryobject)) {
$question->formoptions = new stdClass(); $question->formoptions = new stdClass();
$categorycontext = context::instance_by_id($category->contextid); $categorycontext = context::instance_by_id($category->contextid);
$question->contextid = $category->contextid;
$addpermission = has_capability('moodle/question:add', $categorycontext); $addpermission = has_capability('moodle/question:add', $categorycontext);
if ($id) { if ($id) {

View file

@ -209,9 +209,11 @@ class qtype_calculatedsimple_test_helper extends question_test_helper {
} }
public function get_calculatedsimple_question_data_sumwithvariants() { public function get_calculatedsimple_question_data_sumwithvariants() {
global $USER;
$q = new stdClass(); $q = new stdClass();
$q->name = 'Calculated simple'; $q->name = 'Calculated simple';
$q->createdby = $USER->id;
$q->questiontext = '<p>This is a simple sum of two variables.</p>'; $q->questiontext = '<p>This is a simple sum of two variables.</p>';
$q->questiontextformat = '1'; $q->questiontextformat = '1';
$q->generalfeedback = '<p>The answer is  {a} + {b}</p>'; $q->generalfeedback = '<p>The answer is  {a} + {b}</p>';

View file

@ -43,6 +43,8 @@ class qtype_gapselect_edit_form_base_testable extends qtype_gapselect_edit_form_
$category = question_make_default_categories(array($syscontext)); $category = question_make_default_categories(array($syscontext));
$fakequestion = new stdClass(); $fakequestion = new stdClass();
$fakequestion->qtype = 'stack'; $fakequestion->qtype = 'stack';
$fakequestion->contextid = $syscontext->id;
$fakequestion->createdby = 2;
$fakequestion->category = $category->id; $fakequestion->category = $category->id;
$fakequestion->questiontext = 'Test [[1]] question [[2]]'; $fakequestion->questiontext = 'Test [[1]] question [[2]]';
$fakequestion->options = new stdClass(); $fakequestion->options = new stdClass();