MDL-76614 quiz: deprecate class moodle_quiz_exception
Code should just directly use moodle_execption. Note, some of the existing uses (in web services) were passing a literal message, not a language string identifier, but I decided now was not the time to try to fix that.
This commit is contained in:
@@ -57,7 +57,7 @@ if ($attemptobj->get_userid() != $USER->id) {
|
||||
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
|
||||
redirect($attemptobj->review_url(null, $page));
|
||||
} else {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ $slots = $attemptobj->get_slots($page);
|
||||
|
||||
// Check.
|
||||
if (empty($slots)) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound');
|
||||
throw new moodle_exception('noquestionsfound', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
|
||||
// Update attempt page, redirecting the user if $page is not valid.
|
||||
|
||||
+1
-30
@@ -31,35 +31,6 @@ use mod_quiz\access_manager;
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use mod_quiz\question\display_options;
|
||||
|
||||
|
||||
/**
|
||||
* Class for quiz exceptions. Just saves a couple of arguments on the
|
||||
* constructor for a moodle_exception.
|
||||
*
|
||||
* @copyright 2008 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class moodle_quiz_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param quiz $quizobj the quiz the error relates to.
|
||||
* @param string $errorcode The name of the string from error.php to print.
|
||||
* @param mixed $a Extra words and phrases that might be required in the error string.
|
||||
* @param string $link The url where the user will be prompted to continue.
|
||||
* If no url is provided the user will be directed to the site index page.
|
||||
* @param string|null $debuginfo optional debugging information.
|
||||
*/
|
||||
public function __construct($quizobj, $errorcode, $a = null, $link = '', $debuginfo = null) {
|
||||
if (!$link) {
|
||||
$link = $quizobj->view_url();
|
||||
}
|
||||
parent::__construct($errorcode, 'quiz', $link, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A class encapsulating a quiz and the questions it contains, and making the
|
||||
* information available to scripts like view.php.
|
||||
@@ -525,7 +496,7 @@ class quiz {
|
||||
*/
|
||||
protected function ensure_question_loaded($id) {
|
||||
if (isset($this->questions[$id]->_partiallyloaded)) {
|
||||
throw new moodle_quiz_exception($this, 'questionnotloaded', $id);
|
||||
throw new moodle_exception('questionnotloaded', 'quiz', $this->view_url(), $id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ require_login($attemptobj->get_course(), false, $attemptobj->get_cm());
|
||||
|
||||
// Check that this attempt belongs to this user.
|
||||
if ($attemptobj->get_userid() != $USER->id) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Check capabilities.
|
||||
@@ -55,8 +55,7 @@ if (!$attemptobj->is_preview_user()) {
|
||||
|
||||
// If the attempt is already closed, send them to the review page.
|
||||
if ($attemptobj->is_finished()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(),
|
||||
'attemptalreadyclosed', null, $attemptobj->review_url());
|
||||
throw new moodle_exception('attemptalreadyclosed', 'quiz', $attemptobj->review_url());
|
||||
}
|
||||
|
||||
$attemptobj->process_auto_save($timenow);
|
||||
|
||||
@@ -305,7 +305,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param int $quizid quiz instance id
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function view_quiz($quizid) {
|
||||
global $DB;
|
||||
@@ -366,10 +365,9 @@ class mod_quiz_external extends external_api {
|
||||
* @param bool $includepreviews whether to include previews or not
|
||||
* @return array of warnings and the list of attempts
|
||||
* @since Moodle 3.1
|
||||
* @throws invalid_parameter_exception
|
||||
*/
|
||||
public static function get_user_attempts($quizid, $userid = 0, $status = 'finished', $includepreviews = false) {
|
||||
global $DB, $USER;
|
||||
global $USER;
|
||||
|
||||
$warnings = array();
|
||||
|
||||
@@ -711,7 +709,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param bool $forcenew Whether to force a new attempt or not.
|
||||
* @return array of warnings and the attempt basic data
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
public static function start_attempt($quizid, $preflightdata = array(), $forcenew = false) {
|
||||
global $DB, $USER;
|
||||
@@ -733,7 +730,7 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
// Check questions.
|
||||
if (!$quizobj->has_questions()) {
|
||||
throw new moodle_quiz_exception($quizobj, 'noquestionsfound');
|
||||
throw new moodle_exception('noquestionsfound', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
|
||||
// Create an object to manage all the other (non-roles) access rules.
|
||||
@@ -767,7 +764,7 @@ class mod_quiz_external extends external_api {
|
||||
$errors = $accessmanager->validate_preflight_check($provideddata, [], $currentattemptid);
|
||||
|
||||
if (!empty($errors)) {
|
||||
throw new moodle_quiz_exception($quizobj, array_shift($errors));
|
||||
throw new moodle_exception(array_shift($errors), 'quiz', $quizobj->view_url());
|
||||
}
|
||||
|
||||
// Pre-flight check passed.
|
||||
@@ -776,9 +773,9 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
if ($currentattemptid) {
|
||||
if ($lastattempt->state == quiz_attempt::OVERDUE) {
|
||||
throw new moodle_quiz_exception($quizobj, 'stateoverdue');
|
||||
throw new moodle_exception('stateoverdue', 'quiz', $quizobj->view_url());
|
||||
} else {
|
||||
throw new moodle_quiz_exception($quizobj, 'attemptstillinprogress');
|
||||
throw new moodle_exception('attemptstillinprogress', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
}
|
||||
$offlineattempt = WS_SERVER ? true : false;
|
||||
@@ -813,7 +810,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param bool $checkaccessrules whether to check the quiz access rules or not
|
||||
* @param bool $failifoverdue whether to return error if the attempt is overdue
|
||||
* @return array containing the attempt object and access messages
|
||||
* @throws moodle_quiz_exception
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
protected static function validate_attempt($params, $checkaccessrules = true, $failifoverdue = true) {
|
||||
@@ -826,7 +822,7 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
// Check that this attempt belongs to this user.
|
||||
if ($attemptobj->get_userid() != $USER->id) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
|
||||
// General capabilities check.
|
||||
@@ -844,15 +840,15 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
$messages = $accessmanager->prevent_access();
|
||||
if (!$ispreviewuser && $messages) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attempterror');
|
||||
throw new moodle_exception('attempterror', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt closed?.
|
||||
if ($attemptobj->is_finished()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptalreadyclosed');
|
||||
throw new moodle_exception('attemptalreadyclosed', 'quiz', $attemptobj->view_url());
|
||||
} else if ($failifoverdue && $attemptobj->get_state() == quiz_attempt::OVERDUE) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'stateoverdue');
|
||||
throw new moodle_exception('stateoverdue', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// User submitted data (like the quiz password).
|
||||
@@ -864,7 +860,7 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
$errors = $accessmanager->validate_preflight_check($provideddata, [], $params['attemptid']);
|
||||
if (!empty($errors)) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), array_shift($errors));
|
||||
throw new moodle_exception(array_shift($errors), 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
// Pre-flight check passed.
|
||||
$accessmanager->notify_preflight_check_passed($params['attemptid']);
|
||||
@@ -873,19 +869,19 @@ class mod_quiz_external extends external_api {
|
||||
if (isset($params['page'])) {
|
||||
// Check if the page is out of range.
|
||||
if ($params['page'] != $attemptobj->force_page_number_into_range($params['page'])) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Invalid page number');
|
||||
throw new moodle_exception('Invalid page number', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Prevent out of sequence access.
|
||||
if (!$attemptobj->check_page_access($params['page'])) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access');
|
||||
throw new moodle_exception('Out of sequence access', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Check slots.
|
||||
$slots = $attemptobj->get_slots($params['page']);
|
||||
|
||||
if (empty($slots)) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noquestionsfound');
|
||||
throw new moodle_exception('noquestionsfound', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1048,7 +1044,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param array $preflightdata preflight required data (like passwords)
|
||||
* @return array of warnings and the attempt data, next page, message and questions
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_quiz_exceptions
|
||||
*/
|
||||
public static function get_attempt_data($attemptid, $page, $preflightdata = array()) {
|
||||
global $PAGE;
|
||||
@@ -1372,8 +1367,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param array $params Array of parameters including the attemptid
|
||||
* @return array containing the attempt object and display options
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
protected static function validate_attempt_review($params) {
|
||||
|
||||
@@ -1383,13 +1376,13 @@ class mod_quiz_external extends external_api {
|
||||
$displayoptions = $attemptobj->get_display_options(true);
|
||||
if ($attemptobj->is_own_attempt()) {
|
||||
if (!$attemptobj->is_finished()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'attemptclosed');
|
||||
throw new moodle_exception('attemptclosed', 'quiz', $attemptobj->view_url());
|
||||
} else if (!$displayoptions->attempt) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreview', null, '',
|
||||
throw new moodle_exception('noreview', 'quiz', $attemptobj->view_url(), null,
|
||||
$attemptobj->cannot_review_message());
|
||||
}
|
||||
} else if (!$attemptobj->is_review_allowed()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
|
||||
throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
return array($attemptobj, $displayoptions);
|
||||
}
|
||||
@@ -1417,8 +1410,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param int $page page number, empty for all the questions in all the pages
|
||||
* @return array of warnings and the attempt data, feedback and questions
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
public static function get_attempt_review($attemptid, $page = -1) {
|
||||
global $PAGE;
|
||||
@@ -1548,7 +1539,7 @@ class mod_quiz_external extends external_api {
|
||||
|
||||
// Update attempt page, throwing an exception if $page is not valid.
|
||||
if (!$attemptobj->set_currentpage($params['page'])) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'Out of sequence access');
|
||||
throw new moodle_exception('Out of sequence access', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
$result = array();
|
||||
@@ -1714,7 +1705,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param float $grade the grade to check
|
||||
* @return array of warnings and status result
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function get_quiz_feedback_for_grade($quizid, $grade) {
|
||||
global $DB;
|
||||
@@ -1785,7 +1775,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param int $quizid quiz instance id
|
||||
* @return array of warnings and the access information
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
public static function get_quiz_access_information($quizid) {
|
||||
global $DB, $USER;
|
||||
@@ -1869,7 +1858,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param int $attemptid attempt id, 0 for the user last attempt if exists
|
||||
* @return array of warnings and the access information
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
public static function get_attempt_access_information($quizid, $attemptid = 0) {
|
||||
global $DB, $USER;
|
||||
@@ -1888,7 +1876,7 @@ class mod_quiz_external extends external_api {
|
||||
if (!empty($params['attemptid'])) {
|
||||
$attemptobj = quiz_attempt::create($params['attemptid']);
|
||||
if ($attemptobj->get_userid() != $USER->id) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
$attempttocheck = $attemptobj->get_attempt();
|
||||
}
|
||||
@@ -1975,7 +1963,6 @@ class mod_quiz_external extends external_api {
|
||||
* @param int $quizid quiz instance id
|
||||
* @return array of warnings and the access information
|
||||
* @since Moodle 3.1
|
||||
* @throws moodle_quiz_exception
|
||||
*/
|
||||
public static function get_quiz_required_qtypes($quizid) {
|
||||
global $DB, $USER;
|
||||
|
||||
@@ -140,7 +140,7 @@ function quiz_get_completion_state($course, $cm, $userid, $type) {
|
||||
* @copyright 2012 the Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @deprecated since Moodle 4.2. Code moved to mod_quiz\task\update_overdue_attempts.
|
||||
* @todo MDL-71196 Final deprecation in Moodle 4.3
|
||||
* @todo MDL-76612 Final deprecation in Moodle 4.6
|
||||
*/
|
||||
class mod_quiz_overdue_attempt_updater {
|
||||
|
||||
@@ -162,3 +162,33 @@ class mod_quiz_overdue_attempt_updater {
|
||||
return (new update_overdue_attempts())->get_list_of_overdue_attempts((int) $processto);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class for quiz exceptions. Just saves a couple of arguments on the
|
||||
* constructor for a moodle_exception.
|
||||
*
|
||||
* @copyright 2008 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
* @deprecated since Moodle 4.2. Please just use moodle_exception.
|
||||
* @todo MDL-76612 Final deprecation in Moodle 4.6
|
||||
*/
|
||||
class moodle_quiz_exception extends moodle_exception {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param quiz $quizobj the quiz the error relates to.
|
||||
* @param string $errorcode The name of the string from error.php to print.
|
||||
* @param mixed $a Extra words and phrases that might be required in the error string.
|
||||
* @param string $link The url where the user will be prompted to continue.
|
||||
* If no url is provided the user will be directed to the site index page.
|
||||
* @param string|null $debuginfo optional debugging information.
|
||||
* @deprecated since Moodle 4.2. Please just use moodle_exception.
|
||||
*/
|
||||
public function __construct($quizobj, $errorcode, $a = null, $link = '', $debuginfo = null) {
|
||||
if (!$link) {
|
||||
$link = $quizobj->view_url();
|
||||
}
|
||||
parent::__construct($errorcode, 'quiz', $link, $a, $debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2442,7 +2442,6 @@ function quiz_view($quiz, $course, $cm, $context) {
|
||||
* @param int $page page to jump to in the attempt
|
||||
* @param bool $redirect whether to redirect or throw exceptions (for web or ws usage)
|
||||
* @return array an array containing the attempt information, access error messages and the page to jump to in the attempt
|
||||
* @throws moodle_quiz_exception
|
||||
* @since Moodle 3.1
|
||||
*/
|
||||
function quiz_validate_new_attempt(quiz $quizobj, access_manager $accessmanager, $forcenew, $page, $redirect) {
|
||||
@@ -2485,7 +2484,7 @@ function quiz_validate_new_attempt(quiz $quizobj, access_manager $accessmanager,
|
||||
if ($redirect) {
|
||||
redirect($quizobj->review_url($lastattempt->id));
|
||||
} else {
|
||||
throw new moodle_quiz_exception($quizobj, 'attemptalreadyclosed');
|
||||
throw new moodle_exception('attemptalreadyclosed', 'quiz', $quizobj->view_url());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ require_sesskey();
|
||||
|
||||
// Check that this attempt belongs to this user.
|
||||
if ($attemptobj->get_userid() != $USER->id) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Check capabilities.
|
||||
@@ -81,8 +81,7 @@ if (!$attemptobj->is_preview_user()) {
|
||||
|
||||
// If the attempt is already closed, send them to the review page.
|
||||
if ($attemptobj->is_finished()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(),
|
||||
'attemptalreadyclosed', null, $attemptobj->review_url());
|
||||
throw new moodle_exception('attemptalreadyclosed', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Process the attempt, getting the new status for the attempt.
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ if ($attemptobj->is_own_attempt()) {
|
||||
}
|
||||
|
||||
} else if (!$attemptobj->is_review_allowed()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
|
||||
throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Load the questions and states needed by this page.
|
||||
|
||||
@@ -71,7 +71,7 @@ if ($attemptobj->is_own_attempt()) {
|
||||
}
|
||||
|
||||
} else if (!$attemptobj->is_review_allowed()) {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'noreviewattempt');
|
||||
throw new moodle_exception('noreviewattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
|
||||
// Prepare summary informat about this question attempt.
|
||||
|
||||
@@ -44,7 +44,7 @@ if ($attemptobj->get_userid() != $USER->id) {
|
||||
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
|
||||
redirect($attemptobj->review_url(null));
|
||||
} else {
|
||||
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
|
||||
throw new moodle_exception('notyourattempt', 'quiz', $attemptobj->view_url());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-18
@@ -29,6 +29,7 @@ namespace mod_quiz\external;
|
||||
use externallib_advanced_testcase;
|
||||
use mod_quiz_external;
|
||||
use mod_quiz\question\display_options;
|
||||
use moodle_exception;
|
||||
use quiz;
|
||||
use quiz_attempt;
|
||||
|
||||
@@ -340,7 +341,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::view_quiz(0);
|
||||
$this->fail('Exception expected due to invalid mod_quiz instance id.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('invalidrecord', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -350,7 +351,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::view_quiz($this->quiz->id);
|
||||
$this->fail('Exception expected due to not enrolled user.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('requireloginerror', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -386,7 +387,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::view_quiz($this->quiz->id);
|
||||
$this->fail('Exception expected due to missing capability.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('requireloginerror', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -846,7 +847,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'bad')));
|
||||
$this->fail('Exception expected due to invalid passwod.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals(get_string('passworderror', 'quizaccess_password'), $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -865,7 +866,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
|
||||
$this->fail('Exception expected due to attempt not finished.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('attemptstillinprogress', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -942,7 +943,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
'preflightdata' => array(array("name" => "quizpassword", "value" => 'bad')));
|
||||
testable_mod_quiz_external::validate_attempt($params);
|
||||
$this->fail('Exception expected due to invalid passwod.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals(get_string('passworderror', 'quizaccess_password'), $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -958,7 +959,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
testable_mod_quiz_external::validate_attempt($params);
|
||||
$this->fail('Exception expected due to page out of range.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('Invalid page number', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -975,7 +976,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
testable_mod_quiz_external::validate_attempt($params);
|
||||
$this->fail('Exception expected due to passed dates.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('attempterror', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -986,7 +987,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
testable_mod_quiz_external::validate_attempt($params, false);
|
||||
$this->fail('Exception expected due to attempt finished.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('attemptalreadyclosed', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -1011,7 +1012,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
testable_mod_quiz_external::validate_attempt($params);
|
||||
$this->fail('Exception expected due to not your attempt.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('notyourattempt', $e->errorcode);
|
||||
}
|
||||
}
|
||||
@@ -1504,7 +1505,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
$params = array('attemptid' => $attempt->id);
|
||||
testable_mod_quiz_external::validate_attempt_review($params);
|
||||
$this->fail('Exception expected due not closed attempt.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('attemptclosed', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -1527,7 +1528,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
$params = array('attemptid' => $attempt->id);
|
||||
testable_mod_quiz_external::validate_attempt_review($params);
|
||||
$this->fail('Exception expected due missing permissions.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('noreviewattempt', $e->errorcode);
|
||||
}
|
||||
}
|
||||
@@ -1642,7 +1643,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::view_attempt($attempt->id, 0);
|
||||
$this->fail('Exception expected due to try to see a previous page.');
|
||||
} catch (\moodle_quiz_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertEquals('Out of sequence access', $e->errorcode);
|
||||
}
|
||||
|
||||
@@ -2026,7 +2027,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::view_attempt($attemptobj->get_attemptid(), 3, []);
|
||||
$this->fail('Exception expected due to out of sequence access.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertStringContainsString('quiz/Out of sequence access', $e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -2057,7 +2058,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::get_attempt_data($attemptobj->get_attemptid(), 2);
|
||||
$this->fail('Exception expected due to out of sequence access.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertStringContainsString('quiz/Out of sequence access', $e->getMessage());
|
||||
}
|
||||
// Now we moved to page 1, we should see page 2 and 1 but not 0 or 3.
|
||||
@@ -2066,14 +2067,14 @@ class external_test extends externallib_advanced_testcase {
|
||||
try {
|
||||
mod_quiz_external::get_attempt_data($attemptobj->get_attemptid(), 0);
|
||||
$this->fail('Exception expected due to out of sequence access.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertStringContainsString('quiz/Out of sequence access', $e->getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
mod_quiz_external::get_attempt_data($attemptobj->get_attemptid(), 3);
|
||||
$this->fail('Exception expected due to out of sequence access.');
|
||||
} catch (\moodle_exception $e) {
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertStringContainsString('quiz/Out of sequence access', $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -2127,7 +2128,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
* @param int|null $userid
|
||||
* @param bool|null $ispreview
|
||||
* @return quiz_attempt
|
||||
* @throws \moodle_exception
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
private function create_quiz_attempt_object(quiz $quizobj, ?int $userid = null, ?bool $ispreview = false): quiz_attempt {
|
||||
global $USER;
|
||||
|
||||
@@ -40,6 +40,7 @@ This files describes API changes in the quiz code.
|
||||
|
||||
* The following classes have been deprecated:
|
||||
- mod_quiz_overdue_attempt_updater - merged into mod_quiz\task\update_overdue_attempts
|
||||
- moodle_quiz_exception - just use normal moodle_exception
|
||||
|
||||
* As part of the clean-up, the following files are no longer required, and if you try to
|
||||
include them, you will get a debugging notices telling you not to:
|
||||
|
||||
Reference in New Issue
Block a user