Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  
  18  /**
  19   * This file contains tests that just test the display mark/penalty information.
  20   *
  21   * @package   qbehaviour_adaptive
  22   * @copyright 2012 The Open University
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  global $CFG;
  30  require_once (__DIR__ . '/../../../engine/lib.php');
  31  require_once (__DIR__ . '/../behaviour.php');
  32  
  33  
  34  /**
  35   * Unit tests for the adaptive behaviour the display of mark/penalty information.
  36   *
  37   * @copyright 2012 The Open University
  38   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class qbehaviour_adaptive_mark_display_test extends basic_testcase {
  41      /** @var qbehaviour_adaptive_renderer the renderer to test. */
  42      protected $renderer;
  43  
  44      /** @var question_display_options display options to use when rendering. */
  45      protected $options;
  46  
  47      protected function setUp(): void {
  48          global $PAGE;
  49          parent::setUp();
  50          $this->renderer = $PAGE->get_renderer('qbehaviour_adaptive');
  51          $this->options = new question_display_options();
  52      }
  53  
  54      public function test_blank_before_graded() {
  55          $this->assertEquals('',
  56                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
  57                          question_state::$todo), $this->options));
  58      }
  59  
  60      public function test_correct_no_penalty() {
  61          $this->assertEquals('<div class="correctness badge correct">' . get_string('correct', 'question') . '</div>' .
  62                  '<div class="gradingdetails">' .
  63                  get_string('gradingdetails', 'qbehaviour_adaptive',
  64                          array('cur' => '1.00', 'raw' => '1.00', 'max' => '1.00')) . '</div>',
  65                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
  66                          question_state::$gradedright, 1, 1, 1, 0, 0, false), $this->options));
  67      }
  68  
  69      public function test_partial_first_try() {
  70          $this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
  71                  '</div><div class="gradingdetails">' .
  72                  get_string('gradingdetails', 'qbehaviour_adaptive',
  73                          array('cur' => '0.50', 'raw' => '0.50', 'max' => '1.00')) . ' ' .
  74                  get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . '</div>',
  75                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
  76                          question_state::$gradedpartial, 1, 0.5, 0.5, 0.1, 0.1, true), $this->options));
  77      }
  78  
  79      public function test_partial_second_try() {
  80          $mark = array('cur' => '0.80', 'raw' => '0.90', 'max' => '1.00');
  81          $this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
  82                  '</div><div class="gradingdetails">' .
  83                  get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
  84                  get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . ' ' .
  85                  get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . ' ' .
  86                  get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', '0.20') . '</div>',
  87                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
  88                          question_state::$gradedpartial, 1, 0.8, 0.9, 0.1, 0.2, true), $this->options));
  89      }
  90  
  91      public function test_correct_third_try() {
  92          $mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
  93          $this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
  94                  '</div><div class="gradingdetails">' .
  95                  get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
  96                  get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
  97                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
  98                          question_state::$gradedpartial, 1, 0.8, 1.0, 0.1, 0.3, false), $this->options));
  99      }
 100  
 101      public function test_correct_third_try_if_we_dont_increase_penalties_for_wrong() {
 102          $mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
 103          $this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
 104                  '</div><div class="gradingdetails">' .
 105                  get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
 106                  get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
 107                  $this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
 108                          question_state::$gradedpartial, 1, 0.8, 1.0, 0, 0.2, false), $this->options));
 109      }
 110  }