Merge branch 'MDL-61971-master' of git://github.com/mickhawkins/moodle
[moodle.git] / question / behaviour / adaptive / tests / mark_display_test.php
CommitLineData
a3e6ad77
TH
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
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
1fcf0ca8
RS
30require_once(__DIR__ . '/../../../engine/lib.php');
31require_once(__DIR__ . '/../behaviour.php');
a3e6ad77
TH
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 */
40class 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() {
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 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 partiallycorrect">' . get_string('partiallycorrect', 'question') . '</div>' .
71 '<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 partiallycorrect">' . get_string('partiallycorrect', 'question') . '</div>' .
82 '<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 partiallycorrect">' . get_string('partiallycorrect', 'question') . '</div>' .
94 '<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 partiallycorrect">' . get_string('partiallycorrect', 'question') . '</div>' .
104 '<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}