|
|
|
@@ -16,6 +16,7 @@
|
|
|
|
|
|
|
|
|
|
namespace qformat_gift;
|
|
|
|
|
|
|
|
|
|
use phpunit_util;
|
|
|
|
|
use qformat_gift;
|
|
|
|
|
use question_bank;
|
|
|
|
|
use question_check_specified_fields_expectation;
|
|
|
|
@@ -37,15 +38,17 @@ require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
|
|
|
|
|
*/
|
|
|
|
|
class giftformat_test extends \question_testcase {
|
|
|
|
|
public function assert_same_gift($expectedtext, $text) {
|
|
|
|
|
$this->assertEquals(str_replace("\r\n", "\n", $expectedtext),
|
|
|
|
|
str_replace("\r\n", "\n", $text));
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
phpunit_util::normalise_line_endings($expectedtext),
|
|
|
|
|
phpunit_util::normalise_line_endings($text)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function test_import_essay() {
|
|
|
|
|
$gift = '
|
|
|
|
|
// essay
|
|
|
|
|
::Q8:: How are you? {}';
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -114,7 +117,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
=[markdown]A collection of web pages that anyone can add to or edit. -> Wiki
|
|
|
|
|
= -> Chat
|
|
|
|
|
}';
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -284,7 +287,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
~red # [html]wrong, it's yellow
|
|
|
|
|
~[plain]blue # wrong, it's yellow
|
|
|
|
|
}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -387,7 +390,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
~%50%off-beige # right; good!
|
|
|
|
|
~%-100%[plain]blue # wrong
|
|
|
|
|
}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -482,7 +485,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
~%-50%red # wrong
|
|
|
|
|
~%-50%blue # wrong
|
|
|
|
|
}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -694,7 +697,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
$gift = "
|
|
|
|
|
// math range question
|
|
|
|
|
::Q5:: What is a number from 1 to 5? {#3:2~#Completely wrong}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -800,7 +803,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
=%50%Cat#What is it with Moodlers and cats?
|
|
|
|
|
=%0%*#Completely wrong
|
|
|
|
|
}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -856,7 +859,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
=%0%*#Completely wrong
|
|
|
|
|
####[html]Here is some general feedback!
|
|
|
|
|
}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1029,7 +1032,7 @@ class giftformat_test extends \question_testcase {
|
|
|
|
|
// true/false
|
|
|
|
|
::Q1:: 42 is the Absolute Answer to everything.{
|
|
|
|
|
FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1063,7 +1066,7 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
public function test_import_truefalse_true_answer1() {
|
|
|
|
|
$gift = "// name 0-11
|
|
|
|
|
::2-08 TSL::TSL is blablabla.{T}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1097,7 +1100,7 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
public function test_import_truefalse_true_answer2() {
|
|
|
|
|
$gift = "// name 0-11
|
|
|
|
|
::2-08 TSL::TSL is blablabla.{TRUE}";
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1219,7 +1222,7 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
$gift = '
|
|
|
|
|
// essay
|
|
|
|
|
::double backslash:: A \\\\ B \\\\\\\\ C{}';
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1257,7 +1260,7 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
\}
|
|
|
|
|
</pre>
|
|
|
|
|
{}';
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
@@ -1296,7 +1299,7 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
|
|
|
|
|
// This question is to test importing tags: [tag:tag] [tag:other-tag].
|
|
|
|
|
// And an idnumber: [id:myid].
|
|
|
|
|
::Question name:: How are you? {}';
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
|
|
|
|
|
$lines = preg_split('/[\\n\\r]/', phpunit_util::normalise_line_endings($gift));
|
|
|
|
|
|
|
|
|
|
$importer = new qformat_gift();
|
|
|
|
|
$q = $importer->readquestion($lines);
|
|
|
|
|