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
98 \core_privacy\local\metadata\provider
,
99 \core_plagiarism\privacy\plagiarism_provider
{
101 use \core_plagiarism\privacy\legacy_polyfill
;
102 use \core_privacy\local\legacy_polyfill
;
105 * @var test_legacy_polyfill_plagiarism_provider $mock.
107 public static $mock = null;
110 * Export all user data for the plagiarism plugin.
113 * @param context $context
114 * @param array $subcontext
115 * @param array $linkarray
117 protected static function _export_plagiarism_user_data($userid, \context
$context, array $subcontext, array $linkarray) {
118 static::$mock->get_return_value(__FUNCTION__
, func_get_args());
122 * Deletes all user data for the given context.
124 * @param context $context
126 protected static function _delete_plagiarism_for_context(\context
$context) {
127 static::$mock->get_return_value(__FUNCTION__
, func_get_args());
131 * Delete personal data for the given user and context.
134 * @param context $context
136 protected static function _delete_plagiarism_for_user($userid, \context
$context) {
137 static::$mock->get_return_value(__FUNCTION__
, func_get_args());
141 * Returns metadata about this plugin.
143 * @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to.
144 * @return \core_privacy\local\metadata\collection A listing of user data stored through this system.
146 protected static function _get_metadata(\core_privacy\local\metadata\collection
$collection) {
152 * Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params.
154 * @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
155 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
157 class test_plagiarism_legacy_polyfill_mock_wrapper
{
159 * Get the return value for the specified item.
161 public function get_return_value() {