MDL-30001 WEBCT Import does not work for 2.0

This commit is contained in:
Jean-Michel Vedrine
2013-08-11 08:06:13 +02:00
parent ea3f5b5d95
commit 390cb87e76
6 changed files with 920 additions and 238 deletions
-7
View File
@@ -1,7 +0,0 @@
- Ajouter un espace aprs un symbole <= s'il prfixe une parenthse ouvrante.
- Grer 'and', 'or', ... comme &&, ||
- Ne pas mettre de '$' sur les @param si aucun nom de variable n'esp spcifi.
- Ajouter OneTrueBrace pour les if, while, for, else ... (Gustavo Carreno <[email protected]>, Richard Bateman <[email protected]>, Yaroslav Shvetsov <[email protected]>, Chris Small <[email protected]>)
- Remove blank lines (Sergio Marchesini <[email protected]>)
- Forcer une ligne vide aprs une dclaration de fonction (Richard Bateman <[email protected]>)
File diff suppressed because it is too large Load Diff
@@ -17,8 +17,7 @@
/**
* Strings for component 'qformat_webct', language 'en', branch 'MOODLE_20_STABLE'
*
* @package qformat
* @subpackage webct
* @package qformat_webct
* @copyright 2010 Helen Foster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -31,6 +30,6 @@ $string['pluginname'] = 'WebCT format';
$string['pluginname_help'] = 'WebCT format enables multiple-choice and short answer questions saved in WebCT\'s text-based format to be imported.';
$string['pluginname_link'] = 'qformat/webct';
$string['questionnametoolong'] = 'Question name too long at line {$a} (255 char. max). It has been truncated.';
$string['unknowntype'] = 'Unknown type';
$string['unknowntype'] = 'Unknown question type after line {$a}';
$string['warningsdetected'] = '{$a} warning(s) detected';
$string['wronggrade'] = 'Wrong grade (after line {$a}) :';
+117
View File
@@ -0,0 +1,117 @@
# Start of question:Question 001
:TYPE:MC:1:0:A
:TITLE:USER-1
:QUESTION:H
42 is the Absolute Answer to everything.
:LAYOUT:horizontal
:ANSWERORDER:randomized
:INDICES:letters
:ANSWER1:0:H
True
:REASON1:H
42 is the <b>Ultimate</b> Answer.
:ANSWER2:100:H
False
:REASON2:H
42 is the <b>Ultimate</b> Answer.
:CAT:webct
:ASSESSMENT:Test
# End of question:Question 001
# Start of question:Question 002
:TYPE:MC:1:0:A
:TITLE:USER-2
:QUESTION:H
<font size="+1">What's between orange and green in the spectrum?</font>
:LAYOUT:horizontal
:ANSWERORDER:randomized
:INDICES:letters
:ANSWER1:0:H
red
:REASON1:H
Red is not between orange and green in the spectrum but yellow is.
:ANSWER2:100:H
yellow
:REASON2:H
You gave the right answer.
:ANSWER3:0:H
blue
:REASON3:H
Blue is not between orange and green in the spectrum but yellow is.
:CAT:webct
:ASSESSMENT:Test
# End of question:Question 002
# Start of question:Question 003
:TYPE:MC:N:0:A
:TITLE:USER-3
:QUESTION:H
<i>What's between orange and green in the spectrum?</i>
:LAYOUT:horizontal
:ANSWERORDER:randomized
:INDICES:letters
:ANSWER1:50:H
yellow
:REASON1:H
True, yellow is between orange and green in the spectrum,
:ANSWER2:0:H
red
:REASON2:H
False, red is not between orange and green in the spectrum,
:ANSWER3:50:H
off-beige
:REASON3:H
True, off-beige is between orange and green in the spectrum,
:ANSWER4:0:H
blue
:REASON4:H
False, red is not between orange and green in the spectrum,
:CAT:webct
:ASSESSMENT:Test
# End of question:Question 003
# Start of question:Question 004
:TYPE:M:short:short:E:0
:TITLE:Classify the animals.
:QUESTION:H
<i>Classify the animals.</i>
:IMAGE:
:L1
cat
:R1
mammal
:L2
frog
:R2
amphibian
:L3
newt
:R3
amphibian
:CAT:Ch 00 Instr Test Items
:ASSESSMENT:Test
# End of question:Question 004
# Start of question:Question 005
:TYPE:S
:TITLE:USER-5
:QUESTION:H
Name an amphibian&#58; __________
:ANSWERS:1
:ANSWER1:frog:100:0:20:0
:FEEDBACK1:H
A frog is an amphibian
:CAT:webct
:ASSESSMENT:Test
# End of question:Question 005
# Start of question:Question 006
:TYPE:P
:TITLE:USER-6
:QUESTION:H:60:5
How are you?
:ANSWER:H
Blackboard answer for essay questions will be imported as informations for graders.
:CAT:webct
:ASSESSMENT:Test
# End of question:Question 006
@@ -0,0 +1,366 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Unit tests for Web CT question importer.
*
* @package qformat_webct
* @copyright 2013 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format.php');
require_once($CFG->dirroot . '/question/format/webct/format.php');
require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
/**
* Unit tests for the webct question import format.
*
* @copyright 2013 Jean-Michel Vedrine
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class qformat_webct_test extends question_testcase {
public function make_test() {
$lines = file(__DIR__ . '/fixtures/sample_webct.txt');
return $lines;
}
public function test_import_match() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[3];
$expectedq = new stdClass();
$expectedq->qtype = 'match';
$expectedq->name = 'Classify the animals.';
$expectedq->questiontext = '<i>Classify the animals.</i>';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->partiallycorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->incorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->subquestions = array(
1 => array('text' => 'cat', 'format' => FORMAT_HTML),
2 => array('text' => 'frog', 'format' => FORMAT_HTML),
3 => array('text' => 'newt', 'format' => FORMAT_HTML));
$expectedq->subanswers = array(1 => 'mammal', 2 => 'amphibian', 3 => 'amphibian');
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_multichoice_single() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[1];
$expectedq = new stdClass();
$expectedq->qtype = 'multichoice';
$expectedq->single = 1;
$expectedq->name = 'USER-2';
$expectedq->questiontext = '<font size="+1">What\'s between orange and green in the spectrum?</font>';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->partiallycorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->incorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->answer = array(
1 => array(
'text' => 'red',
'format' => FORMAT_HTML,
),
2 => array(
'text' => 'yellow',
'format' => FORMAT_HTML,
),
3 => array(
'text' => 'blue',
'format' => FORMAT_HTML,
)
);
$expectedq->fraction = array(
1 => 0,
2 => 1,
3 => 0,
);
$expectedq->feedback = array(
1 => array(
'text' => 'Red is not between orange and green in the spectrum but yellow is.',
'format' => FORMAT_HTML,
),
2 => array(
'text' => 'You gave the right answer.',
'format' => FORMAT_HTML,
),
3 => array(
'text' => 'Blue is not between orange and green in the spectrum but yellow is.',
'format' => FORMAT_HTML,
)
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_multichoice_multi() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[2];
$expectedq = new stdClass();
$expectedq->qtype = 'multichoice';
$expectedq->single = 0;
$expectedq->name = 'USER-3';
$expectedq->questiontext = '<i>What\'s between orange and green in the spectrum?</i>';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->partiallycorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->incorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->penalty = 0.3333333;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->answer = array(
1 => array(
'text' => 'yellow',
'format' => FORMAT_HTML,
),
2 => array(
'text' => 'red',
'format' => FORMAT_HTML,
),
3 => array(
'text' => 'off-beige',
'format' => FORMAT_HTML,
),
4 => array(
'text' => 'blue',
'format' => FORMAT_HTML,
)
);
$expectedq->fraction = array(
1 => 0.5,
2 => 0,
3 => 0.5,
4 => 0,
);
$expectedq->feedback = array(
1 => array(
'text' => 'True, yellow is between orange and green in the spectrum,',
'format' => FORMAT_HTML,
),
2 => array(
'text' => 'False, red is not between orange and green in the spectrum,',
'format' => FORMAT_HTML,
),
3 => array(
'text' => 'True, off-beige is between orange and green in the spectrum,',
'format' => FORMAT_HTML,
),
4 => array(
'text' => 'False, red is not between orange and green in the spectrum,',
'format' => FORMAT_HTML,
)
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_truefalse() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[0];
$expectedq = new stdClass();
$expectedq->qtype = 'multichoice';
$expectedq->single = 1;
$expectedq->name = 'USER-1';
$expectedq->questiontext = '42 is the Absolute Answer to everything.';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->correctfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->partiallycorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->incorrectfeedback = array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array(),
);
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_MOODLE;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->shuffleanswers = get_config('quiz', 'shuffleanswers');
$expectedq->answer = array(
1 => array(
'text' => 'True',
'format' => FORMAT_HTML,
),
2 => array(
'text' => 'False',
'format' => FORMAT_HTML,
),
);
$expectedq->fraction = array(
1 => 0,
2 => 1,
);
$expectedq->feedback = array(
1 => array(
'text' => '42 is the <b>Ultimate</b> Answer.',
'format' => FORMAT_HTML,
),
2 => array(
'text' => '42 is the <b>Ultimate</b> Answer.',
'format' => FORMAT_HTML,
),
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_fill_in_the_blank() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[4];
$expectedq = new stdClass();
$expectedq->qtype = 'shortanswer';
$expectedq->name = 'USER-5';
$expectedq->questiontext = 'Name an amphibian&#58; __________';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = 'A frog is an amphibian';
$expectedq->generalfeedbackformat = FORMAT_HTML;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->usecase = 0;
$expectedq->answer = array(
1 => 'frog',
);
$expectedq->fraction = array(
1 => 1,
);
$expectedq->feedback = array(
1 => array(
'text' => '',
'format' => FORMAT_HTML,
),
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_essay() {
$txt = $this->make_test();
$importer = new qformat_webct();
$questions = $importer->readquestions($txt);
$q = $questions[5];
$expectedq = new stdClass();
$expectedq->qtype = 'essay';
$expectedq->name = 'USER-6';
$expectedq->questiontext = 'How are you?';
$expectedq->questiontextformat = FORMAT_HTML;
$expectedq->generalfeedback = '';
$expectedq->generalfeedbackformat = FORMAT_HTML;
$expectedq->defaultmark = 1;
$expectedq->length = 1;
$expectedq->responseformat = 'editor';
$expectedq->responsefieldlines = 15;
$expectedq->attachments = 0;
$expectedq->graderinfo = array(
'text' => 'Blackboard answer for essay questions will be imported as informations for graders.',
'format' => FORMAT_HTML,
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
}
+3 -4
View File
@@ -15,10 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information for the calculated question type.
* Version information for the Web CT question import format.
*
* @package qformat
* @subpackage webct
* @package qformat_webct
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -26,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'qformat_webct';
$plugin->version = 2012112900;
$plugin->version = 2012112901;
$plugin->requires = 2012112900;