Ejemplo n.º 1
0
    public function test_export_truefalse() {
        $qdata = (object) array(
            'id' => 666 ,
            'name' => 'Q1',
            'questiontext' => "42 is the Absolute Answer to everything.",
            'questiontextformat' => FORMAT_MOODLE,
            'generalfeedback' => '',
            'generalfeedbackformat' => FORMAT_MOODLE,
            'defaultmark' => 1,
            'penalty' => 1,
            'length' => 1,
            'qtype' => 'truefalse',
            'options' => (object) array(
                'id' => 123,
                'question' => 666,
                'trueanswer' => 1,
                'falseanswer' => 2,
                'answers' => array(
                    1 => (object) array(
                        'id' => 123,
                        'answer' => 'True',
                        'answerformat' => 0,
                        'fraction' => 1,
                        'feedback' => 'You gave the right answer.',
                        'feedbackformat' => FORMAT_MOODLE,
                    ),
                    2 => (object) array(
                        'id' => 124,
                        'answer' => 'False',
                        'answerformat' => 0,
                        'fraction' => 0,
                        'feedback' => "42 is the Ultimate Answer.",
                        'feedbackformat' => FORMAT_HTML,
                    ),
                ),
            ),
        );

        $exporter = new qformat_gift();
        $gift = $exporter->writequestion($qdata);

        $expectedgift = "// question: 666  name: Q1
::Q1::42 is the Absolute Answer to everything.{TRUE#[html]42 is the Ultimate Answer.#You gave the right answer.}

";

        $this->assert_same_gift($expectedgift, $gift);
    }
 public function test_export_backslash()
 {
     // There was a bug (MDL-34171) where \\ was getting exported as \\, not
     // \\\\, and on import, \\ in converted to \.
     // We need \\\\ in the test code, because of PHPs string escaping rules.
     $qdata = (object) array('id' => 666, 'name' => 'backslash', 'questiontext' => 'A \\ B \\\\ C', 'questiontextformat' => FORMAT_MOODLE, 'generalfeedback' => '', 'generalfeedbackformat' => FORMAT_MOODLE, 'defaultmark' => 1, 'penalty' => 0.3333333, 'length' => 1, 'qtype' => 'essay', 'options' => (object) array('responseformat' => 'editor', 'responsefieldlines' => 15, 'attachments' => 0, 'graderinfo' => '', 'graderinfoformat' => FORMAT_HTML));
     $exporter = new qformat_gift();
     $gift = $exporter->writequestion($qdata);
     $expectedgift = "// question: 666  name: backslash\n::backslash::A \\\\ B \\\\\\\\ C{}\n\n";
     $this->assert_same_gift($expectedgift, $gift);
 }
Ejemplo n.º 3
0
 function export_quest($quest_list, $file_format)
 {
     $quest_export = '';
     switch ($file_format) {
         case 0:
             // gift format -------------------
             require_once $GLOBALS['where_lms'] . '/modules/question/format.gift.php';
             $qgift = new qformat_gift();
             while (list($id_quest, $type_quest) = each($quest_list)) {
                 $oQuest = $this->instanceQuestType($id_quest, $type_quest);
                 if ($oQuest) {
                     $oRawQuest = $oQuest->exportToRaw($id_quest);
                     $quest_export .= $qgift->writequestion($oRawQuest);
                 } else {
                     die($type_quest);
                 }
             }
             break;
         case 1:
             // xml moodle format -------------
             break;
     }
     return $quest_export;
 }