';
}
}
diff --git a/mod/lesson/pagetypes/branchtable.php b/mod/lesson/pagetypes/branchtable.php
index 749f85d3fad..c382ffafd3d 100644
--- a/mod/lesson/pagetypes/branchtable.php
+++ b/mod/lesson/pagetypes/branchtable.php
@@ -237,6 +237,8 @@ class lesson_page_type_branchtable extends lesson_page {
$answers = $this->get_answers();
$formattextdefoptions = new stdClass;
$formattextdefoptions->para = false; //I'll use it widely in this page
+ $formattextdefoptions->context = $answerpage->context;
+
foreach ($answers as $answer) {
$data = "id\" value=\"".s(strip_tags(format_text($answer->answer, FORMAT_MOODLE,$formattextdefoptions)))."\" disabled=\"disabled\"> ";
$data .= get_string('jumpsto', 'lesson', $this->get_jump_name($answer->jumpto));
diff --git a/mod/lesson/pagetypes/essay.php b/mod/lesson/pagetypes/essay.php
index be86f7a27c5..cceef9ad8b4 100644
--- a/mod/lesson/pagetypes/essay.php
+++ b/mod/lesson/pagetypes/essay.php
@@ -122,7 +122,7 @@ class lesson_page_type_essay extends lesson_page {
$userresponse->response = "";
$result->userresponse = serialize($userresponse);
$result->studentanswerformat = $studentanswerformat;
- $result->studentanswer = s($studentanswer);
+ $result->studentanswer = $studentanswer;
return $result;
}
public function update($properties, $context = null, $maxbytes = null) {
@@ -179,9 +179,6 @@ class lesson_page_type_essay extends lesson_page {
}
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
$answers = $this->get_answers();
- $formattextdefoptions = new stdClass;
- $formattextdefoptions->para = false; //I'll use it widely in this page
- $formattextdefoptions->context = $answerpage->context;
foreach ($answers as $answer) {
if ($useranswer != null) {
@@ -224,7 +221,9 @@ class lesson_page_type_essay extends lesson_page {
// dont think this should ever be reached....
$avescore = get_string("nooneansweredthisquestion", "lesson");
}
- $answerdata->answers[] = array(format_text($essayinfo->answer, $essayinfo->answerformat, $formattextdefoptions), $avescore);
+ // This is the student's answer so it should be cleaned.
+ $answerdata->answers[] = array(format_text($essayinfo->answer, $essayinfo->answerformat,
+ array('para' => true, 'context' => $answerpage->context)), $avescore);
$answerpage->answerdata = $answerdata;
}
return $answerpage;
diff --git a/mod/lesson/pagetypes/multichoice.php b/mod/lesson/pagetypes/multichoice.php
index 58e9ff02180..c22a6ea0bb4 100644
--- a/mod/lesson/pagetypes/multichoice.php
+++ b/mod/lesson/pagetypes/multichoice.php
@@ -353,6 +353,7 @@ class lesson_page_type_multichoice extends lesson_page {
$answers = $this->get_used_answers();
$formattextdefoptions = new stdClass;
$formattextdefoptions->para = false; //I'll use it widely in this page
+ $formattextdefoptions->context = $answerpage->context;
foreach ($answers as $answer) {
if ($this->properties->qoption) {
diff --git a/mod/lesson/pagetypes/truefalse.php b/mod/lesson/pagetypes/truefalse.php
index fcfa4bd5632..c0376c6bb27 100644
--- a/mod/lesson/pagetypes/truefalse.php
+++ b/mod/lesson/pagetypes/truefalse.php
@@ -245,6 +245,8 @@ class lesson_page_type_truefalse extends lesson_page {
$formattextdefoptions = new stdClass(); //I'll use it widely in this page
$formattextdefoptions->para = false;
$formattextdefoptions->noclean = true;
+ $formattextdefoptions->context = $answerpage->context;
+
foreach ($answers as $answer) {
$answer = parent::rewrite_answers_urls($answer);
if ($this->properties->qoption) {
diff --git a/mod/lesson/report.php b/mod/lesson/report.php
index d5383580be2..3895f728c6a 100644
--- a/mod/lesson/report.php
+++ b/mod/lesson/report.php
@@ -466,6 +466,7 @@ if ($action === 'delete') {
$options = new stdClass;
$options->noclean = true;
$options->overflowdiv = true;
+ $options->context = $context;
$answerpage->contents = format_text($page->contents, $page->contentsformat, $options);
$answerpage->qtype = $qtypes[$page->qtype].$page->option_description_string();
diff --git a/mod/lesson/tests/behat/lesson_essay_question.feature b/mod/lesson/tests/behat/lesson_essay_question.feature
new file mode 100644
index 00000000000..56fde01735d
--- /dev/null
+++ b/mod/lesson/tests/behat/lesson_essay_question.feature
@@ -0,0 +1,79 @@
+@mod @mod_lesson
+Feature: In a lesson activity, teacher can add an essay question
+ As a teacher
+ I need to add an essay question in a lesson and grade student attempts
+
+ @javascript
+ Scenario: questions with essay question
+ 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"
+ And I navigate to "My private files" node in "My profile"
+ And I upload "mod/lesson/tests/fixtures/moodle_logo.jpg" file to "Files" filemanager
+ And I click on "Save changes" "button"
+ 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 |
+ | Use default feedback | Yes |
+ And I follow "Test lesson name"
+ And I follow "Add a question page"
+ And I set the field "Select a question type" to "Essay"
+ And I press "Add a question page"
+ And I set the following fields to these values:
+ | Page title | Essay question |
+ | Page contents |
Please write a story about a frog.
|
+ And I click on "Image" "button"
+ And I click on "Browse repositories..." "button"
+ And I click on "Private files" "link"
+ And I click on "moodle_logo.jpg" "link"
+ And I click on "Select this file" "button"
+ And I set the field "Describe this image for someone who cannot see it" to "It's the logo"
+ And I click on "Save image" "button"
+ And I press "Save page"
+ And I log out
+ And I log in as "student1"
+ And I follow "Course 1"
+ When I follow "Test lesson name"
+ Then I should see "Please write a story about a frog."
+ And I set the field "Your answer" to "
Once upon a time there was a little green frog."
+ And I click on "Image" "button"
+ And I set the following fields to these values:
+ | Enter URL | http://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Greenfrog.jpg/120px-Greenfrog.jpg |
+ | Describe this image for someone who cannot see it | A frog |
+ And I press "Save image"
+ And I press "Submit"
+ And I should see "Your answer"
+ And I should see "Once upon a time there was a little green frog."
+ And I should not see "<b>"
+ And I press "Continue"
+ And I should see "Congratulations - end of lesson reached"
+ And I should see "You earned 0 out of 0 for the automatically graded questions."
+ And I should see "Your 1 essay question(s) will be graded and added into your final score at a later date."
+ And I should see "Your current grade without the essay question(s) is 0 out of 1."
+ And I log out
+ And I log in as "teacher1"
+ And I follow "Course 1"
+ And I follow "Test lesson name"
+ And I follow "Grade essays"
+ And I should see "Student 1"
+ And I should see "Essay question"
+ And I follow "Essay question"
+ And I should see "Student 1's response"
+ And I should see "Once upon a time there was a little green frog."
+ And I set the following fields to these values:
+ | Your comments | Well done. |
+ | Essay score | 1 |
+ And I press "Save changes"
+ And I should see "Changes saved"