From cc2454a92b21479f21da5643d83e69cf992b29e9 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Thu, 5 Apr 2018 11:59:38 +0800 Subject: [PATCH] MDL-61761 message_jabber: Add privacy files and unit tests --- .../jabber/classes/privacy/provider.php | 92 +++++++++++++++++++ .../output/jabber/lang/en/message_jabber.php | 5 + message/output/jabber/tests/privacy_test.php | 60 ++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 message/output/jabber/classes/privacy/provider.php create mode 100644 message/output/jabber/tests/privacy_test.php diff --git a/message/output/jabber/classes/privacy/provider.php b/message/output/jabber/classes/privacy/provider.php new file mode 100644 index 00000000000..3f1f8630b9e --- /dev/null +++ b/message/output/jabber/classes/privacy/provider.php @@ -0,0 +1,92 @@ +. +/** + * Privacy class for requesting user data. + * + * @package message_jabber + * @copyright 2018 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace message_jabber\privacy; + +defined('MOODLE_INTERNAL') || die(); + +use \core_privacy\local\metadata\collection; +use \core_privacy\local\request\contextlist; +use \core_privacy\local\request\approved_contextlist; + +/** + * Privacy class for requesting user data. + * + * @package message_jabber + * @copyright 2018 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements + \core_privacy\local\metadata\provider, + \core_privacy\local\request\plugin\provider { + + /** + * Returns meta data about this system. + * + * @param collection $collection The initialised collection to add items to. + * @return collection A listing of user data stored through this system. + */ + public static function get_metadata(collection $collection) { + $collection->link_external_location('External Jabber server.', [ + 'userto' => 'privacy:metadata:userto', + 'userfrom' => 'privacy:metadata:userfrom', + 'smallmessage' => 'privacy:metadata:smallmessage', + 'contexturl' => 'privacy:metadata:contexturl', + ], 'privacy:metadata:externalpurpose'); + return $collection; + } + + /** + * Get the list of contexts that contain user information for the specified user. + * + * @param int $userid The user to search. + * @return contextlist The contextlist containing the list of contexts used in this plugin. + */ + public static function get_contexts_for_userid($userid) { + return new contextlist(); + } + + /** + * Export all user data for the specified user, in the specified contexts. + * + * @param approved_contextlist $contextlist The approved contexts to export information for. + */ + public static function export_user_data(approved_contextlist $contextlist) { + } + + /** + * Delete all use data which matches the specified deletion_criteria. + * + * @param context $context A user context. + */ + public static function delete_data_for_all_users_in_context(\context $context) { + } + + /** + * Delete all user data for the specified user, in the specified contexts. + * + * @param approved_contextlist $contextlist The approved contexts and user information to delete information for. + */ + public static function delete_data_for_user(approved_contextlist $contextlist) { + } +} diff --git a/message/output/jabber/lang/en/message_jabber.php b/message/output/jabber/lang/en/message_jabber.php index 0da961572b8..b40b681be72 100644 --- a/message/output/jabber/lang/en/message_jabber.php +++ b/message/output/jabber/lang/en/message_jabber.php @@ -35,3 +35,8 @@ $string['jabberpassword'] = 'Jabber password'; $string['jabberport'] = 'Jabber port'; $string['notconfigured'] = 'The Jabber server hasn\'t been configured so Jabber messages cannot be sent'; $string['pluginname'] = 'Jabber'; +$string['privacy:metadata:contexturl'] = 'The url to view the event.'; +$string['privacy:metadata:externalpurpose'] = 'This information is sent to an external Jabber server to be ultimately delivered as a notification message to the recipient.'; +$string['privacy:metadata:smallmessage'] = 'The small version of the message.'; +$string['privacy:metadata:userfrom'] = 'The user sending the notification message.'; +$string['privacy:metadata:userto'] = 'The recipient of the notification message.'; diff --git a/message/output/jabber/tests/privacy_test.php b/message/output/jabber/tests/privacy_test.php new file mode 100644 index 00000000000..99e16cf8e48 --- /dev/null +++ b/message/output/jabber/tests/privacy_test.php @@ -0,0 +1,60 @@ +. +/** + * Base class for unit tests for message_jabber. + * + * @package message_jabber + * @copyright 2018 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +use \core_privacy\tests\provider_testcase; + +/** + * Unit tests for message\output\jabber\classes\privacy\provider.php + * + * @copyright 2018 Mihail Geshoski + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class message_jabber_testcase extends provider_testcase { + + /** + * Basic setup for these tests. + */ + public function setUp() { + $this->resetAfterTest(true); + } + + /** + * Test returning metadata. + */ + public function test_get_metadata() { + $collection = new \core_privacy\local\metadata\collection('message_jabber'); + $collection = \message_jabber\privacy\provider::get_metadata($collection); + $this->assertNotEmpty($collection); + } + + /** + * Test getting the context for the user ID related to this plugin. + */ + public function test_get_contexts_for_userid() { + $user = $this->getDataGenerator()->create_user(); + $contextlist = \message_jabber\privacy\provider::get_contexts_for_userid($user->id); + $this->assertEmpty($contextlist); + } +}