Files
moodle/question/behaviour/adaptive/tests/mark_display_test.php
T
Eloy Lafuente (stronk7) 01148a0816 MDL-81522 phpunit: Add missing void return type to all tests
While this change is not 100% required now, it's good habit
and we are checking for it since Moodle 4.4.

All the changes in this commit have been applied automatically
using the moodle.PHPUnit.TestReturnType sniff and are, exclusively
adding the ": void" return types when missing.
2024-06-11 11:55:07 +02:00

107 lines
5.4 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace qbehaviour_adaptive;
use qbehaviour_adaptive_mark_details;
use question_display_options;
use question_state;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once(__DIR__ . '/../../../engine/lib.php');
require_once(__DIR__ . '/../behaviour.php');
/**
* Unit tests for the adaptive behaviour the display of mark/penalty information.
*
* @package qbehaviour_adaptive
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mark_display_test extends \basic_testcase {
/** @var qbehaviour_adaptive_renderer the renderer to test. */
protected $renderer;
/** @var question_display_options display options to use when rendering. */
protected $options;
protected function setUp(): void {
global $PAGE;
parent::setUp();
$this->renderer = $PAGE->get_renderer('qbehaviour_adaptive');
$this->options = new question_display_options();
}
public function test_blank_before_graded(): void {
$this->assertEquals('',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$todo), $this->options));
}
public function test_correct_no_penalty(): void {
$this->assertEquals('<div class="correctness badge correct">' . get_string('correct', 'question') . '</div>' .
'<div class="gradingdetails">' .
get_string('gradingdetails', 'qbehaviour_adaptive',
array('cur' => '1.00', 'raw' => '1.00', 'max' => '1.00')) . '</div>',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$gradedright, 1, 1, 1, 0, 0, false), $this->options));
}
public function test_partial_first_try(): void {
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
'</div><div class="gradingdetails">' .
get_string('gradingdetails', 'qbehaviour_adaptive',
array('cur' => '0.50', 'raw' => '0.50', 'max' => '1.00')) . ' ' .
get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . '</div>',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$gradedpartial, 1, 0.5, 0.5, 0.1, 0.1, true), $this->options));
}
public function test_partial_second_try(): void {
$mark = array('cur' => '0.80', 'raw' => '0.90', 'max' => '1.00');
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
'</div><div class="gradingdetails">' .
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . ' ' .
get_string('gradingdetailspenalty', 'qbehaviour_adaptive', '0.10') . ' ' .
get_string('gradingdetailspenaltytotal', 'qbehaviour_adaptive', '0.20') . '</div>',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$gradedpartial, 1, 0.8, 0.9, 0.1, 0.2, true), $this->options));
}
public function test_correct_third_try(): void {
$mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
'</div><div class="gradingdetails">' .
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$gradedpartial, 1, 0.8, 1.0, 0.1, 0.3, false), $this->options));
}
public function test_correct_third_try_if_we_dont_increase_penalties_for_wrong(): void {
$mark = array('cur' => '0.80', 'raw' => '1.00', 'max' => '1.00');
$this->assertEquals('<div class="correctness badge partiallycorrect">' . get_string('partiallycorrect', 'question') .
'</div><div class="gradingdetails">' .
get_string('gradingdetails', 'qbehaviour_adaptive', $mark) . ' ' .
get_string('gradingdetailsadjustment', 'qbehaviour_adaptive', $mark) . '</div>',
$this->renderer->render_adaptive_marks(new qbehaviour_adaptive_mark_details(
question_state::$gradedpartial, 1, 0.8, 1.0, 0, 0.2, false), $this->options));
}
}