protected function get_test_question_data() { global $USER; $q = new stdClass(); $q->id = 0; $q->name = 'Gapfill Question'; $q->category = 0; $q->contextid = 0; $q->parent = 0; $q->questiontext = 'The [cat] sat on the [mat]'; $q->questiontextformat = FORMAT_HTML; $q->generalfeedback = 'General feedback.'; $q->generalfeedbackformat = FORMAT_HTML; $q->defaultmark = 1; $q->penalty = 0.3333333; $q->length = 1; $q->stamp = make_unique_id_code(); $q->version = make_unique_id_code(); $q->hidden = 0; $q->timecreated = time(); $q->timemodified = time(); $q->createdby = $USER->id; $q->modifiedby = $USER->id; $q->options = new stdClass(); test_question_maker::set_standard_combined_feedback_fields($q->options); $q->options->displayanswers = 0; $q->options->delimitchars = "[]"; return $q; }
/** * Makes a calculated question about summing two numbers. * @return qtype_calculated_question */ public function make_calculated_question_sum() { question_bank::load_question_definition_classes('calculated'); $q = new qtype_calculated_question(); test_question_maker::initialise_a_question($q); $q->name = 'Simple sum'; $q->questiontext = 'What is {a} + {b}?'; $q->generalfeedback = 'Generalfeedback: {={a} + {b}} is the right answer.'; $q->answers = array( 13 => new qtype_numerical_answer(13, '{a} + {b}', 1.0, 'Very good.', FORMAT_HTML, 0), 14 => new qtype_numerical_answer(14, '{a} - {b}', 0.0, 'Add. not subtract!.', FORMAT_HTML, 0), 17 => new qtype_numerical_answer(17, '*', 0.0, 'Completely wrong.', FORMAT_HTML, 0), ); foreach ($q->answers as $answer) { $answer->correctanswerlength = 2; $answer->correctanswerformat = 1; } $q->qtype = question_bank::get_qtype('calculated'); $q->unitdisplay = qtype_numerical::UNITNONE; $q->unitgradingtype = 0; $q->unitpenalty = 0; $q->ap = new qtype_numerical_answer_processor(array()); $q->synchronised = false; $q->datasetloader = new qtype_calculated_test_dataset_loader(0, array( array('a' => 1, 'b' => 5), array('a' => 3, 'b' => 4), )); return $q; }
public function test_render_missing() { $records = new question_test_recordset(array(array('questionattemptid', 'contextid', 'questionusageid', 'slot', 'behaviour', 'questionid', 'variant', 'maxmark', 'minfraction', 'maxfraction', 'flagged', 'questionsummary', 'rightanswer', 'responsesummary', 'timemodified', 'attemptstepid', 'sequencenumber', 'state', 'fraction', 'timecreated', 'userid', 'name', 'value'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 1, 0, 'todo', null, 1256233700, 1, '_order', '1,2,3'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 2, 1, 'complete', 0.5, 1256233705, 1, '-submit', '1'), array(1, 123, 1, 1, 'strangeunknown', -1, 1, 2.0, 0.0, 1.0, 0, '', '', '', 1256233790, 2, 1, 'complete', 0.5, 1256233705, 1, 'choice0', '1'))); $question = test_question_maker::make_question('truefalse', 'true'); $question->id = -1; question_bank::start_unit_test(); question_bank::load_test_question_data($question); $qa = question_attempt::load_from_records($records, 1, new question_usage_null_observer(), 'deferredfeedback'); question_bank::end_unit_test(); $this->assertEquals(2, $qa->get_num_steps()); $step = $qa->get_step(0); $this->assertEquals(question_state::$todo, $step->get_state()); $this->assertNull($step->get_fraction()); $this->assertEquals(1256233700, $step->get_timecreated()); $this->assertEquals(1, $step->get_user_id()); $this->assertEquals(array('_order' => '1,2,3'), $step->get_all_data()); $step = $qa->get_step(1); $this->assertEquals(question_state::$complete, $step->get_state()); $this->assertEquals(0.5, $step->get_fraction()); $this->assertEquals(1256233705, $step->get_timecreated()); $this->assertEquals(1, $step->get_user_id()); $this->assertEquals(array('-submit' => '1', 'choice0' => '1'), $step->get_all_data()); $output = $qa->render(new question_display_options(), '1'); $this->assertRegExp('/' . preg_quote($qa->get_question()->questiontext, '/') . '/', $output); $this->assertRegExp('/' . preg_quote(get_string('questionusedunknownmodel', 'qbehaviour_missing'), '/') . '/', $output); $this->assertTag(array('tag' => 'div', 'attributes' => array('class' => 'warning')), $output); }
public function test_informationitem_feedback_description() { // Create a true-false question with correct answer true. $description = test_question_maker::make_question('description'); $this->start_attempt_at_question($description, 'deferredfeedback'); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_question_text_expectation($description), new question_contains_tag_with_attributes('input', array('type' => 'hidden', 'name' => $this->quba->get_field_prefix($this->slot) . '-seen', 'value' => 1)), $this->get_does_not_contain_feedback_expectation()); // Process a submission indicating this question has been seen. $this->process_submission(array('-seen' => 1)); $this->check_current_state(question_state::$complete); $this->check_current_mark(null); $this->check_current_output($this->get_does_not_contain_correctness_expectation(), new question_no_pattern_expectation('/type=\\"hidden\\"[^>]*name=\\"[^"]*seen\\"|name=\\"[^"]*seen\\"[^>]*type=\\"hidden\\"/'), $this->get_does_not_contain_feedback_expectation()); // Finish the attempt. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$finished); $this->check_current_mark(null); $this->check_current_output($this->get_contains_question_text_expectation($description), $this->get_contains_general_feedback_expectation($description)); // Process a manual comment. $this->manual_grade('Not good enough!', null, FORMAT_HTML); $this->check_current_state(question_state::$manfinished); $this->check_current_mark(null); $this->check_current_output(new question_pattern_expectation('/' . preg_quote('Not good enough!', '/') . '/')); // Check that trying to process a manual comment with a grade causes an exception. $this->setExpectedException('moodle_exception'); $this->manual_grade('Not good enough!', 1, FORMAT_HTML); }
public function test_false_right_does_not_show_feedback_when_not_answered() { // Create a true-false question with correct answer false. $tf = test_question_maker::make_question('truefalse', 'false'); $this->start_attempt_at_question($tf, 'deferredfeedback', 1); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_question_text_expectation($tf), $this->get_does_not_contain_feedback_expectation(), new question_contains_tag_with_contents('h3', get_string('questiontext', 'question'))); $this->assertEquals(get_string('false', 'qtype_truefalse'), $this->quba->get_right_answer_summary($this->slot)); $this->assertRegExp('/' . preg_quote($tf->questiontext, '/') . '/', $this->quba->get_question_summary($this->slot)); $this->assertNull($this->quba->get_response_summary($this->slot)); // Finish the attempt without answering. $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gaveup); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_tf_true_radio_expectation(false, false), $this->get_contains_tf_false_radio_expectation(false, false), // In particular, check that the false feedback is not displayed. new question_no_pattern_expectation('/' . preg_quote($tf->falsefeedback, '/') . '/')); }
public function test_interactive() { // Create a gapselect question. $q = test_question_maker::make_question('calculated'); $q->hints = array(new question_hint(1, 'This is the first hint.', FORMAT_HTML), new question_hint(2, 'This is the second hint.', FORMAT_HTML)); $this->start_attempt_at_question($q, 'interactive', 3, 1); $values = $q->vs->get_values(); $this->assertEquals($values, $q->datasetloader->load_values(1)); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_validation_error_expectation(), $this->get_does_not_contain_try_again_button_expectation(), $this->get_no_hint_visible_expectation()); // Submit blank. $this->process_submission(array('-submit' => 1, 'answer' => '')); // Verify. $this->check_current_state(question_state::$invalid); $this->check_current_mark(null); $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_contains_validation_error_expectation(), $this->get_does_not_contain_try_again_button_expectation(), $this->get_no_hint_visible_expectation()); // Sumit something that does not look like a number. $this->process_submission(array('-submit' => 1, 'answer' => 'newt')); // Verify. $this->check_current_state(question_state::$invalid); $this->check_current_mark(null); $this->check_current_output($this->get_contains_marked_out_of_summary(), $this->get_contains_submit_button_expectation(true), $this->get_does_not_contain_feedback_expectation(), $this->get_contains_validation_error_expectation(), new question_pattern_expectation('/' . preg_quote(get_string('invalidnumber', 'qtype_numerical'), '/') . '/'), $this->get_does_not_contain_try_again_button_expectation(), $this->get_no_hint_visible_expectation()); // Now get it right. $this->process_submission(array('-submit' => 1, 'answer' => $values['a'] + $values['b'])); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(3); $this->check_current_output($this->get_contains_mark_summary(3), $this->get_does_not_contain_submit_button_expectation(), $this->get_contains_correct_expectation(), $this->get_does_not_contain_validation_error_expectation(), $this->get_no_hint_visible_expectation()); }
public function test_summarise_response() { $question = test_question_maker::make_question('multianswer'); $question->start_attempt(new question_attempt_step(), 1); $rightchoice = $question->subquestions[2]->get_correct_response(); $this->assertEqual(get_string('subqresponse', 'qtype_multianswer', array('i' => 1, 'response' => 'Owl')) . '; ' . get_string('subqresponse', 'qtype_multianswer', array('i' => 2, 'response' => 'Pussy-cat')), $question->summarise_response(array('sub1_answer' => 'Owl', 'sub2_answer' => reset($rightchoice)))); }
protected function setUp() { $this->question = test_question_maker::make_question('description'); $this->question->defaultmark = 3; $this->usageid = 13; $this->qa = new question_attempt($this->question, $this->usageid); }
/** * @return object the data to construct a question like * {@link qtype_gapselect_test_helper::make_a_gapselect_question()}. */ protected function get_test_question_data() { global $USER; $gapselect = new stdClass(); $gapselect->id = 0; $gapselect->category = 0; $gapselect->contextid = 0; $gapselect->parent = 0; $gapselect->questiontextformat = FORMAT_HTML; $gapselect->generalfeedbackformat = FORMAT_HTML; $gapselect->defaultmark = 1; $gapselect->penalty = 0.3333333; $gapselect->length = 1; $gapselect->stamp = make_unique_id_code(); $gapselect->version = make_unique_id_code(); $gapselect->hidden = 0; $gapselect->timecreated = time(); $gapselect->timemodified = time(); $gapselect->createdby = $USER->id; $gapselect->modifiedby = $USER->id; $gapselect->name = 'Selection from drop down list question'; $gapselect->questiontext = 'The [[1]] brown [[2]] jumped over the [[3]] dog.'; $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; $gapselect->qtype = 'gapselect'; $gapselect->options = new stdClass(); $gapselect->options->shuffleanswers = true; test_question_maker::set_standard_combined_feedback_fields($gapselect->options); $gapselect->options->answers = array((object) array('answer' => 'quick', 'feedback' => '1'), (object) array('answer' => 'fox', 'feedback' => '2'), (object) array('answer' => 'lazy', 'feedback' => '3'), (object) array('answer' => 'assiduous', 'feedback' => '3'), (object) array('answer' => 'dog', 'feedback' => '2'), (object) array('answer' => 'slow', 'feedback' => '1')); return $gapselect; }
protected function get_test_question_data() { global $USER; $q = new stdClass(); $q->id = 0; $q->name = 'Drag and drop matching question'; $q->category = 0; $q->contextid = 0; $q->parent = 0; $q->questiontext = 'Classify the animals.'; $q->questiontextformat = FORMAT_HTML; $q->generalfeedback = 'General feedback.'; $q->generalfeedbackformat = FORMAT_HTML; $q->defaultmark = 1; $q->penalty = 0.3333333; $q->length = 1; $q->stamp = make_unique_id_code(); $q->version = make_unique_id_code(); $q->hidden = 0; $q->timecreated = time(); $q->timemodified = time(); $q->createdby = $USER->id; $q->modifiedby = $USER->id; $q->options = new stdClass(); $q->options->shuffleanswers = false; test_question_maker::set_standard_combined_feedback_fields($q->options); $q->options->subquestions = array(14 => (object) array('id' => 14, 'questiontext' => 'frog', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'amphibian', 'answertextformat' => FORMAT_HTML), 15 => (object) array('id' => 15, 'questiontext' => 'cat', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'mammal', 'answertextformat' => FORMAT_HTML), 16 => (object) array('id' => 16, 'questiontext' => 'newt', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'amphibian', 'answertextformat' => FORMAT_HTML), 17 => (object) array('id' => 17, 'questiontext' => '', 'questiontextformat' => FORMAT_HTML, 'answertext' => 'insect', 'answertextformat' => FORMAT_HTML)); return $q; }
public function test_classify_response() { $tf = test_question_maker::make_question('truefalse', 'true'); $tf->start_attempt(new question_attempt_step(), 1); $this->assertEquals(array($tf->id => new question_classified_response(0, get_string('false', 'qtype_truefalse'), 0.0)), $tf->classify_response(array('answer' => '0'))); $this->assertEquals(array($tf->id => new question_classified_response(1, get_string('true', 'qtype_truefalse'), 1.0)), $tf->classify_response(array('answer' => '1'))); $this->assertEquals(array($tf->id => question_classified_response::no_response()), $tf->classify_response(array())); }
protected function setUp() { $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)); $this->qa->add_step($step); } }
public function make_question($question) { try { $q = test_question_maker::make_question('coderunner', $question); } catch (qtype_coderunner_missing_question_type $ex) { $this->markTestSkipped("{$question} question unavailable: test skipped"); } $q->contextid = $this->category->contextid; return $q; }
public function test_classify_response() { $question = test_question_maker::make_question('calculatedsimple'); $question->start_attempt(new question_attempt_step(), 1); $values = $question->vs->get_values(); $this->assertEquals(array(new question_classified_response(13, $values['a'] + $values['b'], 1.0)), $question->classify_response(array('answer' => $values['a'] + $values['b']))); $this->assertEquals(array(new question_classified_response(14, $values['a'] - $values['b'], 0.0)), $question->classify_response(array('answer' => $values['a'] - $values['b']))); $this->assertEquals(array(new question_classified_response(17, 7 * $values['a'], 0.0)), $question->classify_response(array('answer' => 7 * $values['a']))); $this->assertEquals(array(question_classified_response::no_response()), $question->classify_response(array('answer' => ''))); }
protected function setUp() { $this->quba = question_engine::make_questions_usage_by_activity('unit_test', context_system::instance()); $this->quba->set_preferred_behaviour('deferredfeedback'); $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')); $this->qas[$slot] = $this->quba->get_question_attempt($slot); $this->iterator = $this->quba->get_attempt_iterator(); }
public function setUp() { $this->quba = question_engine::make_questions_usage_by_activity('unit_test', get_context_instance(CONTEXT_SYSTEM)); $this->quba->set_preferred_behaviour('deferredfeedback'); $slot = $this->quba->add_question(test_question_maker::make_a_description_question()); $this->qas[$slot] = $this->quba->get_question_attempt($slot); $slot = $this->quba->add_question(test_question_maker::make_a_description_question()); $this->qas[$slot] = $this->quba->get_question_attempt($slot); $this->iterator = $this->quba->get_attempt_iterator(); }
protected function setUp() { $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)); $this->qa->add_step($step); } $this->iterator = $this->qa->get_step_iterator(); }
/** Make sure that if the Jobe URL is wrong we get "jobesandbox is down * or misconfigured" exception. * * @expectedException coderunner_exception * @expectedExceptionMessageRegExp |.*jobesandbox is down or misconfigured.*| * @retrun void */ public function test_misconfigured_jobe() { // if (!get_config('qtype_coderunner', 'jobesandbox_enabled')) { $this->markTestSkipped("Sandbox {$sandbox} unavailable: test skipped"); } set_config('jobe_host', 'localhostxxx', 'qtype_coderunner'); // Broken jobe_host url $q = test_question_maker::make_question('coderunner', 'sqr'); $this->start_attempt_at_question($q, 'adaptive', 1, 1); }
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()); $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, new qubaid_list(array()))); $this->assertEquals($quba->get_variant($slot1), $quba->get_variant($slot2)); }
public function test_informationitem_feedback_description() { // Create a description question. $description = test_question_maker::make_question('description'); $this->start_attempt_at_question($description, 'deferredfeedback'); // Check the initial state. $this->assertEquals('informationitem', $this->quba->get_question_attempt($this->slot)->get_behaviour_name()); $this->check_current_output(new question_contains_tag_with_contents('h4', get_string('informationtext', 'qtype_description'))); // Further tests of the description qtype are in // question/behaviour/informationitem/tests/testwalkthrough.php. }
public function test_is_complete_response() { $essay = test_question_maker::make_an_essay_question(); $essay->start_attempt(new question_attempt_step(), 1); // The empty string should be considered an empty response, as should a lack of a response. $this->assertFalse($essay->is_complete_response(array('answer' => ''))); $this->assertFalse($essay->is_complete_response(array())); // Any nonempty string should be considered a complete response. $this->assertTrue($essay->is_complete_response(array('answer' => 'A student response.'))); $this->assertTrue($essay->is_complete_response(array('answer' => '0 times.'))); $this->assertTrue($essay->is_complete_response(array('answer' => '0'))); }
/** * Create a new question. The question is initialised using one of the * examples from the appropriate {@link question_test_helper} subclass. * Then, any files you want to change from the value in the base example you * can override using $overrides. * @param string $qtype the question type to create an example of. * @param string $which as for the corresponding argument of * {@link question_test_helper::get_question_form_data}. null for the default one. * @param array|stdClass $overrides any fields that should be different from the base example. */ public function create_question($qtype, $which = null, $overrides = null) { global $CFG; require_once $CFG->dirroot . '/question/engine/tests/helpers.php'; $fromform = test_question_maker::get_question_form_data($qtype, $which); $fromform = (object) $this->datagenerator->combine_defaults_and_record((array) $fromform, $overrides); $question = new stdClass(); $question->category = $fromform->category; $question->qtype = $qtype; $question->createdby = 0; return question_bank::get_qtype($qtype)->save_question($question, $fromform); }
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(); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p>')); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog<br /></p>')); $this->assertEquals('Frog<br />Toad', $mc->make_html_inline("<p>Frog</p>\n<p>Toad</p>")); $this->assertEquals('<img src="http://example.com/pic.png" alt="Graph" />', $mc->make_html_inline('<p><img src="http://example.com/pic.png" alt="Graph" /></p>')); $this->assertEquals("Frog<br />XXX <img src='http://example.com/pic.png' alt='Graph' />", $mc->make_html_inline(" <p> Frog </p> \n\r\n <p> XXX <img src='http://example.com/pic.png' alt='Graph' /> </p> ")); $this->assertEquals('Frog', $mc->make_html_inline('<p>Frog</p><p></p>')); $this->assertEquals('Frog<br />†', $mc->make_html_inline('<p>Frog</p><p>†</p>')); }
public function test_deferredfeedback_feedback_multichoice_multi() { // Create a multichoice, multi question. $mc = test_question_maker::make_a_multichoice_multi_question(); $mc->shuffleanswers = false; $this->start_attempt_at_question($mc, 'deferredfeedback', 2); $this->process_submission($mc->get_correct_response()); $this->quba->finish_all_questions(); // Verify. $this->check_current_state(question_state::$gradedright); $this->check_current_mark(2); $this->check_current_output($this->get_contains_mc_checkbox_expectation('choice0', false, true), $this->get_contains_mc_checkbox_expectation('choice1', false, false), $this->get_contains_mc_checkbox_expectation('choice2', false, true), $this->get_contains_mc_checkbox_expectation('choice3', false, false), $this->get_contains_correct_expectation(), new question_pattern_expectation('/class="r0 correct"/'), new question_pattern_expectation('/class="r1"/')); }
/** * @return qtype_linkerdesc_question */ public static function make_linkerdesc_question_info() { question_bank::load_question_definition_classes('linkerdesc'); $q = new qtype_linkerdesc_question(); test_question_maker::initialise_a_question($q); $q->defaultmark = 0; $q->penalty = 0; $q->length = 0; $q->name = 'Description'; $q->questiontext = 'Here is some information about the questions you are about to attempt.'; $q->generalfeedback = 'And here is some more text shown only on the review page.'; $q->qtype = question_bank::get_qtype('linkerdesc'); return $q; }
public function test_deferred_feedback() { // Create a gapselect question. $q = test_question_maker::make_question('multianswer', 'fourmc'); $this->start_attempt_at_question($q, 'deferredfeedback', 4); // Check the initial state. $this->check_current_state(question_state::$todo); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_marked_out_of_summary(), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_validation_error_expectation()); // Save in incomplete answer. $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '', 'sub3_answer' => '', 'sub4_answer' => '')); // Verify. $this->check_current_state(question_state::$invalid); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_marked_out_of_summary(), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_validation_error_expectation()); // TODO, really, it should. See MDL-32049. // Save a partially correct answer. $this->process_submission(array('sub1_answer' => '1', 'sub2_answer' => '1', 'sub3_answer' => '1', 'sub4_answer' => '1')); // Verify. $this->check_current_state(question_state::$complete); $this->check_current_mark(null); $this->check_current_output( $this->get_contains_marked_out_of_summary(), $this->get_does_not_contain_feedback_expectation(), $this->get_does_not_contain_validation_error_expectation()); // Now submit all and finish. $this->process_submission(array('-finish' => 1)); // Verify. $this->check_current_state(question_state::$gradedpartial); $this->check_current_mark(2); $this->check_current_output( $this->get_contains_mark_summary(2), $this->get_contains_partcorrect_expectation(), $this->get_does_not_contain_validation_error_expectation()); }
/** * Makes a match question about completing two blanks in some text. * @return object the question definition data, as it might be returned from * the question editing form. */ public function get_match_question_form_data_foursubq() { $q = new stdClass(); $q->name = 'Matching question'; $q->questiontext = array('text' => 'Classify the animals.', 'format' => FORMAT_HTML); $q->generalfeedback = array('text' => 'General feedback.', 'format' => FORMAT_HTML); $q->defaultmark = 1; $q->penalty = 0.3333333; $q->shuffleanswers = 1; test_question_maker::set_standard_combined_feedback_form_data($q); $q->subquestions = array(0 => array('text' => 'frog', 'format' => FORMAT_HTML), 1 => array('text' => 'cat', 'format' => FORMAT_HTML), 2 => array('text' => 'newt', 'format' => FORMAT_HTML), 3 => array('text' => '', 'format' => FORMAT_HTML)); $q->subanswers = array(0 => 'amphibian', 1 => 'mammal', 2 => 'amphibian', 3 => 'insect'); $q->noanswers = 4; return $q; }
/** * Makes a multichoice all or nothing question with choices 'A', 'B', 'C' and 'D' shuffled. * 'A' and 'C' is correct, defaultmark 1. * @return qtype_multichoiceset_question */ public static function make_a_multichoiceset_question() { question_bank::load_question_definition_classes('multichoiceset'); $mc = new qtype_multichoiceset_question(); test_question_maker::initialise_a_question($mc); $mc->name = 'Multi-choice all or nothing question'; $mc->questiontext = 'The answer is A and C.'; $mc->generalfeedback = 'You should have selected A and C.'; $mc->qtype = question_bank::get_qtype('multichoiceset'); $mc->shuffleanswers = 1; $mc->answernumbering = 'abc'; test_question_maker::set_standard_combined_feedback_fields($mc); $mc->answers = array(13 => new question_answer(13, 'A', 0.5, 'A is part of the right answer', FORMAT_HTML), 14 => new question_answer(14, 'B', 0, 'B is wrong', FORMAT_HTML), 15 => new question_answer(15, 'C', 0.5, 'C is part of the right answer', FORMAT_HTML), 16 => new question_answer(16, 'D', 0, 'D is wrong', FORMAT_HTML)); return $mc; }
/** * Helper method to reduce duplication. * @return qtype_essay_question */ protected function initialise_essay_question() { question_bank::load_question_definition_classes('essay'); $q = new qtype_essay_question(); test_question_maker::initialise_a_question($q); $q->name = 'Essay question (HTML editor)'; $q->questiontext = 'Please write a story about a frog.'; $q->generalfeedback = 'I hope your story had a beginning, a middle and an end.'; $q->responseformat = 'editor'; $q->responsefieldlines = 10; $q->attachments = 0; $q->graderinfo = ''; $q->graderinfoformat = FORMAT_HTML; $q->qtype = question_bank::get_qtype('essay'); return $q; }
/** * @return qtype_gapselect_question */ public static function make_a_maths_gapselect_question() { question_bank::load_question_definition_classes('gapselect'); $gapselect = new qtype_gapselect_question(); test_question_maker::initialise_a_question($gapselect); $gapselect->name = 'Selection from drop down list question'; $gapselect->questiontext = 'Fill in the operators to make this equation work: ' . '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3'; $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; $gapselect->qtype = question_bank::get_qtype('gapselect'); $gapselect->shufflechoices = true; test_question_maker::set_standard_combined_feedback_fields($gapselect); $gapselect->choices = array(1 => array(1 => new qtype_gapselect_choice('+', 1, true), 2 => new qtype_gapselect_choice('-', 1, true), 3 => new qtype_gapselect_choice('*', 1, true), 4 => new qtype_gapselect_choice('/', 1, true))); $gapselect->places = array(1 => 1, 2 => 1, 3 => 1, 4 => 1); $gapselect->rightchoices = array(1 => 1, 2 => 2, 3 => 1, 4 => 2); $gapselect->textfragments = array('7 ', ' 11 ', ' 13 ', ' 17 ', ' 19 = 3'); return $gapselect; }