Merge branch 'MDL-54988-master' of git://github.com/junpataleta/moodle

This commit is contained in:
Dan Poltawski 2016-07-26 09:13:10 +01:00
commit 6d5a7eee0c
3 changed files with 33 additions and 85 deletions

View File

@ -531,22 +531,14 @@ class course_modinfo {
} }
/** /**
* Builds a list of information about sections on a course to be stored in * This method can not be used anymore.
* the course cache. (Does not include information that is already cached
* in some other way.)
*
* This function will be removed in 2.7
* *
* @see course_modinfo::build_course_cache()
* @deprecated since 2.6 * @deprecated since 2.6
* @param int $courseid Course ID
* @return array Information about sections, indexed by section number (not id)
*/ */
public static function build_section_cache($courseid) { public static function build_section_cache($courseid) {
global $DB; throw new coding_exception('Function course_modinfo::build_section_cache() can not be used anymore.' .
debugging('Function course_modinfo::build_section_cache() is deprecated. It can only be used internally to build course cache.'); ' Please use course_modinfo::build_course_cache() whenever applicable.');
$course = $DB->get_record('course', array('id' => $course->id),
array_merge(array('id'), self::$cachedfields), MUST_EXIST);
return self::build_course_section_cache($course);
} }
/** /**
@ -1124,28 +1116,21 @@ class cm_info implements IteratorAggregate {
); );
/** /**
* Magic method to call functions that are now declared as private now but * Magic method to call functions that are now declared as private but were public in Moodle before 2.6.
* were public in Moodle before 2.6. Developers can access them without * These private methods can not be used anymore.
* any warnings but they are not listed in the class methods list.
* *
* @param string $name * @param string $name
* @param array $arguments * @param array $arguments
* @return mixed * @return mixed
* @throws coding_exception
*/ */
public function __call($name, $arguments) { public function __call($name, $arguments) {
global $CFG;
if (in_array($name, self::$standardmethods)) { if (in_array($name, self::$standardmethods)) {
if ($CFG->debugdeveloper) { $message = "cm_info::$name() can not be used anymore.";
if ($alternative = array_search($name, self::$standardproperties)) { if ($alternative = array_search($name, self::$standardproperties)) {
// All standard methods do not have arguments anyway. $message .= " Please use the property cm_info->$alternative instead.";
debugging("cm_info::$name() is deprecated, please use the property cm_info->$alternative instead.", DEBUG_DEVELOPER);
} else {
debugging("cm_info::$name() is deprecated and should not be used.", DEBUG_DEVELOPER);
}
} }
// All standard methods do not have arguments anyway. throw new coding_exception($message);
return $this->$name();
} }
throw new coding_exception("Method cm_info::{$name}() does not exist"); throw new coding_exception("Method cm_info::{$name}() does not exist");
} }
@ -1841,18 +1826,15 @@ class cm_info implements IteratorAggregate {
} }
/** /**
* Getter method for $availablefrom and $availableuntil. Just returns zero * This method can not be used anymore.
* as these are no longer supported.
* *
* @return int Zero * @see \core_availability\info_module::filter_user_list()
* @deprecated Since Moodle 2.8 * @deprecated Since Moodle 2.8
*/ */
private function get_deprecated_group_members_only() { private function get_deprecated_group_members_only() {
debugging('$cm->groupmembersonly has been deprecated and always returns zero. ' . throw new coding_exception('$cm->groupmembersonly can not be used anymore. ' .
'If used to restrict a list of enrolled users to only those who can ' . 'If used to restrict a list of enrolled users to only those who can ' .
'access the module, consider \core_availability\info_module::filter_user_list.', 'access the module, consider \core_availability\info_module::filter_user_list.');
DEBUG_DEVELOPER);
return 0;
} }
/** /**
@ -1897,20 +1879,14 @@ class cm_info implements IteratorAggregate {
} }
/** /**
* Checks whether the module's group settings restrict the current user's * This method has been deprecated and should not be used.
* access. This function is not necessary now that all access restrictions
* are handled by the availability API. You can use $cm->uservisible to
* find out if the current user can access an activity, or $cm->availableinfo
* to get information about why not.
* *
* @return bool False * @see $uservisible
* @deprecated Since Moodle 2.8 * @deprecated Since Moodle 2.8
*/ */
public function is_user_access_restricted_by_group() { public function is_user_access_restricted_by_group() {
debugging('cm_info::is_user_access_restricted_by_group() ' . throw new coding_exception('cm_info::is_user_access_restricted_by_group() can not be used any more.' .
'is deprecated and always returns false; use $cm->uservisible ' . ' Use $cm->uservisible to decide whether the current user can access an activity.');
'to decide whether the current user can access an activity', DEBUG_DEVELOPER);
return false;
} }
/** /**

View File

@ -201,10 +201,6 @@ class core_modinfolib_testcase extends advanced_testcase {
$this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url); $this->assertEquals(new moodle_url('/mod/assign/view.php', array('id' => $moduledb->id)), $cm->url);
$this->assertEquals($cachedcminfo->customdata, $cm->customdata); $this->assertEquals($cachedcminfo->customdata, $cm->customdata);
// Deprecated field.
$this->assertEquals(0, $cm->groupmembersonly);
$this->assertDebuggingCalled();
// Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type). // Dynamic fields, just test that they can be retrieved (must be carefully tested in each activity type).
$this->assertNotEmpty($cm->availableinfo); // Lists all unmet availability conditions. $this->assertNotEmpty($cm->availableinfo); // Lists all unmet availability conditions.
$this->assertEquals(0, $cm->uservisible); $this->assertEquals(0, $cm->uservisible);
@ -470,44 +466,6 @@ class core_modinfolib_testcase extends advanced_testcase {
$this->assertTrue($cm->is_user_access_restricted_by_capability()); $this->assertTrue($cm->is_user_access_restricted_by_capability());
} }
/**
* Tests that various deprecated cm_info methods are throwing debuggign messages
*/
public function test_cm_info_property_deprecations() {
global $DB, $CFG;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course( array('format' => 'topics', 'numsections' => 3),
array('createsections' => true));
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id));
$cm = get_fast_modinfo($course->id)->instances['forum'][$forum->id];
$cm->get_url();
$this->assertDebuggingCalled('cm_info::get_url() is deprecated, please use the property cm_info->url instead.');
$cm->get_content();
$this->assertDebuggingCalled('cm_info::get_content() is deprecated, please use the property cm_info->content instead.');
$cm->get_extra_classes();
$this->assertDebuggingCalled('cm_info::get_extra_classes() is deprecated, please use the property cm_info->extraclasses instead.');
$cm->get_on_click();
$this->assertDebuggingCalled('cm_info::get_on_click() is deprecated, please use the property cm_info->onclick instead.');
$cm->get_custom_data();
$this->assertDebuggingCalled('cm_info::get_custom_data() is deprecated, please use the property cm_info->customdata instead.');
$cm->get_after_link();
$this->assertDebuggingCalled('cm_info::get_after_link() is deprecated, please use the property cm_info->afterlink instead.');
$cm->get_after_edit_icons();
$this->assertDebuggingCalled('cm_info::get_after_edit_icons() is deprecated, please use the property cm_info->afterediticons instead.');
$cm->obtain_dynamic_data();
$this->assertDebuggingCalled('cm_info::obtain_dynamic_data() is deprecated and should not be used.');
}
/** /**
* Tests for function cm_info::get_course_module_record() * Tests for function cm_info::get_course_module_record()
*/ */

View File

@ -30,6 +30,20 @@ information provided here is intended especially for developers.
- setExpectedException(), use @expectedException or $this->expectException() and $this->expectExceptionMessage() - setExpectedException(), use @expectedException or $this->expectException() and $this->expectExceptionMessage()
- getMock(), use createMock() or getMockBuilder()->getMock() - getMock(), use createMock() or getMockBuilder()->getMock()
- UnitTestCase class is removed. - UnitTestCase class is removed.
* The following methods have been finally deprecated and should no longer be used:
- course_modinfo::build_section_cache()
- cm_info::get_deprecated_group_members_only()
- cm_info::is_user_access_restricted_by_group()
* The following methods in cm_info::standardmethods have also been finally deprecated and should no longer be used:
- cm_info::get_after_edit_icons()
- cm_info::get_after_link()
- cm_info::get_content()
- cm_info::get_custom_data()
- cm_info::get_extra_classes()
- cm_info::get_on_click()
- cm_info::get_url()
- cm_info::obtain_dynamic_data()
Calling them through the magic method __call() will throw a coding exception.
=== 3.1 === === 3.1 ===