Skip to content

Commit

Permalink
Merge branch 'MDL-46331_26' of git://github.com/timhunt/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_26_STABLE
  • Loading branch information
danpoltawski committed Sep 15, 2014
2 parents 1c736ac + 3b5ff54 commit b4820a9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion question/format/gift/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function readquestion($lines) {
}
}

$text = trim(implode(' ', $lines));
$text = trim(implode("\n", $lines));

if ($text == '') {
return false;
Expand Down
30 changes: 30 additions & 0 deletions question/format/gift/tests/behat/import.feature
Original file line number Diff line number Diff line change
@@ -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"
45 changes: 45 additions & 0 deletions question/format/gift/tests/giftformat_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,49 @@ public function test_import_backslash() {

$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);
}
}

0 comments on commit b4820a9

Please sign in to comment.