Merge branch 'MDL-46331' of git://github.com/timhunt/moodle

This commit is contained in:
Dan Poltawski 2014-09-15 11:55:16 +01:00
commit d1c9b792b0
3 changed files with 76 additions and 1 deletions

View File

@ -175,7 +175,7 @@ class qformat_gift extends qformat_default {
}
}
$text = trim(implode(' ', $lines));
$text = trim(implode("\n", $lines));
if ($text == '') {
return false;

View File

@ -0,0 +1,30 @@
@qtype @qformat_gift
Feature: Test importing questions from GIFT format.
In order to reuse questions
As an teacher
I need to be able to import them in GIFT format.
Background:
Given the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "users" exist:
| username | firstname |
| teacher | Teacher |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
And I log in as "teacher"
And I follow "Course 1"
@javascript @_file_upload
Scenario: import some GIFT questions
When I navigate to "Import" node in "Course administration > Question bank"
And I set the field "id_format_gift" to "1"
And I upload "question/format/gift/tests/fixtures/questions.gift.txt" file to "Import" filemanager
And I press "id_submitbutton"
Then I should see "Parsing questions from import file."
And I should see "Importing 9 questions from file"
And I should see "What's between orange and green in the spectrum?"
When I press "Continue"
Then I should see "colours"

View File

@ -1070,4 +1070,49 @@ FALSE#42 is the Ultimate Answer.#You gave the right answer.}";
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
public function test_import_pre_content() {
$gift = '
::Q001::[html]<p>What would running the test method print?</p>
<pre>
public void test() \{
method1();
method2();
method3();
\}
</pre>
{}';
$lines = preg_split('/[\\n\\r]/', str_replace("\r\n", "\n", $gift));
$importer = new qformat_gift();
$q = $importer->readquestion($lines);
$expectedq = (object) array(
'name' => 'Q001',
'questiontext' => '<p>What would running the test method print?</p>
<pre>
public void test() {
method1();
method2();
method3();
}
</pre>',
'questiontextformat' => FORMAT_HTML,
'generalfeedback' => '',
'generalfeedbackformat' => FORMAT_HTML,
'qtype' => 'essay',
'defaultmark' => 1,
'penalty' => 0.3333333,
'length' => 1,
'responseformat' => 'editor',
'responsefieldlines' => 15,
'attachments' => 0,
'graderinfo' => array(
'text' => '',
'format' => FORMAT_HTML,
'files' => array()),
);
$this->assert(new question_check_specified_fields_expectation($expectedq), $q);
}
}