MDL-41690 cm_info: deprecate various properties
authorDan Poltawski <dan@moodle.com>
Tue, 17 Dec 2013 08:42:18 +0000 (16:42 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 6 Jan 2014 02:45:59 +0000 (10:45 +0800)
lib/modinfolib.php
lib/tests/modinfolib_test.php
lib/upgrade.txt

index 6e69ce4..2890108 100644 (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();
         }
index 1abab2d..83b9daf 100644 (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.');
+    }
 }
index a160016..afc80e3 100644 (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