diff --git a/lib/completionlib.php b/lib/completionlib.php index 262c1e811f0..de9b8a4e639 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -158,7 +158,7 @@ function completion_can_view_data($userid, $course = null) { if (!is_object($course)) { $cid = $course; - $course = new object(); + $course = new stdClass(); $course->id = $cid; } diff --git a/lib/setuplib.php b/lib/setuplib.php index ee6b8ee61aa..155704ce576 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -63,7 +63,14 @@ define('MEMORY_HUGE', -4); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @deprecated since 2.0 */ -class object extends stdClass {}; +class object extends stdClass { + /** + * Constructor. + */ + public function __construct() { + debugging("'object' class has been deprecated, please use stdClass instead.", DEBUG_DEVELOPER); + } +}; /** * Base Moodle Exception class diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index f126735a56e..d9a75de7af5 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -59,15 +59,7 @@ class core_completionlib_testcase extends advanced_testcase { // Create a course with activities. $this->course = $this->getDataGenerator()->create_course(array('enablecompletion' => true)); $this->user = $this->getDataGenerator()->create_user(); - $studentrole = $DB->get_record('role', array('shortname' => 'student')); - $this->assertNotEmpty($studentrole); - - // Get manual enrolment plugin and enrol user. - require_once($CFG->dirroot.'/enrol/manual/locallib.php'); - $manplugin = enrol_get_plugin('manual'); - $maninstance = $DB->get_record('enrol', array('courseid' => $this->course->id, 'enrol' => 'manual'), '*', MUST_EXIST); - $manplugin->enrol_user($maninstance, $this->user->id, $studentrole->id); - $this->assertEquals(1, $DB->count_records('user_enrolments')); + $this->getDataGenerator()->enrol_user($this->user->id, $this->course->id); $this->module1 = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id)); $this->module2 = $this->getDataGenerator()->create_module('forum', array('course' => $this->course->id)); @@ -858,6 +850,17 @@ class core_completionlib_testcase extends advanced_testcase { $expectedlegacylog = array($this->course->id, 'course', 'completion updated', 'completion.php?id='.$this->course->id); $this->assertEventLegacyLogData($expectedlegacylog, $event); } + + public function test_completion_can_view_data() { + $this->setup_data(); + + $student = $this->getDataGenerator()->create_user(); + $this->getDataGenerator()->enrol_user($student->id, $this->course->id); + + $this->setUser($student); + $this->assertTrue(completion_can_view_data($student->id, $this->course->id)); + $this->assertFalse(completion_can_view_data($this->user->id, $this->course->id)); + } } class core_completionlib_fake_recordset implements Iterator { diff --git a/lib/tests/setuplib_test.php b/lib/tests/setuplib_test.php index b46cd645092..787e581adb8 100644 --- a/lib/tests/setuplib_test.php +++ b/lib/tests/setuplib_test.php @@ -460,4 +460,10 @@ class core_setuplib_testcase extends advanced_testcase { return get_exception_info($e); } } + + public function test_object() { + $obj = new object(); + $this->assertDebuggingCalled("'object' class has been deprecated, please use stdClass instead."); + $this->assertInstanceOf('stdClass', $obj); + } } diff --git a/mod/quiz/attemptlib.php b/mod/quiz/attemptlib.php index 5060db3472d..22819860871 100644 --- a/mod/quiz/attemptlib.php +++ b/mod/quiz/attemptlib.php @@ -1975,23 +1975,6 @@ class quiz_attempt { $event->trigger(); } - /** - * Print the fields of the comment form for questions in this attempt. - * @param $slot which question to output the fields for. - * @param $prefix Prefix to add to all field names. - */ - public function question_print_comment_fields($slot, $prefix) { - // Work out a nice title. - $student = get_record('user', 'id', $this->get_userid()); - $a = new object(); - $a->fullname = fullname($student, true); - $a->attempt = $this->get_attempt_number(); - - question_print_comment_fields($this->quba->get_question_attempt($slot), - $prefix, $this->get_display_options(true)->markdp, - get_string('gradingattempt', 'quiz_grading', $a)); - } - // Private methods ========================================================= /** diff --git a/mod/quiz/upgrade.txt b/mod/quiz/upgrade.txt index 2c395e86287..78bee87a9d0 100644 --- a/mod/quiz/upgrade.txt +++ b/mod/quiz/upgrade.txt @@ -1,5 +1,9 @@ This files describes API changes in the quiz code. +=== 3.1 === +* quiz_attempt::question_print_comment_fields() has been removed. It was broken + since at least Moodle 2.0. + === 2.9 === * There have been changes in classes/output/edit_renderer.php for MDL-40990.