From cb9af73037d3b3d2ca5aad57f3b49c75dcc98c1f Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Wed, 3 Dec 2014 10:37:05 +0100 Subject: [PATCH 1/2] MDL-48473 mod_lesson: fill in the blank shortanswer option --- mod/lesson/pagetypes/shortanswer.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/mod/lesson/pagetypes/shortanswer.php b/mod/lesson/pagetypes/shortanswer.php index 3b5c9a230db..e62dca3be02 100644 --- a/mod/lesson/pagetypes/shortanswer.php +++ b/mod/lesson/pagetypes/shortanswer.php @@ -350,21 +350,31 @@ class lesson_display_answer_form_shortanswer extends moodleform { } } + $placeholder = false; + if (preg_match('/_____+/', $contents, $matches)) { + $placeholder = $matches[0]; + $contentsparts = explode( $placeholder, $contents, 2); + $attrs['size'] = round(strlen($placeholder) * 1.1); + } + $mform->addElement('header', 'pageheader'); - - $mform->addElement('html', $OUTPUT->container($contents, 'contents')); - - $options = new stdClass; - $options->para = false; - $options->noclean = true; - $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'pageid'); $mform->setType('pageid', PARAM_INT); - $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), $attrs); + if ($placeholder) { + $contentsgroup = array(); + $contentsgroup[] = $mform->createElement('static', '', '', $contentsparts[0]); + $contentsgroup[] = $mform->createElement('text', 'answer', '', $attrs); + $contentsgroup[] = $mform->createElement('static', '', '', $contentsparts[1]); + $mform->addGroup($contentsgroup, '', '', '', false); + } else { + $mform->addElement('html', $OUTPUT->container($contents, 'contents')); + $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), $attrs); + + } $mform->setType('answer', PARAM_TEXT); if ($hasattempt) { From b63c745ec6ca154536e7a080aa7c47dbf835b2ba Mon Sep 17 00:00:00 2001 From: Jean-Michel Vedrine Date: Thu, 11 Dec 2014 21:39:34 +0100 Subject: [PATCH 2/2] MDL-48473 mod_lesson: test fill in the blank question --- .../import_fillintheblank_question.feature | 41 ++++++ .../fixtures/sample_blackboard_fib_qti.dat | 138 ++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 mod/lesson/tests/behat/import_fillintheblank_question.feature create mode 100644 mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat diff --git a/mod/lesson/tests/behat/import_fillintheblank_question.feature b/mod/lesson/tests/behat/import_fillintheblank_question.feature new file mode 100644 index 00000000000..78c4bec77ff --- /dev/null +++ b/mod/lesson/tests/behat/import_fillintheblank_question.feature @@ -0,0 +1,41 @@ +@mod @mod_lesson +Feature: In a lesson activity, teacher can import blackboard fill in the blank question + As a teacher + I need to import a fill in the blank question made in Blackboard in a lesson + + @javascript @_file_upload + Scenario: Import fill in the blank question in a lesson + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And I log in as "teacher1" + When I am on homepage + And I follow "Course 1" + And I turn editing mode on + And I add a "Lesson" to section "1" and I fill the form with: + | Name | Test lesson name | + | Description | Test lesson description | + And I follow "Test lesson name" + And I follow "Import questions" + And I set the field "File format" to "Blackboard" + And I upload "mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat" file to "Upload" filemanager + And I press "Import" + Then I should see "Importing 1 questions" + And I should see "Name an amphibian: __________" + And I press "Continue" + And I should not see "__________" + And I should not see "Your answer" + And I set the field "id_answer" to "frog" + And I press "Submit" + And I should see "Your answer : frog" + And I should see "A frog is an amphibian" + And I press "Continue" + And I should see "Congratulations - end of lesson reached" \ No newline at end of file diff --git a/mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat b/mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat new file mode 100644 index 00000000000..e5915432843 --- /dev/null +++ b/mod/lesson/tests/fixtures/sample_blackboard_fib_qti.dat @@ -0,0 +1,138 @@ + + + +
+ + + DD76E663D4244C598FC91CFC433F6D5B + Item + Pool + Subsection + Fill in the Blank + false + 0.0,1.0 + 0.0 + 1.0 + Proprietary + Logical Identifier + School + 0.0 + 0 + Proprietary + Single + Absolute + Normal + 0 + 0.0 + Complete + + + + + + + + <span style="font-size:12pt">Name an amphibian&#58; __________.</span> + + + + + + + + + + + + + + + + + + + + + + + + + + frog + + + + + + + + + 0.0 + + + + + + + + + A frog is an amphibian. + + + + + + + + + + + + + + + + + + + A frog is an amphibian. + + + + + + + + + + + + + + + + + + + + + A frog is an amphibian. + + + + + + + + + + + + + + + + +
+
+