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