Files
moodle/mod/quiz/simpletest/testlib.php
T
tjhunt 84e628a027 quiz settings: MDL-18485 Improve quiz settings form
* Reorder form fields to group things more logically.
** and on the corresponding admin page too.

* Set some options to be 'Advanced' by default:
** Apply penalties.
** Each attempt builds on the last.
** Decimal places for question grades.
** The five 'Extra restrictions on attempts' settings. (password, etc.)
* Admins can still change this to suit their institiution at Administration > Plugins > Activity modules > Quiz.
* These new defaults are applied if the admin had not previously set any fields to be advanced.

* Disable some filds when they are not applicable:
** Grading method, if num attempts = 1
** Penaly scheme, if adaptive mode = no
** Each attempt builds of last, if num attempts = 1
** Review after quiz closed options, if no close date.
** Delay between 1st and 2nd attempts, if num attempts = 1
** Delay between later attempts, if num attempts < 3

* Convert quiz.timelimit to be in seconds, for consistency, and ready for the new duration field type (MDL 18500).
** Including ensuring that backup and restore is backwards compatible.

* MDL-5537 New setting, questiondecimalpoints, so, for example, you can show the quiz grade as an integer, but have fractional question grades.
** There is a 'Same as overall decimal points' option, which is the default.

* Improve some field labels.

* Make corresponding changes in the help files.
2009-03-10 08:39:51 +00:00

58 lines
2.4 KiB
PHP

<?php
/**
* Unit tests for (some of) mod/quiz/locallib.php.
*
* @author T.J.Hunt@open.ac.uk
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package quiz
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
}
require_once($CFG->dirroot . '/mod/quiz/lib.php');
class quiz_lib_test extends UnitTestCase {
function test_quiz_has_grades() {
$quiz = new stdClass;
$quiz->grade = '100.0000';
$quiz->sumgrades = '100.0000';
$this->assertTrue(quiz_has_grades($quiz));
$quiz->sumgrades = '0.0000';
$this->assertFalse(quiz_has_grades($quiz));
$quiz->grade = '0.0000';
$this->assertFalse(quiz_has_grades($quiz));
$quiz->sumgrades = '100.0000';
$this->assertFalse(quiz_has_grades($quiz));
}
function test_quiz_format_grade() {
$quiz = new stdClass;
$quiz->decimalpoints = 2;
$this->assertEqual(quiz_format_grade($quiz, 0.12345678), format_float(0.12, 2));
$this->assertEqual(quiz_format_grade($quiz, 0), format_float(0, 2));
$this->assertEqual(quiz_format_grade($quiz, 1.000000000000), format_float(1, 2));
$quiz->decimalpoints = 0;
$this->assertEqual(quiz_format_grade($quiz, 0.12345678), '0');
}
function test_quiz_format_question_grade() {
$quiz = new stdClass;
$quiz->decimalpoints = 2;
$quiz->questiondecimalpoints = 2;
$this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.12, 2));
$this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 2));
$this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 2));
$quiz->decimalpoints = 3;
$quiz->questiondecimalpoints = -1;
$this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.123, 3));
$this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 3));
$this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 3));
$quiz->questiondecimalpoints = 4;
$this->assertEqual(quiz_format_question_grade($quiz, 0.12345678), format_float(0.1235, 4));
$this->assertEqual(quiz_format_question_grade($quiz, 0), format_float(0, 4));
$this->assertEqual(quiz_format_question_grade($quiz, 1.000000000000), format_float(1, 4));
}
}