Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79937

Lesson: Matching questions does not match with expected response

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79937-401_fixlessonmatching
    • MDL-79937-403_fixlessonmatching
    • MDL-79937_fixlessonmatching
    • Hide

      Test:

      1. Create a Lesson.
      2. Add a Question Page -> Select Matching type.
      3. Create a Sample Question with correct and incorrect answers.
      4. Save Page
      5. Preview the Question
      6. When answering questions correctly make sure you can reach end of lesson

      Regression test:

      The chosen filter for this test will be filter_multilang2, so you should have installed it previously.

      Setup:

      • Navigate to /admin/filters.php and enable the multilang2 filter with the applied to option set to "Content"
      • Install a language pack such as Japanese (Used in testing instructions for shorthanding)

      Test:

      1. Create a Lesson module.
      2. Add a Question page to the lesson (type: matching).
      3. Add at least two Matching pairs with the appropriate settings in bold: 
        1. Answer: Offer a greeting Matches with: {mlang en}Welcome{mlang} {mlang ja}ようこそ{mlang}
        2. Answer: Offer a farewell Matches with: {mlang en}Goodbye{mlang} {mlang ja}
          さよなら{mlang}
      1. Save page and preview it.
      2. Select one of the drop downs
      3. Confirm You see in any order:
        1. Welcome
        2. Goodbye
      4. In a new tab on the site, change your language to Japanese
      5. In the original tab, reload the page
      6. Select one of the drop downs
      7. Confirm You see in any order:
        1. ようこそ
        2. さよなら
      Show
      Test: Create a Lesson. Add a Question Page -> Select Matching type. Create a Sample Question with correct and incorrect answers. Save Page Preview the Question When answering questions correctly make sure you can reach end of lesson Regression test: The chosen filter for this test will be filter_multilang2 , so you should have installed it previously. Setup: Navigate to /admin/filters.php and enable the multilang2 filter with the applied to option set to "Content" Install a language pack such as Japanese (Used in testing instructions for shorthanding) Test: Create a Lesson module. Add a Question page to the lesson (type: matching). Add at least two Matching pairs with the appropriate settings in bold:  Answer : Offer a greeting Matches with: {mlang en}Welcome{mlang} {mlang ja}ようこそ{mlang} Answer : Offer a farewell Matches with: {mlang en}Goodbye{mlang} {mlang ja} さよなら{mlang} Save page and preview it. Select one of the drop downs Confirm You see in any order: Welcome Goodbye In a new tab on the site, change your language to Japanese In the original tab, reload the page Select one of the drop downs Confirm You see in any order: ようこそ さよなら

      Context

      Moodle 4.1.6+
      Mysql 5.7

      In a lesson activity, add a page with a matching question type.

      There is no possibility to go on selecting the correct answers.

      I think it is a collateral effect of applying MDL-78481, about filters.

      Problem

      I have identified missing code that adds this HTML to the answer from the user div class="text_to_html">expected answer</div>, instead of simply expected answer (for the sake of an example).

      Expected

      The user, when selecting correct answers, can go on with the lesson activity.

      Proposed patch

      There is similar fragment working later on on the same file mod/lesson/pagetypes/matching.php, where the method set ups the properties for the format_text() function, like format_text(trim($answer->response), $answer->answerformat, $formattextdefoptions);. Instead, prior to this case, the user answer is processed without them, producing the unexpected incorrect behaviour of the patch.

      The final code results on this:

       

      $formattextdefoptions = new stdClass();
      $formattextdefoptions->noclean = true;
      $formattextdefoptions->para = false;

      $responses = array();
      foreach ($answers as $answer) {
      // get all the response
      if ($answer->response != null)

      { $responses[] = format_text(trim($answer->response), $answer->answerformat, $formattextdefoptions); }

      }
      code}

      and the diff is:

      --- a/mod/lesson/pagetypes/matching.php
      +++ b/mod/lesson/pagetypes/matching.php
      @@ -79,11 +79,15 @@ class lesson_page_type_matching extends lesson_page {
                   $answers[$getanswer->id] = $getanswer;
               }
       
      +        $formattextdefoptions = new stdClass();
      +        $formattextdefoptions->noclean = true;
      +        $formattextdefoptions->para = false;
      +
               $responses = array();
               foreach ($answers as $answer) {
                   // get all the response
                   if ($answer->response != null) {
      -                $responses[] = format_text(trim($answer->response));
      +                $responses[] = format_text(trim($answer->response), $answer->answerformat, $formattextdefoptions);
                   }
               }
       
      
      

      With this patch, the matching question page on the lesson activity works properly.

        1. 2023-11-10_17-11-12.jpg
          2023-11-10_17-11-12.jpg
          60 kB
        2. 2023-11-10_17-14-14.jpg
          2023-11-10_17-14-14.jpg
          23 kB
        3. matching.php
          26 kB
        4. MDL-79937.png
          MDL-79937.png
          393 kB

            Votes:
            54 Vote for this issue
            Watchers:
            68 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 48 minutes
                4h 48m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.