2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Unit tests for the privacy legacy polyfill for plagiarism.
20 * @package core_privacy
22 * @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') || die();
29 * Unit tests for the Plagiarism API's privacy legacy_polyfill.
31 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_plagiarism_privacy_legacy_polyfill_test extends advanced_testcase {
36 * Test that the core_plagiarism\privacy\legacy_polyfill works and that the static _export_plagiarism_user_data can be called.
38 public function test_export_plagiarism_user_data() {
40 $context = context_system::instance();
42 $mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
43 $mock->expects($this->once())
44 ->method('get_return_value')
45 ->with('_export_plagiarism_user_data', [$userid, $context, [], []]);
47 test_legacy_polyfill_plagiarism_provider::$mock = $mock;
48 test_legacy_polyfill_plagiarism_provider::export_plagiarism_user_data($userid, $context, [], []);
52 * Test for _get_metadata shim.
54 public function test_get_metadata() {
55 $collection = new \core_privacy\local\metadata\collection('core_plagiarism');
56 $this->assertSame($collection, test_legacy_polyfill_plagiarism_provider::get_metadata($collection));
60 * Test the _delete_plagiarism_for_context shim.
62 public function test_delete_plagiarism_for_context() {
63 $context = context_system::instance();
65 $mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
66 $mock->expects($this->once())
67 ->method('get_return_value')
68 ->with('_delete_plagiarism_for_context', [$context]);
70 test_legacy_polyfill_plagiarism_provider::$mock = $mock;
71 test_legacy_polyfill_plagiarism_provider::delete_plagiarism_for_context($context);
75 * Test the _delete_plagiarism_for_context shim.
77 public function test_delete_plagiarism_for_user() {
79 $context = \context_system::instance();
81 $mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
82 $mock->expects($this->once())
83 ->method('get_return_value')
84 ->with('_delete_plagiarism_for_user', [$userid, $context]);
86 test_legacy_polyfill_plagiarism_provider::$mock = $mock;
87 test_legacy_polyfill_plagiarism_provider::delete_plagiarism_for_user($userid, $context);
92 * Legacy polyfill test class for the plagiarism_provider.
94 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
95 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
97 class test_legacy_polyfill_plagiarism_provider implements \core_plagiarism\privacy\plagiarism_provider {
99 use \core_plagiarism\privacy\legacy_polyfill;
102 * @var test_legacy_polyfill_plagiarism_provider $mock.
104 public static $mock = null;
107 * Export all user data for the plagiarism plugin.
110 * @param context $context
111 * @param array $subcontext
112 * @param array $linkarray
114 protected static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) {
115 static::$mock->get_return_value(__FUNCTION__, func_get_args());
119 * Deletes all user data for the given context.
121 * @param context $context
123 protected static function _delete_plagiarism_for_context(\context $context) {
124 static::$mock->get_return_value(__FUNCTION__, func_get_args());
128 * Delete personal data for the given user and context.
131 * @param context $context
133 protected static function _delete_plagiarism_for_user($userid, \context $context) {
134 static::$mock->get_return_value(__FUNCTION__, func_get_args());
138 * Returns metadata about this plugin.
140 * @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to.
141 * @return \core_privacy\local\metadata\collection A listing of user data stored through this system.
143 protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) {
149 * Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params.
151 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
152 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
154 class test_plagiarism_legacy_polyfill_mock_wrapper {
156 * Get the return value for the specified item.
158 public function get_return_value() {