Skip to content

Commit

Permalink
MDL-61761 message_jabber: Add privacy files and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihail Geshoski committed Apr 5, 2018
1 parent bdceed1 commit ed7d3f1
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
92 changes: 92 additions & 0 deletions message/output/jabber/classes/privacy/provider.php
@@ -0,0 +1,92 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy class for requesting user data.
*
* @package message_jabber
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @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 <mihail@moodle.com>
* @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 {
$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(int $userid) : contextlist {
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) {
}
}
5 changes: 5 additions & 0 deletions message/output/jabber/lang/en/message_jabber.php
Expand Up @@ -35,3 +35,8 @@
$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.';
60 changes: 60 additions & 0 deletions message/output/jabber/tests/privacy_test.php
@@ -0,0 +1,60 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base class for unit tests for message_jabber.
*
* @package message_jabber
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @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 <mihail@moodle.com>
* @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);
}
}

0 comments on commit ed7d3f1

Please sign in to comment.