1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
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.
|
|
|
8 |
//
|
|
|
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.
|
|
|
13 |
//
|
|
|
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/>.
|
|
|
16 |
|
|
|
17 |
namespace core_plagiarism\privacy;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Unit tests for the Plagiarism API's privacy legacy_polyfill.
|
|
|
23 |
*
|
|
|
24 |
* @package core_plagiarism
|
|
|
25 |
* @category test
|
|
|
26 |
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
27 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
28 |
*/
|
|
|
29 |
class legacy_polyfill_test extends \advanced_testcase {
|
|
|
30 |
/**
|
|
|
31 |
* Test that the core_plagiarism\privacy\legacy_polyfill works and that the static _export_plagiarism_user_data can be called.
|
|
|
32 |
*/
|
11 |
efrain |
33 |
public function test_export_plagiarism_user_data(): void {
|
1 |
efrain |
34 |
$userid = 476;
|
|
|
35 |
$context = \context_system::instance();
|
|
|
36 |
|
|
|
37 |
$mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
|
|
|
38 |
$mock->expects($this->once())
|
|
|
39 |
->method('get_return_value')
|
|
|
40 |
->with('_export_plagiarism_user_data', [$userid, $context, [], []]);
|
|
|
41 |
|
|
|
42 |
test_legacy_polyfill_plagiarism_provider::$mock = $mock;
|
|
|
43 |
test_legacy_polyfill_plagiarism_provider::export_plagiarism_user_data($userid, $context, [], []);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
/**
|
|
|
47 |
* Test for _get_metadata shim.
|
|
|
48 |
*/
|
11 |
efrain |
49 |
public function test_get_metadata(): void {
|
1 |
efrain |
50 |
$collection = new \core_privacy\local\metadata\collection('core_plagiarism');
|
|
|
51 |
$this->assertSame($collection, test_legacy_polyfill_plagiarism_provider::get_metadata($collection));
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Test the _delete_plagiarism_for_context shim.
|
|
|
56 |
*/
|
11 |
efrain |
57 |
public function test_delete_plagiarism_for_context(): void {
|
1 |
efrain |
58 |
$context = \context_system::instance();
|
|
|
59 |
|
|
|
60 |
$mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
|
|
|
61 |
$mock->expects($this->once())
|
|
|
62 |
->method('get_return_value')
|
|
|
63 |
->with('_delete_plagiarism_for_context', [$context]);
|
|
|
64 |
|
|
|
65 |
test_legacy_polyfill_plagiarism_provider::$mock = $mock;
|
|
|
66 |
test_legacy_polyfill_plagiarism_provider::delete_plagiarism_for_context($context);
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Test the _delete_plagiarism_for_context shim.
|
|
|
71 |
*/
|
11 |
efrain |
72 |
public function test_delete_plagiarism_for_user(): void {
|
1 |
efrain |
73 |
$userid = 696;
|
|
|
74 |
$context = \context_system::instance();
|
|
|
75 |
|
|
|
76 |
$mock = $this->createMock(test_plagiarism_legacy_polyfill_mock_wrapper::class);
|
|
|
77 |
$mock->expects($this->once())
|
|
|
78 |
->method('get_return_value')
|
|
|
79 |
->with('_delete_plagiarism_for_user', [$userid, $context]);
|
|
|
80 |
|
|
|
81 |
test_legacy_polyfill_plagiarism_provider::$mock = $mock;
|
|
|
82 |
test_legacy_polyfill_plagiarism_provider::delete_plagiarism_for_user($userid, $context);
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Legacy polyfill test class for the plagiarism_provider.
|
|
|
88 |
*
|
|
|
89 |
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
90 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
91 |
*/
|
|
|
92 |
class test_legacy_polyfill_plagiarism_provider implements
|
|
|
93 |
\core_privacy\local\metadata\provider,
|
|
|
94 |
\core_plagiarism\privacy\plagiarism_provider {
|
|
|
95 |
|
|
|
96 |
use \core_plagiarism\privacy\legacy_polyfill;
|
|
|
97 |
use \core_privacy\local\legacy_polyfill;
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* @var test_legacy_polyfill_plagiarism_provider $mock.
|
|
|
101 |
*/
|
|
|
102 |
public static $mock = null;
|
|
|
103 |
|
|
|
104 |
/**
|
|
|
105 |
* Export all user data for the plagiarism plugin.
|
|
|
106 |
*
|
|
|
107 |
* @param int $userid
|
|
|
108 |
* @param context $context
|
|
|
109 |
* @param array $subcontext
|
|
|
110 |
* @param array $linkarray
|
|
|
111 |
*/
|
|
|
112 |
protected static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) {
|
|
|
113 |
static::$mock->get_return_value(__FUNCTION__, func_get_args());
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/**
|
|
|
117 |
* Deletes all user data for the given context.
|
|
|
118 |
*
|
|
|
119 |
* @param context $context
|
|
|
120 |
*/
|
|
|
121 |
protected static function _delete_plagiarism_for_context(\context $context) {
|
|
|
122 |
static::$mock->get_return_value(__FUNCTION__, func_get_args());
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* Delete personal data for the given user and context.
|
|
|
127 |
*
|
|
|
128 |
* @param int $userid
|
|
|
129 |
* @param context $context
|
|
|
130 |
*/
|
|
|
131 |
protected static function _delete_plagiarism_for_user($userid, \context $context) {
|
|
|
132 |
static::$mock->get_return_value(__FUNCTION__, func_get_args());
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* Returns metadata about this plugin.
|
|
|
137 |
*
|
|
|
138 |
* @param \core_privacy\local\metadata\collection $collection The initialised collection to add items to.
|
|
|
139 |
* @return \core_privacy\local\metadata\collection A listing of user data stored through this system.
|
|
|
140 |
*/
|
|
|
141 |
protected static function _get_metadata(\core_privacy\local\metadata\collection $collection) {
|
|
|
142 |
return $collection;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
/**
|
|
|
147 |
* Called inside the polyfill methods in the test polyfill provider, allowing us to ensure these are called with correct params.
|
|
|
148 |
*
|
|
|
149 |
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
150 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
151 |
*/
|
|
|
152 |
class test_plagiarism_legacy_polyfill_mock_wrapper {
|
|
|
153 |
/**
|
|
|
154 |
* Get the return value for the specified item.
|
|
|
155 |
*/
|
|
|
156 |
public function get_return_value() {
|
|
|
157 |
}
|
|
|
158 |
}
|