MDL-61815 core_privacy: Fix for metadata types and new method.
authorAdrian Greeve <adrian@moodle.com>
Thu, 29 Mar 2018 05:22:55 +0000 (13:22 +0800)
committerAdrian Greeve <adrian@moodle.com>
Tue, 3 Apr 2018 04:05:18 +0000 (12:05 +0800)
Minor fix for subsystem_link and plugintype_link.
Addition of get_null_provider_reason in the manager class.

privacy/classes/local/metadata/types/plugintype_link.php
privacy/classes/local/metadata/types/subsystem_link.php
privacy/classes/manager.php
privacy/tests/manager_test.php

index 54b29cf..a60fa58 100644 (file)
@@ -78,7 +78,7 @@ class plugintype_link implements type {
      * @return  array
      */
     public function get_privacy_fields() : array {
-        return null;
+        return [];
     }
 
     /**
index 88eedb5..4ee260e 100644 (file)
@@ -78,7 +78,7 @@ class subsystem_link implements type {
      * @return  array
      */
     public function get_privacy_fields() : array {
-        return null;
+        return [];
     }
 
     /**
index cc8da79..0889f4a 100644 (file)
@@ -131,6 +131,20 @@ class manager {
         return false;
     }
 
+    /**
+     * Retrieve the reason for implementing the null provider interface.
+     *
+     * @param  string $component Frankenstyle component name.
+     * @return string The key to retrieve the language string for the null provider reason.
+     */
+    public function get_null_provider_reason(string $component) : string {
+        if ($this->component_implements($component, \core_privacy\local\metadata\null_provider::class)) {
+            return $this->get_provider_classname($component)::get_reason();
+        } else {
+            throw new \coding_exception('Call to undefined method', 'Please only call this method on a null provider.');
+        }
+    }
+
     /**
      * Get the privacy metadata for all components.
      *
index 9f341c5..8ef4a54 100644 (file)
@@ -201,4 +201,16 @@ class privacy_manager_testcase extends advanced_testcase {
         $metadata = $manager->get_metadata_for_components();
         $this->assertNotEmpty($metadata);
     }
+
+    /**
+     * Test that the reason for the null provider is returned.
+     */
+    public function test_get_null_provider_reason() {
+        $manager = new \core_privacy\manager();
+        // Null providers return the reason string.
+        $this->assertEquals('testcomponent2 null provider reason', $manager->get_null_provider_reason('mod_testcomponent2'));
+        // Throw an exception if the wrong type of provider is given.
+        $this->expectException(\coding_exception::class);
+        $string = $manager->get_null_provider_reason('mod_testcomponent');
+    }
 }