当前位置: 首页>>代码示例>>PHP>>正文


PHP test_question_maker::get_question_form_data方法代码示例

本文整理汇总了PHP中test_question_maker::get_question_form_data方法的典型用法代码示例。如果您正苦于以下问题:PHP test_question_maker::get_question_form_data方法的具体用法?PHP test_question_maker::get_question_form_data怎么用?PHP test_question_maker::get_question_form_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test_question_maker的用法示例。


在下文中一共展示了test_question_maker::get_question_form_data方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create_question

 /**
  * 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);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:22,代码来源:lib.php

示例2: test_question_saving_sumwithvariants

 public function test_question_saving_sumwithvariants()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('calculatedsimple', 'sumwithvariants');
     $formdata = test_question_maker::get_question_form_data('calculatedsimple', 'sumwithvariants');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     qtype_calculatedsimple_edit_form::mock_submit((array) $formdata);
     $form = qtype_calculatedsimple_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     foreach ($questiondata as $property => $value) {
         if (!in_array($property, array('id', 'version', 'timemodified', 'timecreated', 'options'))) {
             $this->assertAttributeEquals($value, $property, $actualquestiondata);
         }
     }
     foreach ($questiondata->options as $optionname => $value) {
         if ($optionname != 'answers') {
             $this->assertAttributeEquals($value, $optionname, $actualquestiondata->options);
         }
     }
     foreach ($questiondata->options->answers as $answer) {
         $actualanswer = array_shift($actualquestiondata->options->answers);
         foreach ($answer as $ansproperty => $ansvalue) {
             if (!in_array($ansproperty, array('id', 'question', 'answerformat'))) {
                 $this->assertAttributeEquals($ansvalue, $ansproperty, $actualanswer);
             }
         }
     }
     $datasetloader = new qtype_calculated_dataset_loader($actualquestiondata->id);
     $this->assertEquals(10, $datasetloader->get_number_of_items());
     for ($itemno = 1; $itemno <= 10; $itemno++) {
         $item = $datasetloader->get_values($itemno);
         $this->assertEquals($formdata->number[($itemno - 1) * 2 + 2], $item['a']);
         $this->assertEquals($formdata->number[($itemno - 1) * 2 + 1], $item['b']);
     }
 }
开发者ID:pzhu2004,项目名称:moodle,代码行数:42,代码来源:questiontype_test.php

示例3: test_question_saving_true

 public function test_question_saving_true()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('truefalse');
     $formdata = test_question_maker::get_question_form_data('truefalse');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     qtype_truefalse_edit_form::mock_submit((array) $formdata);
     $form = qtype_truefalse_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     foreach ($questiondata as $property => $value) {
         if (!in_array($property, array('options'))) {
             $this->assertAttributeEquals($value, $property, $actualquestiondata);
         }
     }
     foreach ($questiondata->options as $optionname => $value) {
         if (!in_array($optionname, array('trueanswer', 'falseanswer', 'answers'))) {
             $this->assertAttributeEquals($value, $optionname, $actualquestiondata->options);
         }
     }
     $answerindexes = array();
     foreach ($questiondata->options->answers as $ansindex => $answer) {
         $actualanswer = array_shift($actualquestiondata->options->answers);
         foreach ($answer as $ansproperty => $ansvalue) {
             // This question does not use 'answerformat', will ignore it.
             if (!in_array($ansproperty, array('id', 'question', 'answerformat'))) {
                 $this->assertAttributeEquals($ansvalue, $ansproperty, $actualanswer);
             }
         }
         $answerindexes[$answer->answer] = $ansindex;
     }
     $this->assertEquals($questiondata->options->trueanswer, $answerindexes['True']);
     $this->assertEquals($questiondata->options->falseanswer, $answerindexes['False']);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:40,代码来源:questiontype_test.php

示例4: test_question_saving

 public function test_question_saving()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('linkerdesc');
     $formdata = test_question_maker::get_question_form_data('linkerdesc');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     qtype_linkerdesc_edit_form::mock_submit((array) $formdata);
     $form = qtype_linkerdesc_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     foreach ($questiondata as $property => $value) {
         if (!in_array($property, array('id', 'version', 'timemodified', 'timecreated'))) {
             $this->assertAttributeEquals($value, $property, $actualquestiondata);
         }
     }
 }
开发者ID:fontinixxl,项目名称:moodle-qtype_linkerdesc,代码行数:22,代码来源:questiontype_test.php

示例5: test_question_saving_twosubq

 public function test_question_saving_twosubq()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('multianswer');
     $formdata = test_question_maker::get_question_form_data('multianswer');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     qtype_multianswer_edit_form::mock_submit((array) $formdata);
     $form = qtype_multianswer_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     foreach ($questiondata as $property => $value) {
         if (!in_array($property, array('id', 'version', 'timemodified', 'timecreated', 'options', 'hints', 'stamp'))) {
             $this->assertAttributeEquals($value, $property, $actualquestiondata);
         }
     }
     foreach ($questiondata->options as $optionname => $value) {
         if ($optionname != 'questions') {
             $this->assertAttributeEquals($value, $optionname, $actualquestiondata->options);
         }
     }
     foreach ($questiondata->hints as $hint) {
         $actualhint = array_shift($actualquestiondata->hints);
         foreach ($hint as $property => $value) {
             if (!in_array($property, array('id', 'questionid', 'options'))) {
                 $this->assertAttributeEquals($value, $property, $actualhint);
             }
         }
     }
     $this->assertObjectHasAttribute('questions', $actualquestiondata->options);
     $subqpropstoignore = array('id', 'category', 'parent', 'contextid', 'question', 'options', 'stamp', 'version', 'timemodified', 'timecreated');
     foreach ($questiondata->options->questions as $subqno => $subq) {
         $actualsubq = $actualquestiondata->options->questions[$subqno];
         foreach ($subq as $subqproperty => $subqvalue) {
             if (!in_array($subqproperty, $subqpropstoignore)) {
                 $this->assertAttributeEquals($subqvalue, $subqproperty, $actualsubq);
             }
         }
         foreach ($subq->options as $optionname => $value) {
             if (!in_array($optionname, array('answers'))) {
                 $this->assertAttributeEquals($value, $optionname, $actualsubq->options);
             }
         }
         foreach ($subq->options->answers as $answer) {
             $actualanswer = array_shift($actualsubq->options->answers);
             foreach ($answer as $ansproperty => $ansvalue) {
                 // These questions do not use 'answerformat', will ignore it.
                 if (!in_array($ansproperty, array('id', 'question', 'answerformat'))) {
                     $this->assertAttributeEquals($ansvalue, $ansproperty, $actualanswer);
                 }
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:59,代码来源:questiontype_test.php

示例6: test_question_saving_trims_answers

 public function test_question_saving_trims_answers()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('shortanswer');
     $formdata = test_question_maker::get_question_form_data('shortanswer');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     $formdata->answer[0] = '   frog   ';
     qtype_shortanswer_edit_form::mock_submit((array) $formdata);
     $form = qtype_shortanswer_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     $firstsavedanswer = reset($questiondata->options->answers);
     $this->assertEquals('frog', $firstsavedanswer->answer);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:questiontype_test.php

示例7: test_question_saving_foursubq

 public function test_question_saving_foursubq()
 {
     $this->resetAfterTest(true);
     $this->setAdminUser();
     $questiondata = test_question_maker::get_question_data('match');
     $formdata = test_question_maker::get_question_form_data('match');
     $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
     $cat = $generator->create_question_category(array());
     $formdata->category = "{$cat->id},{$cat->contextid}";
     qtype_match_edit_form::mock_submit((array) $formdata);
     $form = qtype_match_test_helper::get_question_editing_form($cat, $questiondata);
     $this->assertTrue($form->is_validated());
     $fromform = $form->get_data();
     $returnedfromsave = $this->qtype->save_question($questiondata, $fromform);
     $actualquestionsdata = question_load_questions(array($returnedfromsave->id));
     $actualquestiondata = end($actualquestionsdata);
     foreach ($questiondata as $property => $value) {
         if (!in_array($property, array('id', 'version', 'timemodified', 'timecreated', 'options', 'stamp'))) {
             $this->assertAttributeEquals($value, $property, $actualquestiondata);
         }
     }
     foreach ($questiondata->options as $optionname => $value) {
         if ($optionname != 'subquestions') {
             $this->assertAttributeEquals($value, $optionname, $actualquestiondata->options);
         }
     }
     $this->assertObjectHasAttribute('subquestions', $actualquestiondata->options);
     $subqpropstoignore = array('id');
     foreach ($questiondata->options->subquestions as $subq) {
         $actualsubq = array_shift($actualquestiondata->options->subquestions);
         foreach ($subq as $subqproperty => $subqvalue) {
             if (!in_array($subqproperty, $subqpropstoignore)) {
                 $this->assertAttributeEquals($subqvalue, $subqproperty, $actualsubq);
             }
         }
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:37,代码来源:questiontype_test.php


注:本文中的test_question_maker::get_question_form_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。