MDL-41690 cm_info: deprecate various properties

This commit is contained in:
Dan Poltawski 2013-12-17 16:42:18 +08:00
parent bbb291b7b7
commit 07e78d935f
3 changed files with 50 additions and 0 deletions

View File

@ -1167,7 +1167,17 @@ class cm_info implements IteratorAggregate {
* @return mixed
*/
public function __call($name, $arguments) {
global $CFG;
if (in_array($name, self::$standardmethods)) {
if ($CFG->debugdeveloper) {
if ($alternative = array_search($name, self::$standardproperties)) {
// All standard methods do not have arguments anyway.
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.
return $this->$name();
}

View File

@ -657,4 +657,42 @@ class core_modinfolib_testcase extends advanced_testcase {
$this->assertFalse($cm->uservisible);
$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.');
}
}

View File

@ -11,6 +11,8 @@ DEPRECATIONS:
* mod_feedback\event\instances_list_viewed has been deprecated. Please use mod_feedback\event\course_module_instance_list_viewed instead.
* mod_page\event\instances_list_viewed has been deprecated. Please use mod_page\event\course_module_instance_list_viewed instead.
* The constants FRONTPAGECOURSELIST, FRONTPAGETOPICONLY & FRONTPAGECOURSELIMIT have been removed.
* Various cm_info methods have been deprecated in favour of their read-only properties (get_url(), get_content(), get_extra_classes(),
get_on_click(), get_custom_data(), get_after_link, get_after_edit_icons)
YUI:
* The lightbox attribute for moodle-core-notification-dialogue has been