MDL-62426 core_enrol: control enrolment subcontexts at the provider
authorJake Dallimore <jake@moodle.com>
Wed, 16 May 2018 02:17:26 +0000 (10:17 +0800)
committerJake Dallimore <jake@moodle.com>
Wed, 16 May 2018 02:22:15 +0000 (10:22 +0800)
Added a function to the core_enrol provider allowing enrol plugins
to set their subcontext relative to a fixed 'enrolments' parent dir.

enrol/classes/privacy/provider.php
enrol/flatfile/classes/privacy/provider.php
enrol/flatfile/tests/privacy_provider_test.php

index 46a0c63..0b55332 100644 (file)
@@ -230,4 +230,16 @@ class provider implements
         $DB->delete_records_select('user_enrolments', "id $sql", $params);
     }
 
+    /**
+     * Get the subcontext for export.
+     *
+     * @param array $subcontext Any additional subcontext to use.
+     * @return array The array containing the full subcontext, i.e. [enrolments, subcontext]
+     */
+    public static function get_subcontext(array $subcontext) {
+        return array_merge(
+            [get_string('privacy:metadata:user_enrolments', 'core_enrol')],
+            $subcontext
+        );
+    }
 }
index e6987da..93e5d83 100644 (file)
@@ -118,7 +118,7 @@ class provider implements
         $futureenrolments->close();
 
         // And finally, write out the data to the relevant course contexts.
-        $subcontext = [get_string('flatfileenrolments', 'enrol_flatfile')];
+        $subcontext = \core_enrol\privacy\provider::get_subcontext([get_string('pluginname', 'enrol_flatfile')]);
         foreach ($enrolmentdata as $courseid => $enrolments) {
             $data = (object) [
                 'pendingenrolments' => $enrolments,
index 6f4d188..5ad5dbb 100644 (file)
@@ -117,15 +117,17 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
         provider::export_user_data($approvedcontextlist);
 
         // Verify we see one future course enrolment in course1, and one in course3.
+        $subcontext = \core_enrol\privacy\provider::get_subcontext([get_string('pluginname', 'enrol_flatfile')]);
+
         $writer = writer::with_context($this->coursecontext1);
-        $this->assertNotEmpty($writer->get_data([get_string('flatfileenrolments', 'enrol_flatfile')]));
+        $this->assertNotEmpty($writer->get_data($subcontext));
 
         $writer = writer::with_context($this->coursecontext3);
-        $this->assertNotEmpty($writer->get_data([get_string('flatfileenrolments', 'enrol_flatfile')]));
+        $this->assertNotEmpty($writer->get_data($subcontext));
 
         // Verify we have nothing in course 2 for this user.
         $writer = writer::with_context($this->coursecontext2);
-        $this->assertEmpty($writer->get_data([get_string('flatfileenrolments', 'enrol_flatfile')]));
+        $this->assertEmpty($writer->get_data($subcontext));
     }
 
     /**
@@ -146,12 +148,14 @@ class enrol_flatfile_privacy_testcase extends provider_testcase {
         provider::export_user_data($subsetapprovedcontextlist);
 
         // Verify we see one future course enrolment in course1 only.
+        $subcontext = \core_enrol\privacy\provider::get_subcontext([get_string('pluginname', 'enrol_flatfile')]);
+
         $writer = writer::with_context($this->coursecontext1);
-        $this->assertNotEmpty($writer->get_data([get_string('flatfileenrolments', 'enrol_flatfile')]));
+        $this->assertNotEmpty($writer->get_data($subcontext));
 
         // And nothing in the course3 context.
         $writer = writer::with_context($this->coursecontext3);
-        $this->assertEmpty($writer->get_data([get_string('flatfileenrolments', 'enrol_flatfile')]));
+        $this->assertEmpty($writer->get_data($subcontext));
     }
 
     /**